Error when trying to deploy Ethereum smart contract using web3j

0 votes

I'm trying to deploy a smart contract in java using web3j and Ganache. After the creation of the java wrapper for my contract, the code that I'm using to deploy the contract is:

public void deployGreeter(String pw, String walletFile, String _greeting) throws IOException, CipherException, Exception{
    Credentials credentials = WalletUtils.loadCredentials(pw, walletFile);
    Greeter g = Greeter.deploy(web3, credentials, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT, _greeting).send();

}

But I'm getting the following error:

Exception in thread "main" java.lang.RuntimeException: 
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: 
buffer(okhttp3.internal.http1.Http1Codec$ChunkedSource@10aa41f2).inputStream(); line: 1, column: 188] (through reference chain: org.web3j.protocol.core.methods.response.EthSendTransaction["error"]->org.web3j.protocol.core.Response$Error["data"])
at org.web3j.tx.Contract.deploy(Contract.java:302)
at org.web3j.tx.Contract.lambda$deployRemoteCall$5(Contract.java:334)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
at com.monsanto.ethereumtest1.Ganache.deployGreeter(Ganache.java:125)
at com.monsanto.ethereumtest1.Main.main(Main.java:61)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token

I've also tried to deploy another contract, but the error output is the same. Can someone tell me how to solve this?

Oct 3, 2018 in Blockchain by digger
• 26,740 points
1,410 views

1 answer to this question.

0 votes

Create a new credential based on the Credentials.create method and then deploy the contract.

Please see bellow the code that worked for me:

public String deployContract(String privateKey, String _lotNumber, int _weight) throws Exception{
    BigInteger biWeight = BigInteger.valueOf(_weight);
    Credentials credentials = Credentials.create(privateKey);
    cst = CST.deploy(web3, credentials, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT, _lotNumber, biWeight).send();
    String ca = cst.getContractAddress();

    System.out.println("Contract deployed! Address: " + ca);
    return ca;
}
answered Oct 3, 2018 by slayer
• 29,350 points

Related Questions In Blockchain

0 votes
1 answer

Why is it downloading the blocks when I am trying to deploy the ethereum private network?

Once you have installed the Ethereum wallet, ...READ MORE

answered May 3, 2018 in Blockchain by Shashank
• 10,400 points
447 views
0 votes
2 answers

How to get notified when an event triggers on ethereum smart contract?

Muchas gracias. ?Como puedo iniciar sesion? READ MORE

answered May 2, 2020 in Blockchain by aqowcmbevs
2,170 views
0 votes
1 answer

Error in sending value to an Ethereum Smart Contract.

It is stated in Solidity 4.0 documentation ...READ MORE

answered Jul 23, 2018 in Blockchain by Perry
• 17,100 points
1,157 views
+1 vote
1 answer

How to deploy ethereum smart contracts on a website?

There are many ways to do this: 1 ...READ MORE

answered Mar 27, 2018 in Blockchain by Johnathon
• 9,090 points
1,664 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,706 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,237 views
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
969 views
0 votes
1 answer

How to access member functions of smart contract using web3?

I have implemented a similar feature and ...READ MORE

answered Aug 13, 2018 in Blockchain by slayer
• 29,350 points
1,402 views
0 votes
1 answer

How to store photos in Hyperledger smart contract?

To do this, you need to represent ...READ MORE

answered Jul 9, 2018 in Blockchain by slayer
• 29,350 points
695 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP