Quickstart

Inscribe mint function#

1. Obtain the information required for signature#

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

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

//Define auxiliary function
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": 27, // mid-range
     "maxFeeRate": 35, //Highest gear
     "minFeeRate": 22, // low gear
     "inscriptionOutput": 546, //Inscribed output
     "minOutput" : 1500, // Minimum required output
     "normalCost" : "1800", // Consumption of a single transaction
     "maxCost" : "3600", // Maximum cost of a single transaction
     "minCost" : "600", // Minimum cost for a single transaction
   }]
}

2. Get available UTXO#

You can call the POST /api/v5/waas/transaction/get-utxo API to get the list of available UTXOs.

Instructions for filling in some parameters:
1. coinAmount = inscriptionOutput * inscribe_nums > minOutput ? inscriptionOutput * inscribe_nums : minOutput.
2. serviceCharge = normalCost * inscribe_nums.
inscribe_nums = commitTX + revealTxs, in the current mint scenario inscribe_nums is 1 + 2 = 3.
//Define your parameters
const postBody = {
   chainId: 0,
   utxoRequests: [{
     address: "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
     coinAmount: 1644,
     serviceCharge: 4800,
     utxoType: 11
   }]
};

//Define auxiliary function
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": "",
  "data": [
  {
    "address": "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
    "canTransferAmount": "27627",
    "utxoType": 11,
    "utxoList": [
      {
        "txHash": "a33ea20a5d9c1106e577f920816b4349fcda004f5c74e5896c47779e95220437",
        "vout": 0,
        "coinAmount": 27627,
        "status": 1
      }
    ]
  }
]
}

3. Generate inscribed signature info#

Call SDK to perform mint engraving operation and generate signedTx (commitTx + revealTxs[])

Instructions for filling in some parameters:
1. In the commitTxPrevOutputList of the SDK, the txId in each item corresponds to the txHash of each UTXO in the list returned by get-utxo.
2. In the InscriptionRequest of the SDK, commitFeeRate and revealFeeRate fill in the normalFeeRate returned by the get-sign-info API by default. revealOutValue fills in the inscriptionOutput returned by the get-sign-info API by default.
3. changeAddress is the change address (usually the address of the initiator).
4. revealAddr is the address engraved in the inscription (usually the address of the initiator).
import { inscribe, networks, PrevOutput, InscriptionData, InscriptionRequest } from '@okxweb3/coin-bitcoin';

// Construct an unspent input list used by engraving. Unspent items can be queried through the backend api.
const commitTxPrevOutputList: PrevOutput[] = [];
commitTxPrevOutputList.push({
   txId: "a33ea20a5d9c1106e577f920816b4349fcda004f5c74e5896c47779e95220437", // Unspent transaction ID
   vOut: 0, // Unspent output index
   amount: 27627, // unspent balance
   address: "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u", // Unspent address
   privateKey: "***sXSA1tzG9Hyc2S2ZQLsbR3o8pvzQyz9DYewrRQDcFC2vhcwGT***", // Unspent WIF encoded private key
});

// Construct the data that needs to be engraved. For batch inscription, you only need to cycle through the construction list. You can mint multiple pens at the same time, with a total of 5 + 5 = 10 mint.
const inscriptionDataList: InscriptionData[] = [];
inscriptionDataList.push({
   contentType: "text/plain;charset=utf-8", // Inscription type, represented by MIME type
   body: `{"p":"brc-20","op":"mint","tick":"tokb","amt":"5"}`, // Inscription content, utf-8 string or binary buffer
   revealAddr: "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u", // Inscription inscription (binding) address
});
inscriptionDataList.push({
   contentType: "text/plain;charset=utf-8", // Inscription type, represented by MIME type
   body: `{"p":"brc-20","op":"mint","tick":"tokb","amt":"5"}`, // Inscription content, utf-8 string or binary buffer
   revealAddr: "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u", // Inscription inscription (binding) address
});
// Custom information, including rate, change address, and inscription output amount
const request: InscriptionRequest = {
   commitTxPrevOutputList,
   commitFeeRate: 27, // Please use the current network rate to avoid pending transactions not being uploaded to the chain.
   revealFeeRate: 27,
   revealOutValue: 546,
   inscriptionDataList,
   changeAddress: "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
};

//Return the list of transactions to be broadcast. Transactions can be broadcast through the backend API.
const txs = inscribe(networks.testnet, request);

txs structure:

