【发布时间】:2018-07-14 18:42:39
【问题描述】:
我正在发送已签名的交易并收到错误:
资金不足。您尝试从中发送交易的帐户 没有足够的资金。需要 750000000000000 得到:0。
问题是我的账户有足够的资金,你可以在这里查看0x002D189c25958c60736aE21C966ff3131C2AC849 如果我设置了gasLimit:web3.utils.toHex(20000),那么我会得到另一个错误:
交易气体太低。没有足够的气体来覆盖最小 交易成本(最低:21464,得到:20000)。尝试增加 供气。
这是我的node / web3 代码:
const Web3 = require('web3')
// connect to Infura node
const web3 = new Web3(new Web3.providers.HttpProvider('https://kovan.infura.io/api_key'))
// the addresses & private key
const addressFrom = '0x002D189c25958c60736aE21C966ff3131C2AC849';
const contractAddress = '0x36075430619b21Fff798454e2D5C81E9C18DEe81';
const privKey = '240462d...';
//ABI objects
var contractABI = new web3.eth.Contract(
[ ...abi... ],
contractAddress);
const contractFunction = contractABI.methods.changeBox(5);
const functionABI = contractFunction.encodeABI();
// construct the Tx data
const rawTx = {
//gasPrice: '0x09184e72a000',
gasLimit: web3.utils.toHex(25000),
to: contractAddress,
from: addressFrom,
data: functionABI
};
//sign & send Tx
web3.eth.accounts.signTransaction(rawTx, privKey)
.then(RLPencodedTx => {
web3.eth.sendSignedTransaction(RLPencodedTx['rawTransaction'])
.on('receipt', console.log);
});
有人知道为什么 web3 会抛出这些错误的错误吗?
【问题讨论】:
-
你是如何从私钥得到地址的?你确定你有那个钥匙的正确地址吗?旁注:你不应该需要 10 Terawei 的汽油价格才能包含在一个区块中。最近的几笔交易包含在 30 Gigawei。
-
我通过
Parity创建了账户,并将账户导出为json文件,其中包含ciphertext,这是私钥 -
另外,我看到你喜欢 python。有一些python工具可以做类似的工作,例如:web3py.readthedocs.io/en/stable/web3.eth.account.html
标签: javascript node.js ethereum web3