[英]Getting Error: Returned error: Must be authenticated! , while sending erc20 code using web3.js
const fs = require('fs');
let web3 = new Web3(new Web3.providers.HttpProvider('http:127.0.0.1'))
const abi = fs.readFileSync('erc20_abi.json', 'utf-8')
const contractAddress = '0xB4...'
const privateKey = '...'
let contract = new web3.eth.Contract(JSON.parse(abi), contractAddress);
let transfer = contract.methods.transfer("0xd...", 10);
let encodedABI = transfer.encodeABI();
var tx = {
from: "0xF...",
to: contractAddress,
gas: 2000000,
data: encodedABI
};
web3.eth.accounts.signTransaction(tx, privateKey).then(signed => {
var tran = web3.eth.sendSignedTransaction(signed.rawTransaction);
tran.on('confirmation', (confirmationNumber, receipt) => {
console.log('confirmation: ' + confirmationNumber);
});
tran.on('transactionHash', hash => {
console.log('hash');
console.log(hash);
});
tran.on('receipt', receipt => {
console.log('reciept');
console.log(receipt);
});
tran.on('error', console.error);
});
I am using the above code to send ERC20 tokens from account to another account, Its throwing this error我正在使用上面的代码将 ERC20 令牌从帐户发送到另一个帐户,它会抛出此错误
UnhandledPromiseRejectionWarning: Error: Returned error: Must be authenticated UnhandledPromiseRejectionWarning:错误:返回错误:必须经过身份验证
我发现我使用了错误的 rpc 提供程序,更改 Rpc 提供程序可以解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.