问题描述
我尝试通过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 (将#修改为@)