1

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
7
  • if you upload the project on github with the smart contract, I could probably help more (using ganache). but take care remove any private infomration – Majd TL Mar 3 at 15:33
  • @MajdTL Well here you go link. Feel free to test it. I think I have removed any sensitive information. – Greymist Mar 3 at 16:49
  • I tested it... and i got another problem... :( I will take another try at the weekend – Majd TL Mar 4 at 18:02
  • @MajdTL Any luck? I mean ganache does show that a block is mined from contract creation even though the error pops up. – Greymist Mar 7 at 10:23
  • yes I saw the contract on ganache, but could not solve the error,# maybe there is something wrong with that web3 maven version, or your java application. try to use java 11 – Majd TL Mar 7 at 12:09
0

Ok, I know what's going on.

Referring to this post Web3j gets stack underflow error with Ganache, turns out that Web3j CLI doesn't accept and process properly for any binary file generated from Remix-IDE (Don't know why but definitely a bug).

So I switched the IDE to Buidl to compile and it works perfectly now on both ganache and geth.

0

As another way of doing it. If you have the smart contract, you can actually use the web3j-gradle-plugin to compile the contract on the go and deploy it (without having to copy past manually the generated java wrapper).

To do so, just apply the plugin to your project using:

plugins {
  id "org.web3j" version "4.8.4"
}

if you are using gradle. If not, you can also specify it for a maven project.

Then, put the smart contract under the src/main/solidity folder and it will be picked up automatically, compiled and the java wrappers will be generated and also available to use directly from your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.