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
• 27,620 points
146 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,050 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,330 points
25 views
0 votes
1 answer

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

Here's a simple example for web3js 1.0.0.beta*: function handler ...READ MORE

answered Jun 8, 2018 in Blockchain by ariaholic
• 7,320 points
283 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,010 points
41 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 26, 2018 in Blockchain by Johnathon
• 9,070 points
66 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
103 views
0 votes
1 answer
+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,620 points
117 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,050 points
51 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,050 points
54 views