0

I am new to web3j and smart contract deployment.

Consider a scenario where a user is too scared to give his wallet credential file or username/password or private key in a piece of code(the code is not visible to him and he fears his credentials may be used in a way he does not intend). The user also has an offline computer(not connected to the internet) and an online computer(connected to the internet).

I have read about rawTransaction and TransactionEncoder.signMessage and if the user would have wanted to just transfer ethers, he could do both of these steps in an offline computer and then provide this signedMessage on an online computer to proceed with the transfer of funds.

Is there something similar he can do while deploying the smart contract? Have I understood it all correctly or am I thinking of doing something which does not make sense?

1
  • Deploying a contract is also a transaction, it is just a transaction that has the binary code of the contract in the data... So the same steps.. I will try to write a code for that next week :)
    – Majd TL
    May 24 '20 at 11:20
0

With web3j and similar by webjs

You need the binary code of your contract... you can generate the java wrapper class of your contract with web3j command-line and it always includes the needed Binary as public variable . usually, the command looks like this

web3j truffle generate --javaTypes ./build/contracts/YOURCONTRACT.json -o ./your-dist-pfad

You need the credentials, which you can generate by your private key using web3j

public Credentials getWallet(String ethPrivateKey) {
    BigInteger privateKeyInBT = new BigInteger(ethPrivateKey, 16);
    ECKeyPair aPair = ECKeyPair.create(privateKeyInBT);
    return Credentials.create(aPair);
}

You need also to know the nonce of your account

RawTransaction rawTransaction = RawTransaction.createContractTransaction(<your-nonce>, <your-fee>, <your-GASLIMIT>, BigInteger.ZERO, <YourContract>.BINARY);
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, <your-credentials);
String hexValue = Numeric.toHexString(signedMessage);

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.