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"}}