简体   繁体   English

如何使用 metamask/web3.js 发送 BUSD

[英]How to send BUSD with metamask/web3.js

I have two coins in binance testnet:我在币安测试网中有两个硬币:

在此处输入图像描述

I can send default main coins (BNB) to another account:我可以将默认主币(BNB)发送到另一个账户:

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

But i don't know how to send other coins (USDT or BUSD).但我不知道如何发送其他硬币(USDT 或 BUSD)。

Also i can check current amount of coins, but only for BNB:我也可以检查当前的硬币数量,但仅限于 BNB:

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

When you transfer tokens, you interact with the token contract invoking its transfer() function.当您转移代币时,您与调用其transfer() function 的代币合约进行交互。

Same goes for the token balance - you can get the user token balance by querying the token contract's balanceOf() function.代币余额也是如此——您可以通过查询代币合约的balanceOf() function 来获取用户代币余额。

These functions are specified in the ERC-20 standard, so each token contract following the standard implements them.这些功能是在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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM