zoidpay-blockchain-helpers 中文文档教程

发布于 2年前 浏览 15 项目主页 更新于 2年前

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

ESDTNFTSFTMetaESDT
transferissueNonFungibleissueSemiFungibleregisterMetaESDT
localMintsetSpecialRolesetSpecialRolechangeSFTToMetaESDT
localBurnESDTNFTCreateESDTNFTCreate
issuetransferNFTCreateRoleESDTNFTBurn
pausestopNFTCreateESDTNFTAddQuantity
unPauseESDTNFTUpdateAttributes
freezeESDTNFTAddURI
unFreezefreezeSingleNFT
setSpecialRoleunFreezeSingleNFT
unSetSpecialRolewipeSingleNFT
controlChangesESDTNFTTransfer
transferOwnership
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文