问题描述
我想在 BSC 测试网络上使用 web3.js 从我的元掩码钱包发送 BNB。我不知道我该怎么做。此代码在我的钱包中发送 ETH,但我无法发送 BNB。如果你能帮忙我会很高兴..
const holder = ethereum.selectedAddress;
// paymentAddress is where funds will be send to
const paymentAddress = '0xEdccc7De37305372c3a274aF32Bc0eed26D1891C'
const amount = web3.utils.toWei("0.000011","ether")
web3.eth.sendTransaction({
from: holder,to: '0x0B75fbeB0BC7CC0e9F9880f78a245046eCBDBB0D',value: '1000000000000000000',},function(err,transactionHash) {
if (err) {
console.log('Payment Failed',err)
$('#status').html('Payment Failed')
} else {
console.log(transactionHash);
$('#status').html('Payment successful')
}
});
解决方法
您需要在交易对象中指定chainId: '56'
(即BSC的ID-source)。