I am trying to execute a gasless transaction using openzeppelin relayers and ether.js but have not able to succeed in it. Currently i am getting this issue with the transaction object.Error pic.
I am not using any smart contract here. I just want to send amount from one address to another. The private key of the sender's address will signed the transaction and then the transaction will be sent to relayer to manage and execute the transaction. The gas price of this transaction should be paid by the relayer.
Also any advice regarding code improvements or transaction structure would be appreciated.
The code is provided below
const { DefenderRelayProvider,DefenderRelaySigner } = require('@openzeppelin/defender-relay- client/lib/ethers');
const { ethers } = require('ethers');
async function sendGaslessTransaction() {
// Instantiate the DefenderRelayProvider
const credentials = {
apiKey: 'Relayer Api Key',
apiSecret: 'Relayer Api secret'
};
const provider = new DefenderRelayProvider(credentials);
const senderPrivateKey = 'private key';
// Gasless transaction parameters
const transaction = {
to: 'Recipient address',
value: ethers.utils.parseEther("0.0005"),
gasLimit: 21000
};
const wallet = new ethers.Wallet(senderPrivateKey);
const signedTransaction = await wallet.signTransaction(transaction);
console.log("signed transaction",signedTransaction)
const relayerSignedTransaction = {
...transaction,
...signedTransaction
};
// Instantiate the DefenderRelaySigner
const signer = new DefenderRelaySigner(credentials, provider, { speed: 'fast' });
// Populate the transaction with additional details
const populatedTransaction = await signer.populateTransaction(relayerSignedTransaction);
// Send the gasless transaction to the relayer for execution and gas fee payment
try {
const response = await signer.sendTransaction(populatedTransaction);
console.log('Transaction hash:', response.transactionHash);
} catch (error) {
console.error('Error sending gasless transaction:', error);
}
}
sendGaslessTransaction();
I have trying different function provided by ethers library to convert ether into wei according to the requirement but have not been successfull and getting similar errors indication there is an issue with transaction object's "value".