我尝试使用 web3.js 转移我的 BEP-20 令牌
我部署了新的 BEP-20 令牌,并且可以使用 MetaMask 将令牌发送到另一个地址。
我试图转移到nodejs。我按照指南发送令牌。
下面是我的代码
const sendBEP20Transaction = async () => {
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider('https://bsc-dataseed1.binance.org'))
var myAddress = '0xF3b6A45AFbC5892a70EA7ca5b10d61A500BeCeC1';
var toAddress = '0xa5915F48DDD3A7D25Daf1AeBd5Df677389b679bA';
var privateKey = 'd5...';
var abiArray = [...];
var contractAddress = '0xcB39dAF817EC0BaDDF78719dA24768b3fe81A7b5';
var amount = web3.utils.toHex(10)
var count;
await web3.eth.getTransactionCount(myAddress).then(function (v) {
console.log('count: ', v);
count = v
})
let account = web3.eth.accounts.wallet.add(privateKey);
var contract = new web3.eth.Contract(abiArray, contractAddress, {
from: myAddress,
gasPrice: web3.utils.toHex(5),
gasLimit: web3.utils.toHex(80000),
})
contract.methods.transfer(toAddress, amount).send({
from: '0xF3b6A45AFbC5892a70EA7ca5b10d61A500BeCeC1',
gasPrice: web3.utils.toHex(5),
gasLimit: web3.utils.toHex(80000),
})
.then()
.catch(console.error);
}
当我运行此代码时,出现错误“返回错误:交易价格过低”
Error: Returned error: transaction underpriced
at Object.ErrorResponse (F:\bep20_test\node_modules\web3-core-helpers\lib\errors.js:28:19)
at F:\bep20_test\node_modules\web3-core-requestmanager\lib\index.js:304:36
at XMLHttpRequest.request.onreadystatechange (F:\bep20_test\node_modules\web3-providers-http\lib\index.js:98:13)
at XMLHttpRequestEventTarget.dispatchEvent (F:\bep20_test\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (F:\bep20_test\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (F:\bep20_test\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (F:\bep20_test\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
data: null
}
任何人请帮助我,谢谢