如何使用 web3.jsBSC 测试网络发送带有元掩码的 BNB

问题描述

我想在 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)。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...