java中web错误返回码,Java-Web3j Transfer.sendFunds()返回错误“天然气...

在我的私人测试区块链中使用web3j lib进行区块链交易时,我当前遇到标题为错误的响应:*供气不足*价格值*

我要从中转移一些以太币的账户有10000醚的余额.我注销的汽油价格的值为BigInt(它是WEI?)为18000000000,汽油限额是从web3j使用的默认汽油价格,值为21000.

所以问题是为什么我无法进行交易呢?我想转让10以太币:

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

更多细节

生成文件如下所示:

{

"config": {

"chainId": 9999,

"homesteadBlock": 0,

"eip155Block": 0,

"eip158Block": 0,

"byzantiumBlock": 0

},

"difficulty": "400",

"gasLimit": "2100000",

"alloc": {

"0x9b6301bf2cfe11066dbd641f91a2b82e0783130e": {

"balance": "100000000000000000000000"

}

}

}

代码如下:

// 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();

这将导致上述交易错误:资金不足的天然气*价格值

这是日志记录输出:

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 ...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值