报错提问 only replay-protected (EIP-155) transactions allowed over RPC java 调用执行智能合约进行交易出错

合约部署在私有链上,编写java程序使用web3j去调用合约 执行查询的合约方法是正常的。执行交易相关的方法报错如下。

完整报错为:java.util.concurrent.ExecutionException: java.lang.RuntimeException: Error processing transaction request: only replay-protected (EIP-155) transactions allowed over RPC at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357) at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895) at com.example.etherc.utils.Ethc.Ethc1(Ethc.java:42) at com.example.etherc.controller.UserController.test(UserController.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)

请先 登录 后评论

最佳答案 2021-10-25 14:49

两个方案可以解决 1、如果是自己的节点,同步命令加上 --rpc.allow-unprotected-txs

2、如果是第三方的节点,签名内容增加chainId

let chainID =await web3.eth.getChainId();
//
let rawTransaction = {
    from: fromAddr,
    to: to,
    value: value,
    gasLimit: toHex(gasLimit),
    gasPrice: toHex(gasPrice),
    data: data,
    chainId: toHex(chainID),//签名内容增加chainId
    nonce: nonce
};
请先 登录 后评论

其它 1 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 1 关注
  • 0 收藏,7241 浏览
  • a821808553 提出于 2021-10-22 18:12