java调用approve 失败问题

java调用approve 授权

设置gas和limit 小了后然后一直等待直到超时然后报错 org.web3j.protocol.exceptions.TransactionException: Transaction receipt was not generated after 600 seconds for transaction: 试着把gas和limit 设置大后报这个:exceeds block gas limit 应该怎么设置呢?是设置gas错误?还是说approve是这个方法有问题呢?求大佬解决。

    //网上教程让设置默认得,好像也不好用
     BigInteger GAS = Contract.GAS_LIMIT;
     BigInteger GAS_PRICE = Contract.GAS_PRICE;

   //手动指定也不行
    BigInteger limit = new BigInteger("8000000");

    TokenERC20 contract = TokenERC20.load(contractAddress, web3j, credentials,
            GAS_PRICE,GAS);

    RemoteCall<TransactionReceipt> remoteCall=  contract.approve("被授权地址",new BigInteger("授权数量"));
    TransactionReceipt receipt = remoteCall.send();

    // 封装
    public RemoteCall<TransactionReceipt> approve(String _spender, BigInteger _value) {
    Function function = new Function(
            "approve",
            Arrays.<Type>asList(new Address(_spender),
                    new Uint256(_value)),
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
请先 登录 后评论

1 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 1 关注
  • 0 收藏,2518 浏览
  • 我不吃香菜 提出于 2022-12-28 20:46