Guest mode is triggered by passing account: null within a transaction call (such as those from viem or wagmi). When Porto detects a null account, it intercepts the request and manages the account connection flow (prompting the user to connect or create an account) only when the transaction is actually ready to be sent.
import { erc20Abi, parseUnits, type Address } from 'viem'
import { writeContract } from 'viem/actions'
import { useClient } from 'wagmi'
export function Send() {
const client = useClient()
async function handleSend() {
// Setting account to null triggers Porto's interception logic
await writeContract(client!, {
abi: erc20Abi,
account: null,
address: tokenAddress,
functionName: 'transfer',
args: [recipient, parseUnits('10', 18)],
})
}
return (
<button onClick={handleSend}>
Send
</button>
)
}