Using Privy Wallets
If you use Privy to manage wallets for your users, you can connect those wallets to Legend to access DeFi yield, swaps, and transfers — without changing your key management setup. This guide covers the integration pattern: how a Privy embedded wallet becomes a Legend sub-account signer, and how to sign Legend plans using Privy’ssecp256k1_sign method.
How it fits together
Privy handles wallet creation and key management. Legend handles DeFi operations. The two connect through the wallet’s EOA address. Legend never sees the private key. Privy holds it. Your app passes the plan’s EIP-712 digest to Privy for signing, then relays the signature back to Legend for execution.Prerequisites
- A Legend Prime Account with a query key (contact us to get set up)
- A Privy app with embedded wallets enabled
legend-primeand@privy-io/react-authinstalled
Step 1 — Get the Privy wallet address
When a user authenticates with Privy, they get an embedded wallet. Use its address as the Legend signer.Step 2 — Create a Legend sub-account
Pass the wallet address to Legend as aneoa signer. This is typically done from your backend.
legend_wallet_address is where funds live.
Step 3 — Create a plan
When your user wants to earn yield (or swap, transfer, etc.), create a plan through Legend. The plan response includes an EIP-712 digest — a hash that needs to be signed by the wallet’s key.Plans expire after 2 minutes. Sign and execute before
expires_at or create a new plan.Step 4 — Sign the digest with Privy
This is where the two systems meet. Pass the EIP-712 digest to Privy’ssecp256k1_sign method, which performs raw curve-level signing over the hash — exactly what Legend expects.
secp256k1_sign signs the hash directly without any prefix or transformation. This is the same operation that viem’s signer.sign({ hash }) performs — just routed through Privy’s key management instead of a local private key.
Don’t use
personal_sign or eth_signTypedData_v4 here. personal_sign adds an Ethereum message prefix that produces the wrong signature. eth_signTypedData_v4 requires the full EIP-712 typed data object and recomputes the digest internally — unnecessary since Legend already provides the digest.Step 5 — Execute the plan
Send the signature back to Legend. This triggers the on-chain transaction.Step 6 — Monitor
Poll activities or use long-polling events to confirm the transaction.Architecture patterns
Privy + Legend integrations typically follow one of two patterns:User-facing app
Your frontend handles Privy auth and signing. Your backend handles Legend API calls. Users see an “Earn Yield” button, click it, approve the signing request, and funds are deployed.| Layer | Responsibility |
|---|---|
| Frontend | Privy auth, wallet access, secp256k1_sign |
| Backend | Legend SDK, plan creation, plan execution |
Automated backend
Your backend manages Privy wallets via the server SDK and signs on behalf of users (with their consent). No user interaction needed for signing.Full example
Here’s a complete React component that creates an earn plan and signs it with Privy:Next steps
- Plan-Sign-Execute — Understand the signing model in depth
- Earn Yield — More detail on earn plans and supported protocols
- Monitoring — Track transaction status with activities and events
- TypeScript SDK — Full SDK reference