以太坊 web3 sendSignedTransaction:资金不足。该帐户...没有足够的资金。需要 750000000000000 并得到:0
Ethereum web3 sendSignedTransaction: Insufficient funds. The account ... does not have enough funds. Required 750000000000000 and got: 0
我正在发送已签名的交易并收到错误:
Insufficient funds. The account you tried to send transaction from
does not have enough funds. Required 750000000000000 and got: 0.
问题是我的账户有足够的资金,你可以在这里查看0x002D189c25958c60736aE21C966ff3131C2AC849
如果我设置 gasLimit:web3.utils.toHex(20000)
,那么我会得到另一个错误:
Transaction gas is too low. There is not enough gas to cover minimal
cost of the transaction (minimal: 21464, got: 20000). Try increasing
supplied gas.
这是我的 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 会抛出这些错误吗?
I have created the account via Parity and also exported the account as json file, which contains ciphertext
, which is the private key
cipthertext
是私钥的 加密 版本。这个Q&A includes some deeper background,如果你好奇的话。
要获取您的私钥,您需要密钥文件和用于加密它的密码。然后您可以使用 web3.js v1(测试版)中的 web3.eth.accounts.decrypt()
来提取密钥,如下所示:
web3.eth.accounts.decrypt({
version: 3,
id: '04e9bcbb-96fa-497b-94d1-14df4cd20af6',
address: '2c7536e3605d9c16a7a3d7b1898e529396a65c23',
crypto: {
ciphertext: 'a1c25da3ecde4e6a24f3697251dd15d6208520efc84ad97397e906e6df24d251',
cipherparams: { iv: '2885df2b63f7ef247d753c82fa20038a' },
cipher: 'aes-128-ctr',
kdf: 'scrypt',
kdfparams: {
dklen: 32,
salt: '4531b3c174cc3ff32a6a7a85d6761b410db674807b2d216d022318ceee50be10',
n: 262144,
r: 8,
p: 1
},
mac: 'b8b010fff37f9ae5559a352a185e86f9b9c1d7f7a9f1bd4e82a5dd35468fc7f6'
}
}, 'test!'); // <-- your password for the account goes in place of 'test!'
> {
address: "0x2c7536E3605D9C16a7a3D7b1898e529396a65c23",
privateKey: "0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}
我正在发送已签名的交易并收到错误:
Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 750000000000000 and got: 0.
问题是我的账户有足够的资金,你可以在这里查看0x002D189c25958c60736aE21C966ff3131C2AC849
如果我设置 gasLimit:web3.utils.toHex(20000)
,那么我会得到另一个错误:
Transaction gas is too low. There is not enough gas to cover minimal cost of the transaction (minimal: 21464, got: 20000). Try increasing supplied gas.
这是我的 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 会抛出这些错误吗?
I have created the account via Parity and also exported the account as json file, which contains
ciphertext
, which is the private key
cipthertext
是私钥的 加密 版本。这个Q&A includes some deeper background,如果你好奇的话。
要获取您的私钥,您需要密钥文件和用于加密它的密码。然后您可以使用 web3.js v1(测试版)中的 web3.eth.accounts.decrypt()
来提取密钥,如下所示:
web3.eth.accounts.decrypt({
version: 3,
id: '04e9bcbb-96fa-497b-94d1-14df4cd20af6',
address: '2c7536e3605d9c16a7a3d7b1898e529396a65c23',
crypto: {
ciphertext: 'a1c25da3ecde4e6a24f3697251dd15d6208520efc84ad97397e906e6df24d251',
cipherparams: { iv: '2885df2b63f7ef247d753c82fa20038a' },
cipher: 'aes-128-ctr',
kdf: 'scrypt',
kdfparams: {
dklen: 32,
salt: '4531b3c174cc3ff32a6a7a85d6761b410db674807b2d216d022318ceee50be10',
n: 262144,
r: 8,
p: 1
},
mac: 'b8b010fff37f9ae5559a352a185e86f9b9c1d7f7a9f1bd4e82a5dd35468fc7f6'
}
}, 'test!'); // <-- your password for the account goes in place of 'test!'
> {
address: "0x2c7536E3605D9C16a7a3D7b1898e529396a65c23",
privateKey: "0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}