【发布时间】:2021-09-15 01:46:40
【问题描述】:
我正在尝试使用此代码将 erc20token 从合约地址转移到 eth 地址:
var _from = "from Address";
var contAddress = "contract address";
var _to = "to address";
var _Amount = '50';
var txnObject = {
"from":_from,
"to": _to,
"value": web3.utils.toWei(_Amount,'ether'),
// "gas": 21000, (optional)
// "gasPrice": 4500000, (optional)
// "data": 'For testing' (optional)
// "nonce": 10 (optional)
}
web3.eth.sendTransaction(txnObject, function(error, result){
if(error){
console.log( "Transaction error" ,error);
}
else{
var txn_hash = result; //Get transaction hash
//$('#Tx').text(txn_hash);
alert(txn_hash);
}
});
但我收到此错误:
Transaction error Error: Returned error: The method eth_sendTransaction does not exist/is not available
我已经搜索了很多并尝试了此代码,但它没有工作。可能是什么原因?这段代码是错误的还是别的什么?
注意:我使用的是 infura ropsten 网络节点。
【问题讨论】: