I have an issue #3495
Unanswered
nguyenPhuocLoc99
asked this question in
Question
I have an issue
#3495
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have an issue below when trying to run my code below:
`import { createWalletClient, createPublicClient, http, parseUnits } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { bscTestnet } from "viem/chains";
import { PANCAKE_SWAP_ABI } from '../config/contracts'
// Configurations
const chain = bscTestnet;
const rpcUrl = "https://data-seed-prebsc-1-s3.bnbchain.org:8545";
const privateKey = process.env.ASSISTANT_PRIVATE_KEY as
0x${string}
;const account = privateKeyToAccount(privateKey);
const publicClient = createPublicClient({ chain, transport: http(rpcUrl) });
const walletClient = createWalletClient({ account, chain, transport: http(rpcUrl) });
// PancakeSwap Router V2 address
const routerAddress = "0xCc7aDc94F3D80127849D2b41b6439b7CF1eB4Ae0";
// PancakeSwap Router V2 ABI
const routerAbi = PANCAKE_SWAP_ABI;
async function swapTokens(
tokenIn:
0x${string}
,tokenOut:
0x${string}
,amountIn: string,
slippage: number
) {
const amountInWei = parseUnits(amountIn, 18);
const path = [tokenIn, tokenOut];
const to = account.address;
const deadline = Math.floor(Date.now() / 1000) + 60 * 10; // 10 phút
// Get amount out
const amountsOut = await publicClient.readContract({
address: routerAddress,
abi: routerAbi,
functionName: "getAmountsOut",
args: [amountInWei, path],
});
console.log({amountsOut})
// const amountOutMin = amountsOut[1] - (amountsOut[1] * BigInt(slippage * 100) / 10000n);
// // Send transaction
// const hash = await walletClient.writeContract({
// address: routerAddress,
// abi: routerAbi,
// functionName: "swapExactTokensForTokens",
// args: [amountInWei, amountOutMin, path, to, deadline],
// account,
// });
// console.log(
Swap transaction hash: ${hash}
);}
swapTokens(
"0xF8A0BF9cF54Bb92F17374d9e9A321E6a111a51bD", // LINK
"0x55d398326f99059fF775485246999027B3197955", // USDT
"1", // Swap 1 LINK
0.5 // Slippage 0.5%
);`
I'm currently comment the code that send transaction to see if the code above is running properly or not (obviously not for now) and got the bug below:
`node_modules/viem/_types/types/multicall.d.ts:12:18 - error TS2589: Type instantiation is excessively deep and possibly infinite.
12 MaybePartial<Prettify<GetMulticallContractParameters<contract, options['mutability']> & options['properties']>, options['optional']>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/viem/_types/utils/abi/parseEventLogs.d.ts:22:308 - error TS2344: Type 'eventName extends ContractEventName[] ? eventName[number] : eventName' does not satisfy the constraint 'ContractEventName'.
Type 'eventName | eventName[number]' is not assignable to type 'ContractEventName'.
Type 'eventName' is not assignable to type 'ContractEventName'.
Type 'ContractEventName | ContractEventName[]' is not assignable to type 'ContractEventName'.
Type 'ContractEventName[]' is not assignable to type 'ContractEventName'.
22 export type ParseEventLogsReturnType<abi extends Abi | readonly unknown[] = Abi, eventName extends ContractEventName | ContractEventName[] | undefined = ContractEventName, strict extends boolean | undefined = boolean | undefined, derivedEventName extends ContractEventName | undefined = eventName extends ContractEventName[] ? eventName[number] : eventName> = Log<bigint, number, false, undefined, strict, abi, derivedEventName>[];
Found 2 errors in 2 files.
Errors Files
1 node_modules/viem/_types/types/multicall.d.ts:12
1 node_modules/viem/_types/utils/abi/parseEventLogs.d.ts:22`
I'm kinda new so this is beyond me right now. Anyone know how to fix this?
Beta Was this translation helpful? Give feedback.
All reactions