{
   "commitTx": "02000000000104a5093589e4b99dab2789d5f45d19e139f30ad8ed422ed068162cb0d291b4cd3604000000171600145c005c5532ce810ddf20f9d1d9 39631b47089ecdfdffffff2a4127c4ad36d98bf6ed209c88247d41c84997f0aa553e2d7d4251d12c59793d0000000000fdffffff8dbe51b56c29000af450fd949363c3 a2062a04941a19d9bf5db9d8bf8a76f583000000006b483045022100c19038816660c17f8eaa07682f3d4a1238b2bec6d6fe50601644110ee4eb90be02201c7b7 c09b5f47dc762f69a558f1b6d73a7cf915b72b4792ee6cf1033c91af8fd01210357bbb2d4a9cb8a2357633f201b9c518c2795ded682b7913c6beef3fe23bd6d2ffdffffff 417cf5848813e9612ef70de69f5a62d5694b60d1b20ef2f6497508fc2bf983850000000000fdffffff0550030000000000002251206ff0ac47ccff79fc3eaab0cd0047c2 8dead95cd35c6c695dfe33010b8807d16c3c03000000000000225120845a93ad3f2f36750672201709a48e6ad458cc00af450fd949363c3a2062a04941a19d9bf5db9d8bf8a76f583000000006b483045022100c19038816660c17f8eaa07682f3d4a1238b2bec6d6fe50601644 110ee4eb90be02201c7b7c09b5f47dc762f69a558f1b6d73a7cf915b72b4792ee6cf1033c91af8fd01210357bbb2d4a9cb8a2357633f201b9c518c2795ded682b7913 c6beef3fe23bd6d2ffdffffff417cf5848813e9612ef70de69f5a62d5694b60d1b20ef2f6497508fc2bf983850000000000fdffffff0550030000000000002251206ff0ac47 ccff79fc3eaab0cd0047c28dead95cd35c6c695dfe33010b8807d16c3c03000000000000225120845a93ad3f2f36750672201709a48e6ad458cc0a42455f0786cf3bbbe4 2a6d183803000000000000225120be60aa4826e2e3a3245158c0e7b36543ed7ead2ed40a541c4583b80d4b3762003803000000000000225120e7ff49e9dee3ddaf3 a811f12954a9c66cc98bf01c4ecb1ec093acf04ee2d1ffba6d110000000000225120b7ee7f83a6a7fdb513040856c56778aa3abea9a451e0c9bb012f22a77ed99b2102 483045022100f5604773d87ce23082bf44ef299519b7cab37414a4c2973e20baa9d4ac140ab402202c2319337194675b2a7de9ad4f1ca2d2ecb1ccc34dd0ec9647bc5843 1ac414b401210357bbb2d4a9cb8a2357633f201b9c518c2795ded682b7913c6beef3fe23bd6d2f024830450221009d0e54b2d6818768e36c88f913c4b257d7a2fec 5c9612335aa21d5cf5a933db80220404b227c68effd2e5e1c6c79cef6df5fd7c0da25afcef230ae9eec3c98da861e01210357bbb2d4a9cb8a2357633f201b9c518c279 5ded682b7913c6beef3fe23bd6d2f00014016fc622bacdaeb38aae055900b226597ae4149f32f1349f5f9d2b8f642b2c1a9e171c0c228f66eef28be0bcad551ed31b2c48a9 aa6380b7dcaba97e72cede86500000000",
   "revealTxs": [
      "0200000000010195cf7a2aacbb6604682f9462c6ff54377adbc8842e19e29037079a09ff70c8630000000000fdffffff012202000000000000225120b7ee7f83a6a 7fdb513040856c56778aa3abea9a451e0c9bb012f22a77ed99b2103405c2655b788f453c1fdba7cab2fe1be693ff7fa8b12451ceab5b4b3e8d7981713f0ad9cc0f6d547d8 9a77a8b8fdcd6c284b8a6d82ae2093f65873581563edd1c57a2057bbb2d4a9cb8a2357633f201b9c518c2795ded682b7913c6beef3fe23bd6d2fac0063036f726401 0118746578742f706c61696e3b636861727365743d7574662d3800347b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a2 278637662222c22616d74223a22313030227d6821c057bbb2d4a9cb8a2357633f201b9c518c2795ded682b7913c6beef3fe23bd6d2f00000000",
      "0300000000010234cf7a2aacbb6604682f9462c6ff54377adbc8842e19e29037079a09ff70c8630000000000fdffffff012202000000000000225120b7ee7f83a6a 7fdb513040856c56778aa3abea9a451e0c9bb012f22a77ed99b2103405c2655b788f453c1fdba7cab2fe1be693ff7fa8b12451ceab5b4b3e8d7981713f0ad9cc0f6d547d8 9a77a8b8fdcd6c284b8a6d82ae2093f65873581563edd1c57a2057bbb2d4a9cb8a2357633f201b9c518c2795ded682b7913c6beef3fe23bd6d2fac0063036f726401 0118746578742f706c61696e3b636861727365743d7574662d3800347b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a2 278637662222c22616d74223a22313030227d6821c057bbb2d4a9cb8a2357633f201b9c518c2795ded682b7913c6beef3fe23bd6d2f00000000"
   ],
  "commitTxFee": 1180,
  "revealTxFees": [223,302],
  "commitAddrs": [
    //The revealAddr of the two mints are the same, so the commitAddrs will be the same.
    "bc1pxdjk7qysnvamtkfehvaz3u2pgtr3n2ulmxxa55qag3wvhrmd549ses9fuk",
    "bc1pxdjk7qysnvamtkfehvaz3u2pgtr3n2ulmxxa55qag3wvhrmd549ses9fuk"
  ]
}

