I am using web3j java library to deploy a smart contract.
// I am encoding the constructor parameters here -- 2 & 3, 10 & 20
String encodedConstructor =
FunctionEncoder.encodeConstructor(Arrays.asList(new Type(value), ...));
RawTransaction rawTransaction = RawTransaction.createContractTransaction(
<nonce>,
<gasPrice>,
<gasLimit>,
<value>,
"0x <compiled smart contract code>" + encodedConstructor);
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, <credentials>);
String hexValue = Numeric.toHexString(signedMessage);
I am using
web3.eth.sendRawTransaction(hexValue)
to deploy the contract.
My smart contract has a constructor which accepts some parameters(a, b) and it has a function sum which returns sum of a and b. After deployment if I call the sum function, it always returns me 0.
Need help.
Reference Link: https://docs.web3j.io/transactions.html#creation-of-a-smart-contract