Validate Receive Policy
receivePolicy.validate
Checks whether a transfer or mint to a receiver is allowed by the receiver receive policy.
Usage
import { } from './viem.config'
const = await ..({
: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
: '0x20c0000000000000000000000000000000000001',
})
.('Authorized:', .)
Authorized: trueimport { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Recipes
Screen a Payout Before Sending It
Combine receivePolicy.validate with token.transferSync to hold a payroll payout that would block onchain, and surface the reason to your operators.
import { } from './viem.config'
const = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb'
const = '0x20c0000000000000000000000000000000000000'
const { , } = await ..({
: ,
: ..,
: ,
})
if (!) throw new (`Payout blocked: ${}`)
const { } = await ..({
: { : '1250' },
: ,
: ,
})import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Fall Back to a Token the Recipient Accepts
Probe your settlement currencies in preference order and settle in the first one the recipient's policy authorizes.
import { } from './viem.config'
const = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb'
// Settlement currencies in preference order.
const = [
'0x20c0000000000000000000000000000000000000',
'0x20c0000000000000000000000000000000000001',
] as
let
for (const of ) {
const { } = await ..({
: ,
: ..,
: ,
})
if (!) continue
=
break
}
.('Settling in:', )
Settling in: 0x20c0000000000000000000000000000000000000import { , } from 'viem/tempo'
export const = .({
: .('0x...'),
})Return Value
type ReturnType = {
/** Whether the transfer is authorized. */
authorized: boolean
/** Reason the transfer would be blocked. */
blockedReason: 'none' | 'tokenFilter' | 'receivePolicy'
}Whether the transfer is authorized and why it would be blocked.
Parameters
receiver
- Type:
Address
Receiver address.
sender
- Type:
Address
Sender address.
token
- Type:
Address
Token address.
blockNumber (optional)
- Type:
bigint
Block number to read the state from.
blockOverrides (optional)
- Type:
BlockOverrides
Block overrides to apply to the state.
blockTag (optional)
- Type:
BlockTag
Block tag to read the state from.
stateOverride (optional)
- Type:
StateOverride
State override to apply.