.claude/skills/permit2-wagmi-integration/SKILL.md
Integration patterns for Permit2 with wagmi hooks. Use when building UI components that interact with Permit2.
npx skillsauth add cyotee/crane permit2-wagmi-integrationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Complete patterns for integrating Permit2 with wagmi/viem.
import { useWriteContract, useReadContract, useAccount, useChainId } from 'wagmi'
import { usePublicClient, useWalletClient } from 'wagmi'
import { erc20Abi } from 'viem'
import { SignatureTransfer, PERMIT2_ADDRESS } from '@uniswap/permit2-sdk'
function useTokenAllowance(token: string, owner: string) {
const { data } = useReadContract({
address: token,
abi: erc20Abi,
functionName: 'allowance',
args: [owner, PERMIT2_ADDRESS],
query: { staleTime: 0 }
})
return data ?? 0n
}
function usePermit2Allowance(token: string, owner: string, spender: string) {
const { data } = useReadContract({
address: PERMIT2_ADDRESS,
abi: [{
inputs: [
{ name: 'owner', type: 'address' },
{ name: 'token', type: 'address' },
{ name: 'spender', type: 'address' }
],
name: 'allowance',
outputs: [
{ name: 'amount', type: 'uint160' },
{ name: 'expiration', type: 'uint48' },
{ name: 'nonce', type: 'uint48' }
],
stateMutability: 'view',
type: 'function'
}],
functionName: 'allowance',
args: [owner, token, spender],
query: { staleTime: 0 }
})
return data
}
import { useSignTypedData } from 'wagmi'
import { keccak256, encodePacked } from 'viem'
const WITNESS_TYPE: Record<string, TypedDataField[]> = {
Witness: [{ name: 'actionId', type: 'bytes32' }]
}
function usePermitSignature() {
const { signTypedDataAsync } = useSignTypedData()
const chainId = useChainId()
const signPermit = async (
token: string,
amount: bigint,
spender: string,
nonce: bigint,
witness?: { actionId: `0x${string}` }
) => {
const permit: SignatureTransfer.PermitTransferFrom = {
permitted: { token, amount },
nonce,
deadline: BigInt(Math.floor(Date.now() / 1000)) + 1800n
}
const witnessData = witness
? { witness: witness.actionId, witnessTypeName: 'Witness', witnessType: WITNESS_TYPE }
: undefined
const { domain, types, values } = SignatureTransfer.getPermitData(
permit,
PERMIT2_ADDRESS,
chainId,
witnessData
)
return signTypedDataAsync(domain, types, values)
}
return { signPermit }
}
development
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
documentation
Write to contracts and send transactions. Use when executing state-changing contract functions.
development
HTTP and WebSocket transports for blockchain connectivity. Use when configuring network connections.
data-ai
Read contract data with type-safe ABI. Use when querying smart contract view/pure functions.