Quickstart

Transfer inscriptions#

1. Obtain the information required for signing#

Call the POST /api/v5/waas/transaction/get-sign-info API to query some data required for the signature, including the fee rate and other information required by the BTC exchange.

//Define your parameters
const postBody = {
  addrFrom: "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
  addrTo: "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
  txAmount: "0",//fill in 0 here
  chainId: "0",
  extJson: { }
};

//Define auxiliary functions
const sendData = async () => {
  const apiRequestUrl = getRequestUrl(
    apiBaseUrl,
    '/api/v5/waas/transaction/get-sign-info'
  );
  return fetch(apiRequestUrl, {
    method: 'POST',
    headers: headersParams,
    body: JSON.stringify(postBody),
  })
  .then((res) => res.json())
  .then((res) => {
    return res;
  });
};

const { data: sendData } = await sendData();

After calling the API, you will receive the following response:

{
  "code": 0,
  "msg": "",
  "data": [{
    "normalFeeRate": 78,//Medium
    "maxFeeRate": 97,//highest gear
    "minFeeRate": 65,//low gear
    "inscriptionOutput": 546,//inscribed output
    "minOutput": 1500,//minimum required output
    "normalCost": "1800",//Cost per transaction
    "maxCost": "3600",//Maximum cost per transaction
    "minCost": "600",//Minimum cost per transaction
  }]
}

2. Get the transferable BRC-20#

To get a transferable BRC-20, you can call the POST /api/v5/waas/transaction/get-utxo-brc20 API to get a list of transferable UTXOs.

//Define your parameters
const postBody = {
  "chainId":0,
  "utxoRequests":[{
    "address":"bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
    "tick":"tokb",
    "page": 1,
    "pageSize": 10
  }]
};

//Define auxiliary functions
const sendData = async () => {
  const apiRequestUrl = getRequestUrl(
      apiBaseUrl,
      '/api/v5/waas/transaction/get-utxo-brc20'
  );
  return fetch(apiRequestUrl, {
    method: 'POST',
    headers: headersParams,
    body: JSON.stringify(postBody),
  })
  .then((res) => res.json())
  .then((res) => {
    return res;
  });
};

const { data: sendData } = await sendData();

After calling the API, you will receive the following response:

{
  "code": 0,
  "msg": "success",
  "data": [{
    "address": "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
    "utxoList": [{
      "txHash": "a1a41ccfe62ba715a085059ee455f164f649b5321ebb361ef6a4d65b24b047a0",
      "vout": 0,
      "coinAmount": 546,
      "status": 1,
      "inscriptionId": "#46039932",
      "tick": "tokb",
      "tokenAmount": "1000000000000000000",
      "nftLocaltionVOs": [{
        "nftId": "a1a41ccfe62ba715a085059ee455f164f649b5321ebb361ef6a4d65b24b047a0i0",
        "nftLocation": "a1a41ccfe62ba715a085059ee455f164f649b5321ebb361ef6a4d65b24b047a0:0:0"
      }]
    }]
  }]
}

3. Get available utxo#

When the corresponding UTXO of the transferable BRC-20 is not enough to pay the transaction fee, the POST /api/v5/waas/transaction/get-utxo API can also be called to obtain the list of other available UTXOs.

//Define your parameters
const postBody = {
  "chainId":0,
  "utxoRequests":[{
    "address":"bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
    "coinAmount":1500,
    "serviceCharge":3600,
    "utxoType":1
  }]
};

//Define auxiliary functions
const sendData = async () => {
  const apiRequestUrl = getRequestUrl(
    apiBaseUrl,
    '/api/v5/waas/transaction/get-utxo'
  );
  return fetch(apiRequestUrl, {
    method: 'POST',
    headers: headersParams,
    body: JSON.stringify(postBody),
  })
  .then((res) => res.json())
  .then((res) => {
    return res;
  });
};

const { data: sendData } = await sendData();

After calling the API, you will receive the following response:

{
  "code": 0,
  "msg": "success",
  "data": [{
    "address": "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
    "canTransferAmount": "321971",
    "utxoType": 1,
    "utxoList": [{
      "txHash": "82c51ff69fd0a55968e346f7093cb9088ce8b60b60a2493c8a5bc57b977ce348",
      "vout": 0,
      "coinAmount": 200000,
      "status": 1
    }]
  }]
}

4. Call the SDK to generate signTx for ordinary transfers#

Fill in the instructions for some parameters:
1. Fill in the UTXO with the tokb inscription. If amout is not enough, you need to add the unoccupied UTXO.
2. Outputs Fill in the wallet address and UTXO amount of the target transferor.
3. The address is the change address (own address).
4. Fill in the normalFeeRate in get-sign-info with feePerB.
import { BtcWallet } from "@okxweb3/coin-bitcoin";

