Build-Next-Tx

Returns the transaction data for the next transaction

v2/route/build-next-tx

How this endpoint is used :

  • This method returns the transaction data for the next transaction

  • If the transaction requires prior token approval, details of the token to be approved are also sent via the approvalData field. If approvalData is null, an approval tx is not needed.

Returns the to address and data for the next transaction

GET https://api.socket.tech/v2/route/build-next-tx

Query Parameters

NameTypeDescription

activeRouteId*

string

ID of active route

newRecipient

string

Overrides default recipient of the transaction

bridgeSlippage

string

Bridge slippage value b/w 0% - 100%. Learn more here

swapSlippage

string

Swap slippage value b/w 0% - 100%.

{
  "success": true,
  "result": {
    "userTxType": "string",
    "txType": "string",
    "txData": "string",
    "txTarget": "string",
    "chainId": 0,
    "totalUserTx": 0,
    "activeRouteId": 0,
    "value": "string",
    "userTxIndex": 0,
    "approvalData": {}
  }
}

API-KEY needs to be passed in the headers while making the GET request

Description of response parameters :

ParameterDescription

userTxType

Action of transaction user performs. Values in Types page

txType

Type of transaction. Values in Types page

txData

data to add in transaction

txTarget

to address for sending transaction

chainId

ID of chain to perform transaction on

totalUserTx

Total number of transactions to be performed by user in route

activeRouteId

ID of active route

value

value to send in the transaction

userTxIndex

Index of transaction user last performed

approvalData

Object with meta data if token approval is needed

approvalData.minimumApprovalAmount

Minimum amount to give approval

approvalData.approvalTokenAddress

Contract address of token to give approval

approvalData.allowanceTarget

Address of token spender

approvalData.owner

Address of token owner

routeStatus

If route is complete, routeStatus is returned and marked "COMPLETED". Find all values here

approvalData object is returned null for native tokens and returned for ERC-20 tokens. Allowance needs to be checked before making a tx when approvalData is returned. If contracts don't have sufficient allowance, user needs make an approval tx

Example :

Fetching the transaction data for next transaction of user with an active bridging session with activeRouteId = 6419

QUERY PARAMETERS

ParamValue

activeRouteId

6419

REQUEST

GET https://api.socket.tech/v2/route/build-next-tx?activeRouteId=6419

RESPONSE

{
  "success": true,
  "result": {
    "userTxType": "dex-swap",
    "txType": "eth_sendTransaction",
    "txData": "0x9fd7db6d0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f0000000000000000000000003e8cb4bd04d81498ab4b94a392c334f5328b237b0000000000000000000000000000000000000000000000000000000005f5e10000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000002c87c025200000000000000000000000000521709b3cd7f07e29722be0ba28a8ce0e806dbc3000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f000000000000000000000000a0020444b98f67b77a3d6de6e66af11c87da086e0000000000000000000000003e8cb4bd04d81498ab4b94a392c334f5328b237b0000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000005c0510f0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020800000000000000000000000a0020444b98f67b77a3d6de6e66af11c87da086e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024dd93f59a0000000000000000000000001111111254fb6c44bac0bed2854e76f90643097d00000000000000000000000000000000000000000000000000000000733d4004000000000000000000000000000000000000000000000000",
    "txTarget": "0x2ddf16BA6d0180e5357d5e170eF1917a01b41fc0",
    "chainId": 137,
    "totalUserTx": 3,
    "activeRouteId": 6419,
    "value": "0x00",
    "userTxIndex": 0,
    "approvalData": {
      "owner": "0x3e8cB4bd04d81498aB4b94a392c334F5328b237b",
      "allowanceTarget": "0x2ddf16BA6d0180e5357d5e170eF1917a01b41fc0",
      "approvalTokenAddress": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
      "minimumApprovalAmount": "100000000"
    }
  }
}

NEXT STEP :

The data from the response is to be used to send a transaction as illustrated in example below :

// Pseudocode 
const response = await buildNextTx();

let txParams = {
        from: fromSigner.address,
        to: txTarget,
        data: txData,
        value: value,
        gasPrice: gasPrice,
        gasLimit: sourceGasEstimate
    }
    
const tx = await signer.sendTransaction(txParams);
    
 await tx.wait()
  • Once the transaction is sent, the /route/prepare endpoint needs to be called with the transaction hash, userTxIndex and activeRouteId.

This example is elaborated in the Multi Transaction Bridging example

pageMulti Tx Example

TEST QUERY :

https://api.socket.tech/v2/swagger/#/Routes/ActiveRoutesController_nextTx

Last updated