approve
Approves token allowance for a spender.
Usage
example.tsx
import { mintclub, wei } from 'mint.club-v2-sdk'
import { useWalletClient } from 'wagmi'
import { mainnet } from 'viem/chains'
function ApproveExample() {
const { data: walletClient } = useWalletClient()
const handleApprove = async () => {
await mintclub
.withWalletClient({
...walletClient,
chain: mainnet,
} as any)
.network('ethereum')
.token('SYMBOL')
.approve({
amount: wei(1, 18),
spender: '0x...',
})
}
return <button onClick={handleApprove}>Approve</button>
}Return Value
Promise<TransactionReceipt>
Returns a promise that resolves to a TransactionReceipt object when the transaction is successful.
Parameters
amount
- Type:
bigint
Amount to approve
example.ts
import { mintclub, wei } from 'mint.club-v2-sdk'
await mintclub
.network('ethereum')
.token('SYMBOL')
.approve({
amount: wei(1, 18),
spender: '0x...',
})spender
- Type:
'0x...${string}'
The address of the spender
example.ts
import { mintclub, wei } from 'mint.club-v2-sdk'
await mintclub
.network('ethereum')
.token('SYMBOL')
.approve({
amount: wei(1, 18),
spender: '0x...',
})onSignatureRequest (optional)
- Type:
onSignatureRequest?: () => void; - Default:
undefined
Callback function for when the user is requested to sign the transaction.
await mintclub
.network('ethereum')
.token('MINT')
.approve({
amount: wei(1, 18),
spender: '0x...'
onSignatureRequest: () => {}
})onSigned (optional)
- Type:
onSigned?: (txHash: '0x${string}') => void; - Default:
undefined
Callback function for when the user is signs the transaction.
await mintclub
.network('ethereum')
.token('MINT')
.approve({
amount: wei(1, 18),
spender: '0x...'
onSigned: (txHash) => {}
})onSuccess (optional)
- Type:
onSuccess?: (receipt: TransactionReceipt) => void; - Default:
undefined
Callback function for when the transaction is successful.
await mintclub
.network('ethereum')
.token('MINT')
.approve({
amount: wei(1, 18),
spender: '0x...'
onSuccess: (receipt) => {}
})onError (optional)
- Type:
onError?: (error: unknown) => void; - Default:
undefined
Callback function for when the transaction fails. This also includes when the user rejects the transaction.
await mintclub
.network('ethereum')
.token('MINT')
.approve({
amount: wei(1, 18),
spender: '0x...'
onError: (error) => {}
})