1. Generate a SIWE message for the smart account
To start, import theuseLinkWithSiwe hook from @privy-io/react-auth. This hook allows you to generate a SIWE message for an arbitrary wallet and pass the resulting signature for verification.
generateSiweMessage method returned by the hook to generate a SIWE message for the smart account to sign. As parameters to this method, pass an object with the following fields:
Make sure the
chainId you pass to generateSiweMessage and linkWithSiwe is
CAIP-2 formatted.2. Request a personal_sign signature from the smart account
Next, with the message you generated in step (1), request a EIP191 personal_sign signature from the smart account.
The interface for requesting this signature may depend on which smart account provider (ZeroDev, Pimlico, Safe, Biconomy, Alchemy your app uses; see the corresponding guides to understand the best way to request a signature from the wallet.
3. Pass the signature to Privy
Lastly, pass thesignature from the smart account to Privy using the linkWithSiwe method returned by the useLinkWithSiwe hook. As parameters to this method, include an object with the following fields:
As an example, you can pass the smart account’s signature to Privy for verification like so:
4. Get the smart account address
Once you’ve successfully linked the smart account to the user, you can easily get their smart account address from their Privyuser object. Simply inspect the linkedAccounts array for the entry with:
type: 'wallet'walletClientType: 'privy_smart_account', or any other customwalletClientTypeyou chose
linked_accounts array.
