1

I am trying to send a transaction to an address: 0xDD210......... using the EthSendTransaction.sendTransaction() method from the org.web3j.protocol.core.methods.response.EthSendTransaction library.

The transaction contains data but doesn't have any value (I don't have to send funds). I am using the private network(localhost: 8545)

The syntax is:

EthSendTransaction transactionResponse = transactionManager.sendTransaction(220000000,
            43000, "0xDD210......", hashedData.toString(), BigInteger.valueOf(0));

String transactionHash = transactionResponse.getTransactionHash();   

The value of transactionHash is null.

if (transactionResponse.hasError()) {
        logger.info("in error block");
        throw new RuntimeException(
                "Error processing transaction request: " + 
transactionResponse.getError().getMessage());

On runtime, the code gives

"Error processing transaction request: Invalid params: invalid hex."

Does anyone know the solution to this?

1

Did you try something like this:

Transaction transaction = Transaction.createFunctionCallTransaction("FROM_ADDRESS",  nonce, gasprice, gaslimit, "TO_ADDRESS", encodedData);

EthSendTransaction transactionResponse = web3j.ethSendTransaction(transaction).sendAsync().get();
transactionHash = transactionResponse.getTransactionHash();
0

(can you share more of your code, like the method in your smartcontract, how you init the transactionManager and how you get the hashedData?)

I usually do this

Credentials credentials = WalletUtils.loadCredentials("Your PASSWORD", "Your Wallet-File-Location");

// Get Nonce
EthGetTransactionCount ethGetTransactionCount = web3j
                .ethGetTransactionCount(credentials.getAddress(), DefaultBlockParameterName.LATEST).send();
BigInteger nonce = ethGetTransactionCount.getTransactionCount();

RawTransaction rawTransaction = RawTransaction
            .createTransaction(nonce, "Your GASPRICE", "Your GASLIMIT", "Your Contract-Address", "Your encodedFunction");

// Sign the Transaction
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
String hexValue = Numeric.toHexString(signedMessage);

EthSendTransaction transactionResponse = web3j .ethSendRawTransaction(hexValue ).sendAsync().get();

Of course with RawTransaction you should sign the transaction and set nonce (I think that a transactionmanager does it for you)

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.