4. Generate txHash#

Call the SDK to generate the corresponding txHash for all signedTx (commit + revealTxs[]).

Instructions for filling in some parameters:
1. The data in calcTxHashParams of 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: "02000000000101110d0b153f3060700c20e3bf704b5a97d52012c8256963c543b41239ccbb6bac0000000000ffffffff02502d190000000000225120b7ee7f8 3a6a7fdb513040856c56778aa3abea9a451e0c9bb012f22a77ed99b216419000000000000225120b7ee7f83a6a7fdb513040856c56778aa3abea9a451e0c9bb012f 22a77ed99b2101406137f12926ae863937630db5719445a45d868a14198431f3c5eb16df0c45382ee30f5bc083e7b9228728376a860585173b12ddd3b56b0750 2fd7479c4dd2d77c00000000"
};
let txId = await new BtcWallet().calcTxHash(calcTxHashParams);
console.info(txId);

5. Batch transaction to inscribe mint inscriptions#

Implement the mint inscription using the batch transaction API, calling the POST /api/v5/waas/transaction/send-transaction-batch API to achieve the mint functionality for BRC-20 tokens.

broadcast_from_to_cn

Instructions for filling in some parameters:
1. The serviceCharge in the transaction obtains commitTxFee and revealTxFees[index] in the return value of the inscribe method of the SDK, respectively.
2. Under commitTx, use the address from step 3’s commitAddr for the addrTo field.
    Under revealTxs, use the address from step 3’s commitAddr for the addrFrom field.
