【问题标题】:How to send BUSD with metamask/web3.js如何使用 metamask/web3.js 发送 BUSD
【发布时间】:2021-12-28 23:50:31
【问题描述】:

我在币安测试网中有两枚硬币:

我可以将默认主币(BNB)发送到另一个账户:

web3.eth.sendTransaction({
   from: account,
   to: '0x64123c0c6cc87a7b96c498D584Db17c6cA55eD6F',
   value: '1000000',
}, function (err, transactionHash) {
                    
});

但我不知道如何发送其他硬币(USDT 或 BUSD)。

我也可以查看当前的硬币数量,但仅限于 BNB:

const balance = await this.web3.eth.getBalance(account);

【问题讨论】:

    标签: javascript web3js metamask


    【解决方案1】:

    当您转移代币时,您会与调用其transfer() 函数的代币合约进行交互。

    代币余额也是如此——你可以通过查询代币合约的balanceOf()函数来获取用户的代币余额。

    这些函数在ERC-20标准中指定,因此每个遵循该标准的代币合约都会实现它们。

    const usdtContract = new this.web3.eth.Contract(abiJson, contractAddress);
    
    // sends a transaction from the `sender` address
    // containing the `data` field specifying that you want to execute
    // the `transfer()` function, passing it the `recipient` and `amount` arguments
    await usdtContract.methods.transfer(recipient, amount).send({from: sender});
    
    // performs a gas-free read-only call, invoking the `balanceOf()` function of the contract
    await usdtContract.methods.balanceOf(holder).call();
    

    【讨论】:

      猜你喜欢
      • 2021-11-19
      • 2021-08-23
      • 2022-06-27
      • 1970-01-01
      • 2021-07-25
      • 2020-03-29
      • 2020-05-29
      • 1970-01-01
      • 2018-05-04
      相关资源
      最近更新 更多