zoidpay-blockchain-helpers 中文文档教程
Blockchain helper
What does it do?
Facilitates the Elrond blockchain transactions for ESDT, SFT, NFT and METAESDT.
How to use?
Instantiate the Elrond class like follows:
const elrond = new Elrond({
address: "erd1lv6eyd8mwprssw7qcx5zpghggcd95wxas27pwhyygsx75c5we5zskn5k8e", // your address
password: "Azerty.2023", // your password
jsonWallet: walletObject, // your wallet object
networkProvider: "https://devnet-api.multiversx.com" // network you want to use
});
The password
and walletObject
fields are optional, however, if you do not provide them when instantiating the Elrond object, you will not be able to sign and send the transaction with the helper functions signTransaction()
and sendTransaction()
.
Build transaction
Create your payload object, depending on what transaction you want to make. For example, if you wanted to make a token transfer, the payload would look like this:
const createNFTpayload = {
tokenTicker: "MMM-e4f01d",
valueToTransfer: 100,
addressToSendTo: "erd1lv6eyd8mwprssw7qcx5zpghggcd95wxas27pwhyygsx75c5we5zskn5k8e"
}
let tx = await elrond.buildTransaction({
transactionCategory: TransactionCategory.NFT,
transactionType: NFTFunctions.ESDTNFTCreate,
operationsData: createNFTpayload
});
Observation:
when the data payload contains an address it must be already converted from a bech32 to hex format when placed as input. Always look for this type of format to input:
fb359234fb7047083bc0c1a820a2e8461a5a38dd82bc175c84440dea628ecd05
Example of transaction: ``` tx = new Transaction({ gasLimit: builtData.gasLimit, sender: new Address(this.address), ===== Accepted format of address: ```erd1lv6eyd8mwprssw7qcx5zpghggcd95wxas27pwhyygsx75c5we5zskn5k8e``` receiver: new Address(builtData.actionAddress), ===== Accepted of address format: ```erd1lv6eyd8mwprssw7qcx5zpghggcd95wxas27pwhyygsx75c5we5zskn5k8e``` value: builtData.value, chainID: chainId, nonce: nonce, data: new TransactionPayload(builtData.data) ===== Accepted format of address here: ```fb359234fb7047083bc0c1a820a2e8461a5a38dd82bc175c84440dea628ecd05``` }); ```
Sign transaction
elrond.signTransaction(tx);
Send signed transaction
elrond.sendTansaction(tx, await elrond.establishConnection());
Available functions
ESDT | NFT | SFT | MetaESDT |
---|---|---|---|
transfer | issueNonFungible | issueSemiFungible | registerMetaESDT |
localMint | setSpecialRole | setSpecialRole | changeSFTToMetaESDT |
localBurn | ESDTNFTCreate | ESDTNFTCreate | |
issue | transferNFTCreateRole | ESDTNFTBurn | |
pause | stopNFTCreate | ESDTNFTAddQuantity | |
unPause | ESDTNFTUpdateAttributes | ||
freeze | ESDTNFTAddURI | ||
unFreeze | freezeSingleNFT | ||
setSpecialRole | unFreezeSingleNFT | ||
unSetSpecialRole | wipeSingleNFT | ||
controlChanges | ESDTNFTTransfer | ||
transferOwnership |