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
contrato
with the function encoded, that doesn't look right. Try passing only the encoded function call.