简体   繁体   English

Web3j Transfer.sendFunds()返回错误“天然气资金不足*价格+价值”

[英]Web3j Transfer.sendFunds() returns Error “insufficient funds for gas * price + value”

When using the web3j lib for blockchain transaction in my private test blockchain I'm currently running into the titled response error: *insufficient funds for gas * price + value* 当我在私人测试区块链中使用web3j lib进行区块链交易时,我正在遇到标题响应错误: *天然气资金不足*价格+价值*

The account from which I want to transfer some ether has a balance of 10000 ether. 我要转移一些以太的账户余额为10000以太。 The gas price I logged out has a value of 18000000000 as BigInt (it's WEI?) and the gas limit is the default used from the web3j has a value of 21000 . 我注销的汽油价格为Big0000(它是WEI?)的价值为18000000000 ,而web3j的默认燃气价值为21000

So the question is why I getting the transaction not working?I want to transfer 10 ether for example: 所以问题是为什么我让交易不起作用?我想转移10以太:例如:

TransactionReceipt transactionReceipt = Transfer.sendFunds(web3, credentials, toAccount, BigDecimal.valueOf(10.0), Convert.Unit.ETHER).send();

More details 更多细节

the genesis file looks like this: genesis文件如下所示:

{
  "config": {
      "chainId": 9999,
      "homesteadBlock": 0,
      "eip155Block": 0,
      "eip158Block": 0,
      "byzantiumBlock": 0
   },
   "difficulty": "400",
   "gasLimit": "2100000",
   "alloc": {
      "0x9b6301bf2cfe11066dbd641f91a2b82e0783130e": { 
          "balance": "100000000000000000000000" 
      }
   }
}

The code looks like this: 代码如下所示:

// create new account 
Admin admin = Admin.build(new HttpService());
NewAccountIdentifier newAccount = admin.personalNewAccount("PASSWORD").send();

// get current created account
Web3j web3 = Web3.build(new HttpService());
EthAccounts accounts = web3.ethAccounts().send();
String lastAccount = Iterables.getLast(accounts.getAccounts());
// get creadentials for the first account having some ether
String firstAccount = web3.ethAccounts().send().getAccounts().get(0);
Credentials credentials = Credentials.create(firstAccount);

// get current balance for first account
EthGetBalance balance = admin.ethGetBalance(firstAccount, DefaultBlockParameterName.LATEST).send();
BigDecimal balanceVaue = Convert.fromWei(balance.getBalance().toString(), Convert.Unit.ETHER);

// create transaction to give the new created account some ether from the first one
// log some stuff
System.out.println("Account: " + firstAccount);
System.out.println("Account balance: " + balanceVaue);
System.out.println("Gas Price admin.ethGasPrice() in Ether: " + Convert.fromWei(gasPrice.toString(), Convert.Unit.ETHER));
System.out.println("Transfer Gas Limit in Ether: " + Convert.fromWei(Transfer.GAS_LIMIT.toString(), Convert.Unit.ETHER));
System.out.println("Transfer Gas Price in Ether: " + Convert.fromWei(Transfer.GAS_PRICE.toString(), Convert.Unit.ETHER));

TransactionReceipt transactionReceipt = Transfer.sendFunds(web3, credentials, lastAccount, BigDecimal.valueOf(10.0), Convert.Unit.ETHER).send();
String transactionHash = transactionReceipt.getTransactionHash();

This causes the above transaction error: insufficient funds for gas * price + value 这导致上述交易错误: 天然气价格+价值不足

Here is the logging output: 这是日志输出:

Account: 0x9b6301bf2cfe11066dbd641f91a2b82e0783130e
Account balance: 100000
Gas Price admin.ethGasPrice() in Ether: 1.8E-8
Transfer Gas Limit in Ether: 2.1E-14
Transfer Gas Price in Ether: 2.2E-8
Funds transfer triggered ...

Your Credentials object is not correct. 您的Credentials对象不正确。 The method you're using is expecting the private key, not the Ethereum address. 您正在使用的方法是期望私钥,而不是以太坊地址。

Credentials credentials = Credentials.create(firstAccount);

should be 应该

Credentials credentials = Credentials.create("<PRIVATE_KEY_HERE>");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM