Environment
Details
Basically my use case is
I have a Ethereum wallet, I have some usdt erc 20 funds there, I have zero eth in my wallet
I am using defender relayer, I have funded my relayer
I want to send usdt from my wallet to another address without paying the gas fee from the wallet. Instead I want my funded relayer to pay for my gas fee.
Below is my code
const { DefenderRelayProvider, DefenderRelaySigner } = require('@openzeppelin/defender-relay-client/lib/ethers');
const { ethers } = require('ethers');
// Load API credentials for the relayer
const credentials = {
apiKey: 'XXXX', // Replace with your API key
apiSecret: 'XXXX', // Replace with your API secret
};
// Initialize the Defender provider and signer
const provider = new DefenderRelayProvider(credentials);
const relayerSigner = new DefenderRelaySigner(credentials, provider, { speed: 'fast' });
// USDT contract details
const usdtContractAddress = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
// Initialize the USDT contract
const usdtContract = new ethers.Contract(usdtContractAddress, [
{
"constant": true,
"inputs": [{"name": "who", "type": "address"}],
"name": "balanceOf",
"outputs": [{"name": "", "type": "uint256"}],
"type": "function"
},
{
"constant": false,
"inputs": [
{"name": "_to", "type": "address"},
{"name": "_value", "type": "uint256"}
],
"name": "transfer",
"outputs": [{"name": "", "type": "bool"}],
"type": "function"
}
], provider);
// Replace with your compromised wallet's private key
const compromisedWalletPrivateKey = 'XXXX';
const compromisedWallet = new ethers.Wallet(compromisedWalletPrivateKey, provider);
async function prepareMetaTransaction() {
try {
const recipient = 'XXXX'; // Replace with actual recipient address
const amount = ethers.parseUnits('100', 6); // Amount in USDT
// Create the transaction data
const txData = usdtContract.interface.encodeFunctionData('transfer', [recipient, amount]);
// Sign the transaction
// const nonce = await compromisedWallet.getTransactionCount();
const tx = {
nonce: 22709,
gasLimit: 30000, // Adjust as needed
gasPrice: ethers.parseUnits('10', 'gwei'),
maxFeePerGas: ethers.parseUnits('10', 'gwei'),
maxPriorityFeePerGas : ethers.parseUnits('2', 'gwei'),
to: usdtContractAddress,
value: 0,
data: txData,
chainId : 1
};
const signedTx = await compromisedWallet.signTransaction(tx);
// Send the signed transaction to the relayer (this part is hypothetical)
console.log('Signed Transaction:', signedTx);
if (!signedTx) {
throw new Error("Failed to sign transaction");
}
// Send the signed transaction to Defender Relay
const tx1 = await provider.sendTransaction(signedTx);
console.log(tx1);
} catch (error) {
console.error("Error preparing meta transaction:", error);
}
}
prepareMetaTransaction();
I am currently getting below error
Error preparing meta transaction: Error: insufficient funds for intrinsic transaction cost [ See: https://links.ethers.org/v5-errors-INSUFFICIENT_FUNDS ] (error={"code":-32010}, method="sendTransaction", transaction="0x02f8b2018258b584773594008502540be40082753094dac17f958d2ee523a2206206994597c13d831ec780b844a9059cbb0000000000000000000000005ee827cd3f59e10144194b000ffc8efaaf4bdcf60000000000000000000000000000000000000000000000000000000005f5e100c080a09d006104634d81ee03293ef4e4883ab0492a342e49f29e2b9c0f923b0f644029a03ad79a67a8a1e44528b9519e65da2b524fa419ff61dce23788a498f3a6e334e3", code=INSUFFICIENT_FUNDS, version=providers/5.7.2)
at Logger.makeError (C:\Users\USER\Desktop\Blockchain\node_modules@ethersproject\logger\lib\index.js:238:21)
at Logger.throwError (C:\Users\USER\Desktop\Blockchain\node_modules@ethersproject\logger\lib\index.js:247:20)
at checkError (C:\Users\USER\Desktop\Blockchain\node_modules@ethersproject\providers\lib\json-rpc-provider.js:144:16)
at DefenderRelayProvider. (C:\Users\USER\Desktop\Blockchain\node_modules@ethersproject\providers\lib\json-rpc-provider.js:751:47)
at step (C:\Users\USER\Desktop\Blockchain\node_modules@ethersproject\providers\lib\json-rpc-provider.js:48:23)
at Object.throw (C:\Users\USER\Desktop\Blockchain\node_modules@ethersproject\providers\lib\json-rpc-provider.js:29:53)
at rejected (C:\Users\USER\Desktop\Blockchain\node_modules@ethersproject\providers\lib\json-rpc-provider.js:21:65)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
reason: 'insufficient funds for intrinsic transaction cost',
code: 'INSUFFICIENT_FUNDS',
error: Error: InsufficientFunds, Balance is zero, cannot pay gas
at DefenderRelayProvider.send (C:\Users\USER\Desktop\Blockchain\node_modules@openzeppelin\defender-relay-client\lib\ethers\provider.js:58:31)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: -32010,
data: undefined
},
method: 'sendTransaction',
transaction: {
type: 2,
chainId: 1,
nonce: 22709,
maxPriorityFeePerGas: BigNumber { _hex: '0x77359400', _isBigNumber: true },
maxFeePerGas: BigNumber { _hex: '0x02540be400', _isBigNumber: true },
gasPrice: null,
gasLimit: BigNumber { _hex: '0x7530', _isBigNumber: true },
to: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
data: '',
accessList: ,
hash: '0xb2d90728f28beec1ebab5dd185be74febed79fe5f90113939d9b8da3fed79c96',
v: 0,
r: '0x9d006104634d81ee03293ef4e4883ab0492a342e49f29e2b9c0f923b0f644029',
s: '0x3ad79a67a8a1e44528b9519e65da2b524fa419ff61dce23788a498f3a6e334e3',
from: '0x4DE23f3f0Fb3318287378AdbdE030cf61714b2f3',
confirmations: 0
},
transactionHash: '0xb2d90728f28beec1ebab5dd185be74febed79fe5f90113939d9b8da3fed79c96'
}
I am not sure why it is saying insufficient funds as my relayer is funded
Code to reproduce