I successfully run the Openzeppelin workshop about meta-transactions: https://github.com/OpenZeppelin/workshops/tree/master/25-defender-metatx-api
I'm now trying to translate it to Java using the Web3j library. I'm encountering issues with the function's signature. This is what I've do so far:
public TransactionReceipt emitRegistry(Web3j web3j, String signerPrivateKey, String senderPrivateKey, String registryContractAddress, String forwardContractAddress, String addressToSendGreetingsTo) throws Exception {
final Credentials signerCredentials = Credentials.create(signerPrivateKey);
final Credentials senderCredentials = Credentials.create(senderPrivateKey);
BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice();
BigInteger gasLimit = DefaultGasProvider.GAS_LIMIT;
final Function createRegistryfunction = new Function(
FUNC_CREATEREGISTRY,
List.of(new Address(160, addressToSendGreetingsTo)),
Collections.emptyList());
byte[] encodedFunction = FunctionEncoder.encode(createRegistryfunction).getBytes(StandardCharsets.UTF_8);
// Send the signed transaction to the network
Sign.SignatureData signature = Sign.signMessage(encodedFunction, signerCredentials.getEcKeyPair());
byte[] signatureInBytes = new byte[65];
System.arraycopy(signature.getR(), 0, signatureInBytes, 0, 32);
System.arraycopy(signature.getS(), 0, signatureInBytes, 32, 32);
System.arraycopy(signature.getV(), 0, signatureInBytes, 64, 1);
MinimalForwarder minimalForwarder = MinimalForwarder.load(forwardContractAddress, web3j, senderCredentials, new DefaultGasProvider());
BigInteger nonce = minimalForwarder.getNonce(signerCredentials.getAddress()).send();
// create forward request
MinimalForwarder.ForwardRequest forwardRequest = new MinimalForwarder.ForwardRequest(
signerCredentials.getAddress(),
registryContractAddress,
BigInteger.ZERO,
gasLimit,
nonce,
encodedFunction
);
return minimalForwarder.execute(forwardRequest, signatureInBytes, gasLimit.add(gasPrice)).send();
}
But I always receive the message Revert reason: MinimalForwarder: signature does not match request.
Did anyone tried the same?
Thanks