I have a private key and address . Is it possible to make transaction with these parameter using web3j.


If you want to send custom tokens as the contract owner, check out my answer here: Send Custom ERC20 Tokens from one Address to another

If you want to send tokens on behalf of another user, the idea is similiar.

First retrieve user's credentials from the privatekey , then do transaction.

Credentials getUserInfo (String privateKeyInHex){

    BigInteger privateKeyInBT = new BigInteger(privateKeyInHex, 16);

    ECKeyPair aPair = ECKeyPair.create(privateKeyInBT);
    Credentials aCredential = Credentials.create(aPair);

    return aCredential;

send tokens:


    Credentials newUser =  getUserInfo(privateKeyInHex);

    TransactionReceiptProcessor transactionReceiptProcessor = new NoOpProcessor(web3);
    TransactionManager transactionManager = new RawTransactionManager(
                            web3, newUser, ChainId.MAINNET, transactionReceiptProcessor);
                    //if testing, use ChainId.ROPSTEN
| improve this answer | |
Web3j web3j = Web3j.build(new HttpService(""));
    Credentials credentials = Credentials.create("privateKey");
    BigInteger nonce = web3j.ethGetTransactionCount(credentials.getAddress(), DefaultBlockParameterName.PENDING).sendAsync().get().getTransactionCount();
    BigInteger gasPrice = web3j.ethGasPrice().sendAsync().get().getGasPrice();
    RawTransaction rawTransaction = RawTransaction.createEtherTransaction(nonce, gasPrice, Constants.ETH_GAS_LIMIT, "address", Convert.toWei("amount", Convert.Unit.ETHER).toBigIntegerExact());
    EthSendTransaction response = web3j.ethSendRawTransaction(Numeric.toHexString(TransactionEncoder.signMessage(rawTransaction, credentials))).send();
    String hash = response.getTransactionHash();
| improve this answer | |
  • just use this method and put your parameters on the place of the strings. – Sanjay Rao Oct 22 at 23:45

Yes it's possible to send transaction. Use web3.eth.sendTransaction({to:'0xaddress', from:'0xaddress', value:web3.toWei(.033,'ether'),gas:30000})

| improve this answer | |
  • Question is about web3j not web3js – Ajit Soman Feb 28 '18 at 8:21
  • are you using Ethereum wallet? – NoMan Ilyas Feb 28 '18 at 8:26
  • I have no wallet file. I have only ethereum private key and address – Ajit Soman Feb 28 '18 at 8:29

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.