0

I don't know how to send a signed transaction against a method payable in Ganache, can someone help me??? When I call the method in Remix it works fine but from Java I get the Hash of the transaction but it always with response "VM Exception while processing transaction: revert". The wrapper is:

public RemoteFunctionCall<TransactionReceipt> participar(BigInteger weiValue) {
        final Function function = new Function(
                FUNC_PARTICIPAR, 
                Arrays.<Type>asList(), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function, weiValue);
    }

The java code is:

public Main(){
        try {
            web3j = Web3j.build(new HttpService("http://127.0.0.1:7545")); //local ganache 
            credentials = Credentials.create("896d708b0e071ee853......");
        }catch(Exception e){
            e.printStackTrace();
        }
    }


public static void main(String args[]) throws IOException, Exception{
  Main test = new Main();
  Loteria contract = test.loadContract(); //Load the deployed MyContract contract
  ...
  Loteria contract = test.loadContract();
  System.out.println("Precio: " + contract.precio().send()); // work ok
  ...
  Function function = new Function("participar", 
                        Arrays.<Type>asList(), 
                        Collections.<TypeReference<?>>emptyList());
  String encodedFunction = FunctionEncoder.encode(function);
  String contrato = "0x6080604052604051610604380380610604833981810160405260408110156100265......";
  BigInteger nonce = test.getTransactionCount(test.ADDRESS_CUENTA);
  BigInteger valueParticipar = BigInteger.valueOf(100);
  RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, GAS_PRICE, GAS_LIMIT, test.CONTRACT_ADDRESS, valueParticipar, new String(Hex.encode(contrato.getBytes())) +   encodedFunction);             
  byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, test.credentials);
  String hexValue = Numeric.toHexString(signedMessage);
  EthSendTransaction ethSendTransaction = test.web3j.ethSendRawTransaction(hexValue).sendAsync().get();
  String transactionHash = ethSendTransaction.getTransactionHash();
...

The getters for global scope variables work fine.

Thank you so much.

Environment: Web3j version. core 4.6.3 Java 8 Operating System Windows Ganache

2
  • you need to get the string of the REVERT failure, it is reported on the return value of the call
    – Nulik
    Jul 14, 2021 at 15:44
  • I'm not a java developer but it seems you are concatenating the contract bytecode contrato with the function encoded, that doesn't look right. Try passing only the encoded function call.
    – Ismael
    Jul 14, 2021 at 16:33

1 Answer 1

0

I got to fix it. I had several erros. I have used the example to solved it https://github.com/web3j/web3j/blob/master/integration-tests/src/test/java/org/web3j/protocol/scenarios/HumanStandardTokenIT.java.

Thanks you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.