Create Internal Transfer

To create an internal transfer, first obtain the msg hash from the initiate endpoint /initiate/. Next, sign msgHash with your L2 key using the signInternalTxMsgHash function. Finally, provide the signed message along with other required information to the process transfer API /process/.

Note: You will need to include the JWT Auth token to request headers to access this endpoint. To get the JWT Auth Token, refer the login section of this document.

1. Initiate Internal Transfer

Before creating a new Internal Transfer, you will be required to obtain a msg hash by making use of this endpoint. Please note that this is a Private πŸ”’ route which means it needs to be authorized by the account initiating this request.

Endpoint

POST /sapi/v1/internal_transfers/v2/initiate/

Request Headers

{
  "Authorization": "JWT ***"
}

Request Body

Response

{
  "status": "success",
  "message": "Please sign the message, to complete the transaction",
  "payload": {
    "msg_hash": "0x1234567890abcdef",
    "nonce": 123456
  }
}

2. Sign the msg_hash with the L2 key pair

To sign the msg_hash obtained from the above endpoint, you need to generate the L2 key pair. Use the Nodejs-sdk to generate the L2 key pair from your Ethereum private key. 2.1 Generating a L2 key pair from an ethereum private key

import { generateKeyPairFromEthPrivateKey } from '@tanx-libs/tanx-connector'

const keypair = generateKeyPairFromEthPrivateKey(
    ethPrivateKey, 
    'testnet' // The default value is "mainnet," and the allowed values are ['testnet', 'mainnet'].
) 

2.2 Use the L2 key pair to sign the msg_hash obtained from the initiate endpoint.

import { signInternalTxMsgHash } from '@tanx-libs/tanx-connector'

 const signature = signInternalTxMsgHash(
      keyPair,
      initiateResponse.payload.msg_hash,
 )

3. Process Internal Transfer

Process an internal transfer between two users. Before processing the transfer, you will be required to obtain a signature by using the initiate endpoint and the signing utils. Please note that this is a private πŸ”’ route, which means it needs to be authorized by the account initiating this request.

Endpoint

POST /sapi/v1/internal_transfers/v2/process/

Request Headers

{
  "Authorization": "JWT ***"
}

Request Body

Response

{
    "status": "success",
    "message": "Internal transfer processed successfully",
    "payload": {
        "client_reference_id": "795278363509343",
        "amount": "1",
        "currency": "usdc",
        "from_address": "0x1234",
        "destination_address": "0x1234",
        "status": "success",
        "created_at": "2023-07-12T04:42:22.639933Z",
        "updated_at": "2023-07-12T04:43:37.373071Z"
    }
}

Last updated