Skip to content

Commit

Permalink
add native coin value to simulate method call
Browse files Browse the repository at this point in the history
  • Loading branch information
tom2drum committed Nov 25, 2024
1 parent 72a5cf6 commit 08ee5c2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ui/address/contract/methods/useCallMethodPublicClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { FormSubmitResult, MethodCallStrategy, SmartContractMethod } from '
import config from 'configs/app';
import useAccount from 'lib/web3/useAccount';

import { getNativeCoinValue } from './utils';

interface Params {
item: SmartContractMethod;
args: Array<unknown>;
Expand All @@ -31,13 +33,15 @@ export default function useCallMethodPublicClient(): (params: Params) => Promise
// for write payable methods we add additional input for native coin value
// so in simulate mode we need to strip it off
const _args = args.slice(0, item.inputs.length);
const value = getNativeCoinValue(args[item.inputs.length]);

const params = {
abi: [ item ],
functionName: item.name,
args: _args,
address,
account,
value,
};

const result = strategy === 'read' ? await publicClient.readContract(params) : await publicClient.simulateContract(params);
Expand Down

0 comments on commit 08ee5c2

Please sign in to comment.