1

我试图将 erc20 (Bela) 从一个地址发送到另一个地址,结果得到了 tx id,但此交易没有出现在任何 tx 检查服务中,也没有从我的地址发送资金。目前的代码如下所示:

web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/PKEY'));


var myAddress = "0x4d0...";
var toAddress = "0xce6...";
var amount = web3.utils.toHex(5);

var count = web3.eth.getTransactionCount(myAddress).then(function(v){console.log(v); count = v});

var privateKey = new Buffer('pkey', 'hex');

//got from https://etherscan.io/address/0x2e98a6804e4b6c832ed0ca876a943abd3400b224#code
var abiArray = '';

var contractAddress = '0x2e98a6804e4b6c832ed0ca876a943abd3400b224';
var contract = new web3.eth.Contract(abiArray, contractAddress, {from: myAddress});

var rawTransaction = {
    "from":myAddress,
    "gasPrice":"0x098bca5a00",
    "gasLimit":"0xcb05",
    "to":contractAddress,
    "value":"0x0",
    "data":contract.methods.transfer(toAddress, amount).encodeABI(),
    "nonce":web3.utils.toHex(count)
};
var transaction = new Tx(rawTransaction);
transaction.sign(privateKey);

web3.eth.sendSignedTransaction('0x' + transaction.serialize().toString('hex'), function (err, hash) {
    console.log(err, hash);
});

4

1 回答 1

0

使用 contract._address 更新交易对象中的“to”地址

于 2022-02-10T13:06:23.830 回答