Skip to main content
These examples follow the same V5 pattern used by the LFG.RICH application:

Ethers.js

Includes shared setup, estimates, buy, sell, borrow, borrowMore, and repay examples.

Viem

Shows typed public/wallet client reads and writes for the V5 flow.

Web3.js

Provides examples for integrations still using Web3.js.

Python Web3.py

Covers backend scripts, bots, and analytics workers that need direct V5 contract calls.
1

Resolve the token's poolId

Use API data when available, then fall back to hook.tokenToPoolId(tokenAddress).
2

Resolve or build the PoolKey

Prefer factory.getPoolKey(tokenAddress) and only build manually when constants are known.
3

Quote through the Hook

V5 estimate functions include the user wallet address because referral routing can affect fee recipients.
4

Execute buys and sells through the Swap Router

Swap execution uses the token-specific PoolKey.
5

Execute borrow, borrow more, and repay through the Hook

Lending actions use poolId, and collateral approvals go to the Hook.
Do not use old V3 examples for V5 tokens. In V5, estimateBuy and estimateSell include the user address, createToken takes devBuyEth, and token trades must be routed with the correct PoolKey.

Shared V5 concepts

The app can use token.pool_id from the API, but integrations should also know the fallback:
For swaps, prefer factory.getPoolKey(tokenAddress) when available. If you already know the network constants, the same PoolKey can be built as:

Ethers.js v5

Shared setup

Estimate buy

Buy tokens

Estimate sell

Sell tokens

Borrow

Borrow more

Repay

Read user borrow state

Viem

Buy with Viem

Sell with Viem

Borrow, borrow more, and repay with Viem

Web3.js

Python Web3.py

Buy with Python

Sell with Python

Borrow, borrow more, and repay with Python

Common mistakes