//Define your parameters
const postBody = {
  txList: [
    {
      //commitTx
      "signedTx": "020000000001011f0e98481db78df92e6eea702420216f1a406bf318325d7c79ea02c69c5009cd0100000000fdffffff03be1a00000000000022512033656f00909b3bb5d939bb3a28f14142c719ab9fd98dda501d445ccb8f6da54bbe1a00000000000022512033656f00909b3bb5d939bb3a28f14142c719ab9fd98dda501d445ccb8f6da54ba8c700000000000022512084c74a9f1f1453548b52d866ea64029298adf21679d4e09d2c053b8886995e7401405a2a192674d7b11648dfd5f979ed7109b0570765819767addb4694afbdb8846e4b9f5cd4b503aeb58176ba574821abdea3e0f4cbc7f2d88d24f21e26d1e3aa0a00000000",
      "walletId": "13886e05-1265-4b79-8ac3-b7ab46211004",
      "addrFrom": "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
      "addrTo": "bc1pxdjk7qysnvamtkfehvaz3u2pgtr3n2ulmxxa55qag3wvhrmd549ses9fuk",
      "txHash": "e48ddae2a1bbe48eff1c06dc68deddf1685fdef9e0c568ca1af22a80f6a92971",
      "txAmount": 0,
      "chainId": 0,
      "txType": "BRC20_MINT",
      "serviceCharge": 8274,
      "tokenAddress": "btc-brc20-tokb",
      "extJson": {
        "broadcastType": 1,
        "dependTx": [],
        "feeRate": "37",
        "itemId": "commitTx"
      }
    }, {
      //revealTxs[0]
      "signedTx": "020000000001017129a9f6802af21aca68c5e0f9de5f68f1ddde68dc061cff8ee4bba1e2da8de40000000000fdffffff01220200000000000022512084c74a9f1f1453548b52d866ea64029298adf21679d4e09d2c053b8886995e7403406869d46a486b2961981346fe52d1103b3d4d929f4b20ec0425cd0da0eb3a71c0f23d980ac86539a85fc4d51078952868f23b5d4d8dde1b78374b30ebbc3241c87820da459477b18d59be71a3ab0c0565abf3ca79b3e34f4ea66accdfa749c900f163ac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d3800327b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a22746f6b62222c22616d74223a2235227d6821c1da459477b18d59be71a3ab0c0565abf3ca79b3e34f4ea66accdfa749c900f16300000000",
      "walletId": "13886e05-1265-4b79-8ac3-b7ab46211004",
      "addrFrom": "bc1pxdjk7qysnvamtkfehvaz3u2pgtr3n2ulmxxa55qag3wvhrmd549ses9fuk", // commitAddrs
      "addrTo": "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
      "txHash": "945c94dc5f596a198238954e6d898fef359c3f64b199698d0899b6b08ee6cf08",
      "txAmount": 0,
      "chainId": 0,
      "txType": "BRC20_MINT",
      "serviceCharge": 6300,
      "tokenAddress": "btc-brc20-tokb", // MINT、TRANSFER 需填写 tokenAddress, 格式为 btc-btc20-<TICK_NAME>
      "extJson": {
        "broadcastType": 1,
        "dependTx": ["e48ddae2a1bbe48eff1c06dc68deddf1685fdef9e0c568ca1af22a80f6a92971"],
        "feeRate": "37",
        "itemId": "revealTx0"
      }
    }, {
      //revealTxs[1]
      "signedTx": "020000000001017129a9f6802af21aca68c5e0f9de5f68f1ddde68dc061cff8ee4bba1e2da8de40100000000fdffffff01220200000000000022512084c74a9f1f1453548b52d866ea64029298adf21679d4e09d2c053b8886995e7403404b97839e651a6642deffea77469efc225ff30d2eff037a34bcd899738fb3664a23742fba56f95af5f5e7c0468f642c4264e8d18719a3cdcbb88c6a597eef7d2b7820da459477b18d59be71a3ab0c0565abf3ca79b3e34f4ea66accdfa749c900f163ac0063036f7264010118746578742f706c61696e3b636861727365743d7574662d3800327b2270223a226272632d3230222c226f70223a226d696e74222c227469636b223a22746f6b62222c22616d74223a2235227d6821c1da459477b18d59be71a3ab0c0565abf3ca79b3e34f4ea66accdfa749c900f16300000000",
      "walletId": "13886e05-1265-4b79-8ac3-b7ab46211004",
      "addrFrom": "bc1pxdjk7qysnvamtkfehvaz3u2pgtr3n2ulmxxa55qag3wvhrmd549ses9fuk", // commitAddrs
      "addrTo": "bc1psnr548clz3f4fz6jmpnw5eqzj2v2musk082wp8fvq5ac3p5ete6qg05u8u",
      "txHash": "350c1be760c92c5d11823a1f04153e0534b20d458284f6544965a2dba2b6c27c",
      "txAmount": 0,
      "chainId": 0,
      "txType": "BRC20_MINT",
      "serviceCharge": 6300,
      "tokenAddress": "btc-brc20-tokb",
      "extJson": {
        "broadcastType": 1,
        "dependTx": ["e48ddae2a1bbe48eff1c06dc68deddf1685fdef9e0c568ca1af22a80f6a92971"],
        "feeRate": "37",
        "itemId": "revealTx1"
      }
    }
  ]
};

//Define the helper function
const sendTransactionData = async () => {
   const apiRequestUrl = getRequestUrl(
       apiBaseUrl,
       '/api/v5/waas/transaction/send-transaction-batch'
   );
   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": [{
   "txHashList":[
   {
     "itemId":"commitTx",
     "txHash":"e48ddae2a1bbe48eff1c06dc68deddf1685fdef9e0c568ca1af22a80f6a92971"
   },
   {
     "itemId":"reveal0",
       "txHash":"945c94dc5f596a198238954e6d898fef359c3f64b199698d0899b6b08ee6cf08"
   },
   {
     "itemId":"reveal1",
       "txHash":"350c1be760c92c5d11823a1f04153e0534b20d458284f6544965a2dba2b6c27c"
   }
   ]
 }]
}

6. Wait for push notification or query transaction history#

Wait for notifications or actively query transaction history (these steps have been mentioned in the wallet quick start and are not further discussed here). After the transaction is successful, proceed to the next step: engrave transfer inscriptions.