let wallet = new BtcWallet()
let btcTxParams = {
  type: 0
  inputs: [
    {
      //get-utxo-brc20 returns utxoList BRC-20 tokens
      txId: "a1a41ccfe62ba715a085059ee455f164f649b5321ebb361ef6a4d65b24b047a0",
      vOut: 0,
      amount: 546
    },
    {
      //get-utxo returns utxoList
      txId: "82c51ff69fd0a55968e346f7093cb9088ce8b60b60a2493c8a5bc57b977ce348",
      vOut: 0,
      amount: 200000
    }
  ],
  outputs: [
    {
      address: "bc1p9nkcnw8ae9az43uamnaws2e9nvlzm8yjxh48mr3ywvcy7tns6ywqdq77l4",
      amount: 546
    }
  ],
  address: "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
  feePerB: 72
};

let signParams: SignTxParams = {
  privateKey: "***sXSA1tzG9Hyc2S2ZQLsbR3o8pvzQyz9DYewrRQDcFC2vhcwGT***",
  data: btcTxParams
};
let tx = await wallet.signTransaction(signParams);

5. Generate txHash#

Call the SDK to generate the corresponding txHash for the signedTx (there is only one in this case)

Fill in the instructions for some parameters:
1. The data data in the calcTxHashParams of the SDK corresponds to the generated signedTx, and the generated txId is txHash.
import { inscribe, networks, PrevOutput, InscriptionData, InscriptionRequest } from '@okxweb3/coin-bitcoin';

let calcTxHashParams = {
  data: "02000000000101110d0b153f3060700c20e3bf704b5a97d52012c8256963c543b41239ccbb6bac0000000000ffffffff02502d190000000000225120b7ee7f83a6a7fdb513040856c56778aa3abea9a451e0c9bb012f22a77ed99b216419000000000000225120b7ee7f83a6a7fdb513040856c56778aa3abea9a451e0c9bb012f22a77ed99b2101406137f12926ae863937630db5719445a45d868a14198431f3c5eb16df0c45382ee30f5bc083e7b9228728376a860585173b12ddd3b56b07502fd7479c4dd2d77c00000000"
};
let txId = await new BtcWallet().calcTxHash(calcTxHashParams);
console.info(txId);

6. Broadcast transactions#

The transfer of Okex tokens is realized by broadcasting the transaction API, and the POST /api/v5/waas/transaction/send-transaction API is called to realize the deploy function of BRC20 tokens.

Fill in the instructions for some parameters:
1. Fill in 0 for serviceCharge.
2. txAmout Fill in the transfer amount of BRC-20 tokens * accuracy.
//Define your parameters
const postBody = {
  "signedTx": "02000000000102a047b0245bd6a4f61e36bb1e32b549f664f155e49e0585a015a72be6cf1ca4a10000000000ffffffff48e37c977bc55b8a3c49a2600bb6e88c08b93c09f746e36859a5d09ff61fc5820000000000ffffffff0222020000000000002251202ced89b8fdc97a2ac79ddcfae82b259b3e2d9c9235ea7d8e2473304f2e70d11ca8cc02000000000022512084c74a9f1f1453548b52d866ea64029298adf21679d4e09d2c053b8886995e740140e2a4435a723e8e59bdc0941e4d9285133a861c60e2f8dbf0961d9062572bba540807dd2f1f1f2783e81e43f41eb6681f177b690df94cd237011f04010d70f56701405e2e2759704c410d0f501160e65fb047a8167fd260093ca65cd5925bd02516f9cce33bf02e1afdb3788f847ceb78040883c2f8aa4a08607baa624cbf4d5b389f00000000",
  "walletId": "13886e05-1265-4b79-8ac3-b7ab46211004",
  "addrFrom": "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
  "addrTo": "bc1p9nkcnw8ae9az43uamnaws2e9nvlzm8yjxh48mr3ywvcy7tns6ywqdq77l4",
  "txHash": "196b1c9a4a1151af320b874790fda1f83eda43182d3633f20e0b296f8bc7d5d8",
  "txAmount": "1000000000000000000",
  "chainId": 0,
  "txType": "BRC20_SEND",
  "serviceCharge": 0,
  "tokenAddress": "btc-brc20-tokb",
  "extJson": {
    "feeRate": "78"
  }
};

//Define auxiliary functions
const sendTransactionData = async () => {
  const apiRequestUrl = getRequestUrl(
    apiBaseUrl,
    '/api/v5/waas/transaction/send-transaction'
  );
  return fetch(apiRequestUrl, {
    method: 'POST',
    headers: headersParams,
    body: JSON.stringify(postBody),
  })
  .then((res) => res.json())
  .then((res) => {
    return res;
  });
};

const { data: sendTransactionData } = await sendTransactionData();

After calling the API, you will receive the following response:

{
  "code": 0,
  "msg": "success",
  "data": [{
    "orderId": "486750864669831168"
  }]
}