# Transaction

The APIs related to executing transactions consist of three components:&#x20;

* [Retrieve Transaction Information](#retrieve-transaction-information) `/v1/tx/prepare`
* [Sign Transaction](#sign-transaction)`/v1/tx/sign`
* [Broadcast Transaction](#broadcast-transaction)`/v1/tx/broadcast`&#x20;

The necessary APIs can be executed sequentially depending on the situation

* Generating a signature only: Retrieve Transaction Information ⇒ Sign Transaction&#x20;
* Generating a signature and broadcasting in a single step: Retrieve Transaction Information ⇒ Broadcast Transaction
  * (Optional) Generating a signature and broadcasting: Retrieve Transaction Information ⇒ Sign Transaction ⇒ Broadcast Transaction

### Retrieve Transaction Information

Retrieve information such as the required transaction fee.

```http
POST /v1/tx/prepare HTTP/1.1
Host: sdk.wepin.io
X-API-KEY: ${APP_KEY}
X-API-DOMAIN: {APP_DOMAIN}
X-SDK-TYPE: {platform}_rest_api
Content-Type: application/json
Authorization: Bearer ${access_token}
```

#### Request

**Parameter**

<table><thead><tr><th width="134">Name</th><th width="132">Type</th><th width="382">Description</th><th>Required</th></tr></thead><tbody><tr><td>userId</td><td>String</td><td><code>userId</code> from the <a href="/pages/EQaogmCNNR1GmRx6oihQ#login">Login</a> response.</td><td>O</td></tr><tr><td>accountId</td><td>String</td><td>Account ID to send from <code>/v1/account</code> response value.</td><td>O</td></tr><tr><td>contract</td><td>String</td><td>Contract address of the token to be sent when sending tokens.</td><td>X</td></tr><tr><td>to</td><td>String</td><td>Recipient address</td><td>O</td></tr><tr><td>isNft</td><td>String</td><td><code>ERC1155</code> | <code>ERC721</code><br>Define NFT scheme type when transferring FT.</td><td>X</td></tr><tr><td>tokenId</td><td>Number String</td><td>NFT token ID when isNft is set and transferring an NFT.</td><td>X</td></tr><tr><td>amount</td><td>String</td><td>Amount of coin or token to send when transferring FT.</td><td>X</td></tr></tbody></table>

#### Response

**Success Response**

<table><thead><tr><th width="167">Name</th><th width="169">Type</th><th>Description</th></tr></thead><tbody><tr><td>balance</td><td>String</td><td>The current balance of the account to be transferred.</td></tr><tr><td>decimals</td><td>String</td><td>The decimals of the coin in the account to be transferred.</td></tr><tr><td>symbol</td><td>String</td><td>The symbol of the coin in the account to be transferred.</td></tr><tr><td>tokenId</td><td>Number</td><td>If the account to be transferred is a token account, the tokenId.</td></tr><tr><td>detail</td><td>TxData(Object)</td><td>The data required for the transaction. The TxData format differs depending on the type of account.</td></tr></tbody></table>

### Sign Transaction

The actual signing is performed using the data obtained through [Retrieve Transaction Information](#retrieve-transaction-information). If necessary, the fee value in TxData can be modified before signing. Before signing, the user's wallet PIN must be obtained using the PIN Pad Library, and the UVD must be sent together.

```http
POST /v1/tx/sign HTTP/1.1
Host: sdk.wepin.io
X-API-KEY: ${APP_KEY}
X-API-DOMAIN: {APP_DOMAIN}
X-SDK-TYPE: {platform}_rest_api
Content-Type: application/json
Authorization: Bearer ${access_token}
```

#### Request

**Parameter**

<table><thead><tr><th width="129">Name</th><th width="149">Type</th><th width="373">Description</th><th>Required</th></tr></thead><tbody><tr><td>userId</td><td>String</td><td><code>userId</code> from the <a href="/pages/EQaogmCNNR1GmRx6oihQ#login">Login</a> response.</td><td>O</td></tr><tr><td>type</td><td>String</td><td>Types of Signatures<br>•<code>transaction</code> (transaction) | <code>msg_sign</code> (Personal sign) | <code>sign_data</code> (typed data)<br>• The configuration of <code>txData</code> differs depending on the type.<br>•<code>msg_sign</code> | <code>sign_data</code> currently supports only EVM transactions.</td><td>O</td></tr><tr><td>pin</td><td>UVD</td><td>User's UVD</td><td>O</td></tr><tr><td>walletId</td><td>String</td><td>User Wallet ID</td><td>O</td></tr><tr><td>accountId</td><td>String</td><td>ID of the account to be sent. Must match the accountId from <a href="#retrieve-transaction-information">Retrieve Transaction Information</a>.</td><td>O</td></tr><tr><td>tokenId</td><td>String</td><td><code>tokenId</code> for token transfers.</td><td>X</td></tr><tr><td>isNft</td><td>String</td><td><code>ERC1155</code> | <code>ERC721</code></td><td>X</td></tr><tr><td>contract</td><td>String</td><td>Contract address for token transfers.</td><td>X</td></tr><tr><td>txData</td><td>TxData(Object)</td><td>Transaction data required. Includes the data values retrieved through <a href="#retrieve-transaction-information">Retrieve Transaction Information</a>, with a format differing based on the type of account.</td><td>O</td></tr><tr><td>otpCode</td><td>Object</td><td>OTP authentication information.</td><td>X</td></tr></tbody></table>

#### Response

**Success Response**

<table><thead><tr><th width="187">Name</th><th width="142">Type</th><th>Description</th></tr></thead><tbody><tr><td>signatureResult</td><td>Object</td><td>Sign result value. Structure varies by transmission network.</td></tr><tr><td>transaction</td><td>Object</td><td>Transmission details.</td></tr></tbody></table>

### Broadcast Transaction

Sends the signed transaction.

```http
POST /v1/tx/broadcast HTTP/1.1
Host: sdk.wepin.io
X-API-KEY: ${APP_KEY}
X-API-DOMAIN: {APP_DOMAIN}
X-SDK-TYPE: {platform}_rest_api
Content-Type: application/json
Authorization: Bearer ${access_token}

```

#### Request

**Parameter**

<table><thead><tr><th width="163">Name</th><th width="147">Type</th><th width="337">Description</th><th>Required</th></tr></thead><tbody><tr><td>userId</td><td>String</td><td><code>userId</code> from the <a href="/pages/EQaogmCNNR1GmRx6oihQ#login">Login</a> response.</td><td>O</td></tr><tr><td>type</td><td>String</td><td>Types of Signatures<br>• <code>transaction</code> (transaction) | <code>msg_sign</code> (Personal sign) | <code>sign_data</code> (typed dat<br>• The configuration of <code>txData</code> varies depending on the type.<br>• <code>msg_sign</code> | <code>sign_data</code> currently supports only EVM transactions.</td><td>O</td></tr><tr><td>pin</td><td>UVD</td><td>User's UVD</td><td>O</td></tr><tr><td>walletId</td><td>String</td><td>User Wallet ID</td><td>O</td></tr><tr><td>accountId</td><td>String</td><td>ID of the account to be sent. Must match the accountId from <a href="#retrieve-transaction-information">Retrieve Transaction Information</a></td><td>O</td></tr><tr><td>tokenId</td><td>String</td><td><code>tokenId</code> for token transfers.</td><td>X</td></tr><tr><td>contract</td><td>String</td><td>Contract address for token transfers.</td><td>X</td></tr><tr><td>isNft</td><td>String</td><td><code>ERC1155</code> | <code>ERC721</code></td><td>X</td></tr><tr><td>signatureResult</td><td>String | Object</td><td>When executing in the order of <code>/prepare</code>, <code>/sign</code>, and <code>/broadcast</code>, this is the already signed data to be broadcasted. Use the data received after signing (<code>/tx/sign</code>) without modification.</td><td>X</td></tr><tr><td>txData</td><td>TxData(Object)</td><td>When executing in the order of <code>/prepare</code> and <code>/broadcast</code>, this is the required transaction data when signing and broadcasting in a single process. Transaction data required. Includes the data retrieved through <a href="#retrieve-transaction-information">Retrieve Transaction Information</a>, with a format differing based on the type of account.</td><td>X</td></tr><tr><td>otpCode</td><td>Object</td><td>OTP authentication information.</td><td>X</td></tr></tbody></table>

### Response

**Success Response**

<table><thead><tr><th width="190">Name</th><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td>signatureResult</td><td>Object</td><td>Sign result value. The structure varies slightly depending on the transmission network.</td></tr><tr><td>transaction</td><td>Object</td><td>Transmission details.</td></tr><tr><td>broadcastData</td><td>String</td><td>Data sent to the network.</td></tr><tr><td>txid</td><td>String</td><td>Transaction ID</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/en/api/transaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
