3 HECO交易失败

web3j转账交易,以太坊可以成功,但是换了节点之后heco失败

private final static ImmutableList BIP44_ETH_ACCOUNT_ZERO_PATH =
            ImmutableList.of(new ChildNumber(44, true), new ChildNumber(60, true),
                    ChildNumber.ZERO_HARDENED, ChildNumber.ZERO);

    private final static Web3j web3j = Web3j.build(new HttpService("https://http-mainnet.hecochain.com"));`

public static String sendEthRawTransaction(String from, String to, BigDecimal amount, Credentials credentials) throws IOException, ExecutionException, InterruptedException {

BigInteger nonce = web3j.ethGetTransactionCount(from, DefaultBlockParameterName.PENDING).send().getTransactionCount(); BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice(); BigInteger gasLimit = BigInteger.valueOf(210000L);

BigInteger amountWei = Convert.toWei(amount, Convert.Unit.ETHER).toBigInteger();

RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, amountWei, "");

byte[] signMessage = TransactionEncoder.signMessage(rawTransaction,(byte)128, credentials);

System.out.println(Arrays.asList(signMessage)); return web3j.ethSendRawTransaction(Numeric.toHexString(signMessage)).sendAsync().get().getTransactionHash();

}

{"jsonrpc":"2.0","id":2,"error":{"code":-32000,"message":"invalid sender"}}

请先 登录 后评论

最佳答案 2022-08-22 18:09

rawTransaction里面要加上 HECO 网络的 chainId

请先 登录 后评论

其它 1 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 2 关注
  • 1 收藏,3083 浏览
  • PuTao 提出于 2021-11-25 23:26