Contract call with custom sendTransaction parameters #1717
-
I am using ethers.js with a custom wrapper to build an app for Celo blockchain. When sending regular transactions, a custom parameter (feeCurrency) is added to the wallet to specify the stable coin contract address from where the gas fee must be paid. This works fine with standard transactions. However, when sending a contract transaction, I am having difficulty understanding how to set the feeCurrency parameter in a contract call. The contract call looks like this:
What we need is something like this:
For example, Celo has an SDK that is a wrapper over web3.js and it can be used as below:
Notice how the feeCurrency can be set while sending the transaction. Is something like this possible with ethers? Basically, the call to the JSON RPC method sendTransaction must contain the feeCurrency parameter when calling a contract method. So instead of doing just stableTokenContract.transfer(), is there a way to do signer.sendTransaction() with a contract method so that we can use a wrapper over the signer and specify the feeCurrency parameter? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can just populate the data field. And the const populatedTx = await await stabletoken.populateTransaction.transfer(anAddress, amount);
await signer.sendTransaction({
to: stableTokenContractAddress,
data: populatedTx.data
}) Also note that, you don't need to use the signer API, you can also change the contract address in a const txnResponse = await stabletoken
.attach(newStableTokenContractAddress) // specify other contract address (of a different ERC20 token)
.connect(signer) // specify other signer object
.transfer(anAddress, amount) // call the function |
Beta Was this translation helpful? Give feedback.
You can just populate the data field. And the
stableTokenContractAddress
is pretty much theto
address in terms of ERC20 transfer transaction.Also note that, you don't need to use the signer API, you can also change the contract address in a
Contract
object as well as thesigner
for the from addr…