# Prepare A Transaction From an Address in HD Wallet (xPub, yPub, zPub) EVM

Through the “Prepare an account-based transaction from xPub” endpoint users can prepare a transaction for signing from a synced with Crypto APIs address from the specific xPub. This endpoint applies to all supported account-based blockchain protocols, e.g. Ethereum, BSC, etc

- **Endpoint:** `POST https://rest.cryptoapis.io/hd-wallets/evm/{blockchain}/{network}/{extendedPublicKey}/transactions/prepare`
- **Authentication:** `x-api-key` header
- **Credits cost:** 130 credits for 1 result by default; per blockchain: Ethereum: 130, Ethereum Classic: 169, Binance Smart Chain: 325, Tron: 195
- **Documentation page:** https://developers.cryptoapis.io/v-2.2024-12-12-175/RESTapis/hd-wallet-data-evm/prepare-a-transaction-from-an-address-in-hd-wallet-xpub-ypub-zpub-evm/post

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `blockchain` | string | yes | Represents the specific blockchain protocol name, e.g. Ethereum, Bitcoin, etc. Allowed values: `binance-smart-chain`, `ethereum-classic`, `ethereum`. |
| `network` | string | yes | Represents the name of the blockchain network used; blockchain networks are usually identical as technology and software, but they differ in data, e.g. - "mainnet" is the live network with actual data while networks like "testnet", "ropsten" are test networks. Allowed values: `testnet`, `mainnet`, `mordor`, `sepolia`. |
| `extendedPublicKey` | string | yes | Defines the account extended publicly known key which is used to derive all child public keys. |

## Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `context` | string | no | In batch situations the user can use the context to correlate responses with requests. This property is present regardless of whether the response was successful or returned as an error. `context` is specified by the user. |

## Request body (application/json)

```json
{
  "context": "yourExampleString",
  "data": {
    "item": {
      "additionalData": "yourAdditionalDataHere",
      "amount": "0.000003",
      "nonce": "0",
      "recipient": "0x041c594a0cc194e826bef5411b29c7f27001b7e3",
      "sender": "0x03654A9E78771442CAdf8DB37ae60D6a12bAEa9f",
      "fee": {
        "exactAmount": "0.00045",
        "priority": "standard"
      },
      "transactionType": "legacy-transaction"
    }
  }
}
```

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `context` | string | no | In batch situations the user can use the context to correlate responses with requests. This property is present regardless of whether the response was successful or returned as an error. `context` is specified by the user. |
| `data` | object | yes |  |
| `data.item` | object | yes |  |
| `data.item.additionalData` | string | no | Representation of the additional data. |
| `data.item.amount` | string | yes | Representation of the amount of the transaction |
| `data.item.nonce` | string | no | Representation of the nonce value |
| `data.item.recipient` | string | yes | Represents a list of recipient addresses with the respective amounts. In account-based protocols like Ethereum there is only one address in this list. |
| `data.item.sender` | string | yes | Represents a  sender address with the respective amount. In account-based protocols like Ethereum there is only one address in this list. |
| `data.item.fee` | object | yes | When isConfirmed is True - Defines the amount of the transaction fee When isConfirmed is False - For ETH-based blockchains this attribute represents the max fee value. |
| `data.item.fee.exactAmount` | string | no | Representation of the exact amount value |
| `data.item.fee.priority` | string | no | Represents the fee priority |
| `data.item.transactionType` | string | no | Representation of the transaction type |

## Responses

| Status | Description |
| --- | --- |
| 200 | The resource has been successfully submitted. |
| 400 | 400 |
| 401 | 401 |
| 402 | 402 |
| 403 | 403 |
| 409 | The data provided seems to be invalid. |
| 415 | The selected Media Type is unavailable. The Content-Type header should be 'application/json'. |
| 422 | Your request body for POST requests must have a structure of { data: { item: [...properties] } } |
| 429 | The request limit has been reached. There can be maximum {requests} requests per {seconds} second(s) made. Please contact our team via email if you need more or upgrade your plan. |
| 500 | An unexpected server error has occurred, we are working to fix this. Please try again later and in case it occurs again please report it to our team via email. |

### Example 200 response

```json
{
  "apiVersion": "2024-12-12",
  "requestId": "601c1710034ed6d407996b30",
  "context": "yourExampleString",
  "data": {
    "item": {
      "derivationIndex": 0,
      "fee": {
        "unit": "WEI",
        "maxFeePerGas": 2000000008,
        "maxPriorityFeePerGas": 2000000000
      },
      "gasLimit": 552020,
      "gasPrice": 2500000007,
      "inputData": "0x0079006f00750072004100640064006900740069006f006e0061006c00440061007400610048006500720065",
      "nonce": 0,
      "recipient": "0x041c594a0cc194e826bef5411b29c7f27001b7e3",
      "sender": "0x03654A9E78771442CAdf8DB37ae60D6a12bAEa9f",
      "sigHash": "40738814e379fd2b1923729c87ac80dddc6810a3f8f02fef05452251972ec83a",
      "value": {
        "amount": 0,
        "unit": "WEI"
      },
      "type": "legacy-transaction"
    }
  }
}
```

### 200 response fields

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `apiVersion` | string | yes | Specifies the version of the API that incorporates this endpoint. |
| `requestId` | string | yes | Defines the ID of the request. The `requestId` is generated by Crypto APIs and it's unique for every request. |
| `context` | string | no | In batch situations the user can use the context to correlate responses with requests. This property is present regardless of whether the response was successful or returned as an error. `context` is specified by the user. |
| `data` | object | yes |  |
| `data.item` | object | yes |  |
| `data.item.derivationIndex` | integer | yes | Representation of the derivation index of the xpub address |
| `data.item.fee` | object | yes | When isConfirmed is True - Defines the amount of the transaction fee When isConfirmed is False - For ETH-based blockchains this attribute represents the max fee value. |
| `data.item.fee.unit` | string | yes |  |
| `data.item.fee.maxFeePerGas` | integer | no | Representation of the max fee per gas value |
| `data.item.fee.maxPriorityFeePerGas` | integer | no | Representation of the max priority fee per gas value |
| `data.item.gasLimit` | integer | yes | Represents the amount of gas used by this specific transaction alone. |
| `data.item.gasPrice` | integer | yes | Represents the price offered to the miner to purchase this amount of gas. |
| `data.item.inputData` | string | yes | Representation of the data in hex value |
| `data.item.nonce` | integer | yes | Represents the sequential running number for an address, starting from 0 for the first transaction. E.g., if the nonce of a transaction is 10, it would be the 11th transaction sent from the sender's address. |
| `data.item.recipient` | string | yes | Represents a recipient addresses. In account-based protocols like Ethereum there is only one address in this list. |
| `data.item.sender` | string | yes | Represents a sender address with the respective amount. In account-based protocols like Ethereum there is only one address in this list. |
| `data.item.sigHash` | string | yes | Representation of the hash that should be signed. |
| `data.item.value` | object | yes |  |
| `data.item.value.amount` | integer | yes | Representation of the amount of the transaction |
| `data.item.value.unit` | string | yes | Represents the unit of the amount to be sent. |
| `data.item.type` | string | yes | Representation of the transaction type |
