Skip to Content
wstGBP is live on Ethereum mainnet · all addresses in these docs are verifiable on-chain
GuidesIntegration Recipes

Integration Recipes

Practical snippets for integrating wstGBP. They use viem  and wagmi ; the math mirrors the on‑chain contract to the wei. Paste the ABI into ./wstgbpAbi.ts first.

addresses.ts
export const WSTGBP = '0x57C3571f10767E49C9d7b60feb6c67804783B7aE' export const TGBP = '0x27f6c8289550fCE67f6B50BeD1F519966aFE5287' export const MULTICALL3 = '0xcA11bde05977b3631167028862bE2a173976CA11'

Read NAV and quoting state

mintcost() and burncost() are already fee‑adjusted — use them directly rather than re‑deriving from navprice().

import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' import { wstgbpAbi } from './wstgbpAbi' import { WSTGBP } from './addresses' const pub = createPublicClient({ chain: mainnet, transport: http() }) const [navprice, mintcost, burncost] = await Promise.all([ pub.readContract({ address: WSTGBP, abi: wstgbpAbi, functionName: 'navprice' }), pub.readContract({ address: WSTGBP, abi: wstgbpAbi, functionName: 'mintcost' }), pub.readContract({ address: WSTGBP, abi: wstgbpAbi, functionName: 'burncost' }), ])

Batch every read in one Multicall3 call

Reading state piecemeal is wasteful and can tear (values from different blocks). Batch with viem’s multicall (it routes through Multicall3 at 0xcA11bde05977b3631167028862bE2a173976CA11).

const wst = { address: WSTGBP, abi: wstgbpAbi } as const const [ navprice, mintcost, burncost, mintable, burnable, cooldown, capacity, totalSupply, ] = await pub.multicall({ allowFailure: false, contracts: [ { ...wst, functionName: 'navprice' }, { ...wst, functionName: 'mintcost' }, { ...wst, functionName: 'burncost' }, { ...wst, functionName: 'mintable' }, { ...wst, functionName: 'burnable' }, { ...wst, functionName: 'cooldown' }, { ...wst, functionName: 'capacity' }, { ...wst, functionName: 'totalSupply' }, ], })

Preview mint & redeem (WAD math)

These mirror the contract exactly — BigInt only, no floating point.

preview.ts
export const WAD = 10n ** 18n export const wdiv = (x: bigint, y: bigint) => (x * WAD) / y // floor export const wmul = (x: bigint, y: bigint) => (x * y) / WAD // floor // mint: tGBP in -> wstGBP out export function previewMint(args: { amountIn: bigint; mintcost: bigint; totalSupply: bigint; capacity: bigint; mintable: boolean }): { out: bigint; reason?: 'paused' | 'dust' | 'capacity' } { if (!args.mintable) return { out: 0n, reason: 'paused' } if (args.amountIn < args.mintcost) return { out: 0n, reason: 'dust' } const out = wdiv(args.amountIn, args.mintcost) if (args.totalSupply + out > args.capacity) return { out, reason: 'capacity' } return { out } } // redeem: wstGBP in -> tGBP out export function previewRedeem(args: { amountIn: bigint; burncost: bigint; burnable: boolean }): { out: bigint; reason?: 'paused' | 'dust' } { if (!args.burnable) return { out: 0n, reason: 'paused' } if (args.amountIn < WAD) return { out: 0n, reason: 'dust' } // min one whole wstGBP return { out: wmul(args.amountIn, args.burncost) } }

To target an exact output, round the input up: wmulUp(targetOut, mintcost) for mint, wdivUp(targetOut, burncost) for redeem (see Mint & Redeem).

Watch events

import { parseAbiItem } from 'viem' // new mints const unwatchMint = pub.watchEvent({ address: WSTGBP, event: parseAbiItem( 'event ContractCreated(address indexed creator, uint256 indexed price, uint256 indexed amount)', ), onLogs: (logs) => console.log('minted', logs), }) // redemptions opened + claims settled const unwatchClaim = pub.watchEvent({ address: WSTGBP, event: parseAbiItem( 'event ClaimProcessed(uint256 indexed id, address indexed claimer, uint256 indexed amount)', ), onLogs: (logs) => console.log('claimed', logs), })

wagmi (React)

import { useReadContracts } from 'wagmi' import { wstgbpAbi } from './wstgbpAbi' import { WSTGBP } from './addresses' const wst = { address: WSTGBP, abi: wstgbpAbi } as const export function useWstgbpState() { return useReadContracts({ allowFailure: false, contracts: [ { ...wst, functionName: 'mintcost' }, { ...wst, functionName: 'burncost' }, { ...wst, functionName: 'mintable' }, { ...wst, functionName: 'burnable' }, { ...wst, functionName: 'cooldown' }, { ...wst, functionName: 'totalSupply' }, ], }) }

For full mint/redeem write flows (approval, simulate, send, decode receipt), see Mint & Redeem. For historical/aggregated data (supply over time, holders, price history, redemption lifecycle), use the subgraph in Data & Analytics.

Last updated on