如何解决使用web3的Object.exports.toBuffer中的类型无效
我尝试通过Truffle将原始交易发送给Ganache。 错误消息“ Object.exports.toBuffer处的类型无效”。
代码如下:
const Tx = require('ethereumjs-tx').Transaction;
const privateKey = Buffer.from('5b58ae3fe5bf48d05f0a94c87a28fb480ec2bc200a4423ab42ea9557f3617743','hex');
const payment_usercashTx = {
nonce: myAsyncNonceFunction(),gasPrice: web3.utils.toHex(25000),gasLimit: web3.utils.toHex(10e9),to: '0x107180312267DB452930731EA475187BdD4948DB',from: web3.eth.defaultAccount,value: '0x00',data: encode_usercash
}
let usercashTx = new Tx(payment_usercashTx);
usercashTx.sign(privateKey);
let usercash_serializedTx = usercashTx.serialize();
web3.eth.sendSignedTransaction('0x' + usercash_serializedTx.toString('hex'))
.on('receipt',console.log);
新消息:
Error: invalid type
at Object.exports.toBuffer (/Users/yuha/Desktop/blockchainProject/Kidari/node_modules/ethereumjs-util/dist/bytes.js:97:19)
at Transaction.setter [as nonce] (/Users/yuha/Desktop/blockchainProject/Kidari/node_modules/ethereumjs-util/dist/object.js:43:25)
at /Users/yuha/Desktop/blockchainProject/Kidari/node_modules/ethereumjs-util/dist/object.js:96:38
at Array.forEach (<anonymous>)
at Object.exports.defineProperties (/Users/yuha/Desktop/blockchainProject/Kidari/node_modules/ethereumjs-util/dist/object.js:94:20)
at new Transaction (/Users/yuha/Desktop/blockchainProject/Kidari/node_modules/ethereumjs-tx/dist/transaction.js:127:27)
at Object.<anonymous> (/Users/yuha/Desktop/blockchainProject/Kidari/routes/payment.js:72:18)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。