简体   繁体   中英

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:

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).

Also i can check current amount of coins, but only for BNB:

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

When you transfer tokens, you interact with the token contract invoking its transfer() function.

Same goes for the token balance - you can get the user token balance by querying the token contract's balanceOf() function.

These functions are specified in the ERC-20 standard, so each token contract following the standard implements them.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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