I have a java server that uses web3j library with geth as the provider. When I tried to deploy my contract on my private test net. I got this error:
org.web3j.protocol.exceptions.TransactionException: Transaction 0x70fed47c9d291f0818ff239be085b2dc3a87f436f56b9c0b6750e568a24dbdf1 has failed with status: 0x0. Gas used: 6721975. Revert reason: 'invalid argument 0: json: cannot unmarshal invalid hex string into Go struct field CallArgs.data of type hexutil.Bytes'.
at org.web3j.tx.Contract.executeTransaction(Contract.java:377)
at org.web3j.tx.Contract.create(Contract.java:422)
at org.web3j.tx.Contract.deploy(Contract.java:456)
at org.web3j.tx.Contract.deploy(Contract.java:506)
at org.web3j.tx.Contract.lambda$deployRemoteCall$5(Contract.java:549)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
at java_ethereum.ContractController.deployContract(ContractController.java:41)
My java code looks something like this:
Web3j web3 = Web3j.build(new HttpService("http://localhost:8545"));
Credentials credentials = WalletUtils.loadCredentials("", "path/to/geth/keystore");
String contractAddress = deployContract(web3, credentials);
MyContract myContract = loadContract(contractAddress, web3, credentials);
@SuppressWarnings("deprecation")
private String deployContract(Web3j web3, Credentials credentials) throws Exception{
return myContract.deploy(web3, credentials, GAS_PRICE, GAS_LIMIT).send().getContractAddress();
}
My web3j should be the latest version(4.8.4), I am not sure if I have missed anything. The content of the contract should not matter (I think) because the same error pops up even when I try to deploy a blank contract. I suspect there is some problem with the credentials created from geth. Any help would be appreciated.
My command to initialize the geth node:
geth --identity "TestNode" --rpc -rpcaddr "0.0.0.0" --rpcport "8545" --port "30303" --nodiscover --rpcapi "db,eth,net,web3,miner,net,personal,net,txpool,debug,admin" --networkid 1900 --datadir C:/Users/Documents/Test --allow-insecure-unlock --ipcdisable --dev --dev.period 1
@Majd TL suggests testing it on ganache instead, and it returns different error this time:
java.lang.RuntimeException: java.lang.RuntimeException: Error processing transaction request: VM Exception while processing transaction: invalid opcode
at org.web3j.tx.Contract.deploy(Contract.java:460)
at org.web3j.tx.Contract.deploy(Contract.java:506)
at org.web3j.tx.Contract.lambda$deployRemoteCall$5(Contract.java:549)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
at ContractController.deployContract(ContractController.java:52)
Caused by: java.lang.RuntimeException: Error processing transaction request: VM Exception while processing transaction: invalid opcode
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:162)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:127)
at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
at org.web3j.tx.Contract.create(Contract.java:422)
at org.web3j.tx.Contract.deploy(Contract.java:456)
... 11 more