Customs extrinsics & queries
Last updated
Last updated
Ternoa-js provides the capability to create custom calls to the blockchain. If existing helpers do not meet your requirements, you can still perform custom operations thanks to the library's atomic architecture.
You should not have to install directly the Polkadot{js} library as the ternoa js might cover all your needs.
If you have explored the , you would have noticed that the functions are interdependent to maintain modularity and enhance the customized usage of these functions.
Under the hood, extrinsics helpers provided on the SDK rely on this function: createTxHex()
which creates a transaction in hex format:
The createTxHex()
function expects three params:
txPallet
is a string corresponding to the name of the pallet. Example for an NFT mint: "nft"
txExtrinsic
is a string corresponding to the name of the extrinsic to execute. Example for an NFT mint: "createNft"
txArgs
is an optional array of arguments needed to execute the extrinsic. Example for an NFT mint: [offchainData, royalty, collectionId, isSoulbound ]
Assuming you want to execute a transaction that is not natively proposed as a helper in the SDK, for example, a bridge deposit. Your atomic function could look like this:
or
Performing custom queries works the same, except that instead of using the createTxHex()
function, it uses the query()
function that executes under the hood, the following code:
The query()
function expects three params:
module
is a string corresponding to the name of the pallet. Example to query the NFT mint fee: "nft"
call
is a string corresponding to the name of the call to execute. Example to query the NFT mint fee: "nftMintFee"
args
is an optional array of arguments needed to execute the query. Example to query the NFT mint fee: [ ] as no argument is expected for this query.
Same as the custom extrinsic, you can perform the desired custom query by specifying the arguments of your choice.
Feel free to look at the to see the available queries, extrinsics, or constants and make your custom requests.