You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
simulate and WalletClient calls should accept the same fields.
Viem recommends that most contract calls or transactions are first simulated
Warning: The write internally sends a transaction – it does not validate if the contract write will succeed (the contract may throw an error). It is highly recommended to simulate the contract write with `contract.simulate` before you execute it.
Steps To Reproduce
import{createPublicClient,createWalletClient,http,parseEther,parseGwei,Address,getContract,erc20Abi,parseUnits,formatUnits,}from"viem";import{privateKeyToAccount}from"viem/accounts";import{celoAlfajores}from"viem/chains";import{PRIVATE_KEY,RECIPIENT,cUSD_CONTRACT_ADDRESS,USDC_CONTRACT_ADDRESS,USDC_ADAPTER_ADDRESS,}from"./constants";/** * Boilerplate to create a viem client and viem-compatible wallet */constread=createPublicClient({chain: celoAlfajores,transport: http(),});constwrite=createWalletClient({chain: celoAlfajores,// Celo testnettransport: http(),});constsender=privateKeyToAccount(`0x${PRIVATE_KEY}`);/** * Set up ERC20 contract */constcontract=getContract({address: cUSD_CONTRACT_ADDRESS,abi: erc20Abi,client: {public: read,wallet: write},});const[symbol,decimals,tokenBalance]=awaitPromise.all([contract.read.symbol(),contract.read.decimals(),contract.read.balanceOf(["0xcEe284F754E854890e311e3280b767F80797180d"]),]);/** * Makes a transaction to transfer ERC20 tokens using a fee currency */asyncfunctionerc20Transfer(){console.log(`Initiating fee currency transaction...`);console.log(`${symbol} balance of ${sender}: ${formatUnits(tokenBalance,decimals)}`);consttransactionSimulation=awaitcontract.simulate.transfer([RECIPIENT,parseUnits("0.01",decimals)],{account: sender,feeCurrency: "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1"});consttransactionReceipt=awaitcontract.write.transfer([RECIPIENT,parseUnits("0.01",decimals)],{account: sender,feeCurrency: "0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1"});console.log(transactionReceipt);}erc20Transfer().catch((err)=>{console.error("An error occurred:",err);});
Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)
The text was updated successfully, but these errors were encountered:
arthurgousset
changed the title
bug: contract.publicWallet.simulate() does not accept feeCurrency field
bug: contract.simulate does not accept feeCurrency field
Feb 29, 2024
Is there an existing issue for this?
Package Version
2.7.9
Current Behavior
This code snippet shows an error (red squiggly line) under
feeCurrency
:The error message is:
But the same code as
contract.write.transfer
accepts thefeeCurrency
Expected Behavior
simulate
andWalletClient
calls should accept the same fields.Viem recommends that most contract calls or transactions are first simulated
Steps To Reproduce
Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)
https://github.com/celo-org/feecurrency/blob/main/viem.ts
Anything else?
No response
Related
- celo-org/feecurrency demo repo
The text was updated successfully, but these errors were encountered: