Skip to main content
This guide builds a Next.js flow where users discover a yield across DeFi, staking and tokenized real-world assets, enter it, track the position and exit, signing with the Sequence embedded wallet. Sequence wallets are smart wallets, so every step of an action, such as an approval and a deposit, can go out as one atomic transaction with a single confirmation, and gas can be sponsored. The second part covers Trails, Sequence’s intent-based cross-chain rails, and how yield.xyz supplies the discovery, transaction building and position tracking behind Trails Earn.

Resources

Prerequisites

  • A yield.xyz API key. See Projects & API keys.
  • A Sequence project access key and WaaS config key from Sequence Builder.

Getting started with Sequence

Install the SDK and sign the user in. Social login, email and guest sign-in are supported, with no seed phrase.
A Sequence wallet address is the same across every app on the same Sequence project.

How yield.xyz fits

yield.xyz gives you one API across 4,000+ yields on 85+ networks:
  • Discover: GET /v1/yields returns yields with their metadata.
  • Act: POST /v1/actions/enter, /exit and /manage return an ordered list of unsigned transactions.
  • Track: POST /v1/yields/{yieldId}/balances and POST /v1/yields/balances return lifecycle-aware balances.
yield.xyz builds transactions and never signs or holds funds. Sequence signs them in the user’s wallet. This guide uses EVM networks.

Keep the API key on your server

Keep your yield.xyz API key on your server. The snippets in this guide call a small proxy route that adds the key, for example a Next.js route handler:
On the client, one helper calls it:

Discover a yield

The discovery response already carries what your UI needs, so you don’t need a second request per yield.
Every field on a yield is described in Yield metadata.

Find yields to offer

Rather than hardcoding yield IDs, which change as yields are added and retired, query the catalog for what you want to offer:
Add prime=true to return only yields that meet the Prime quality bar. For staking, default users to preferred validators. For DeFi, wrap yields in an OAV to charge fees and auto-compound incentives (see Monetization).

Enter a yield

Build the action, map its transactions to Sequence’s format and send them as one batch. Sequence simulates the batch first and does not broadcast it if it would fail.
To make the flow gasless for users, sponsor the yield contracts or your users’ wallets in Sequence Builder and leave out the fee quote. Show the fee option in your UI if you charge users for gas. Build the arguments from mechanics.arguments.enter.fields rather than hardcoding { amount }, so the same code works for yields that also need a validatorAddress or another field. Amounts are in token units, for example "100" for 100 USDC. See Enter and exit flows.

KYC-gated RWA yields

Tokenized real-world assets, such as US Treasuries, money market funds and private credit, use the same enter and exit flow, so no new signing code is needed. Some issuers require the wallet to be allowlisted first, shown by mechanics.requirements.kycRequired: true on the yield. Check the wallet when it connects, so you can show “Verify identity” instead of “Deposit” for a gated yield:
Send the user to authorizeUrl when the status is not_started or rejected, ideally in a new tab or after saving the pending deposit so you can resume it, and enter once it is approved. If you call enter for a wallet that is not cleared, the API returns 412 with RwaKycError, and the message includes the issuer’s KYC URL:
Read entryLimits.minimum before you build the action: many RWA yields have high minimums. Issuer eligibility is in RWA KYC and on each issuer’s page under RWAs.

Read the position balance

Balances are lifecycle-aware: each one has a type that says whether funds are active, entering, exiting, withdrawable, claimable or locked.
For many yields or wallets at once, use POST /v1/yields/balances with { "queries": [{ "address", "network" }] }, up to 25 queries per request:
See Tracking balances.

Handle pending actions

A balance can carry pendingActions, such as CLAIM_REWARDS or CLAIM_UNSTAKED. Pass one back to POST /v1/actions/manage unchanged, then sign the result the same way as an enter:

Exit a yield

Exiting is the same pattern as entering:
Some exits need more than one transaction, for example withdraw and unwrap. Sequence sends them as one batch, with one confirmation. Not every exit settles at once. Staking unbonds wait out the network’s cooldown, and many RWA redemptions settle on a NAV strike or over several days. While that happens the position shows as an exiting balance. When it settles it becomes withdrawable with a CLAIM_UNSTAKED pending action, which you complete through POST /v1/actions/manage as above. Poll balances on a sensible cadence and show the in-flight state in your UI.

Track transaction status

After each broadcast, report the hash with PUT /v1/transactions/{transactionId}/submit-hash, then poll GET /v1/transactions/{transactionId} (or GET /v1/actions/{actionId}) until it reaches a terminal status:
See Monitoring and alerting.

Integration tips

  • Send transactions in stepIndex order and skip any already at a terminal status.
  • Never change to, data, value, gas or nonce before signing.
  • Build arguments from mechanics.arguments.* for the right fields and units.
  • Keep your yield.xyz API key on the server.
  • Geo-blocking is applied by the API for your project; see Geo-blocking.
  • Batch every step of an action into one sendTransaction call: one confirmation, atomic execution.
  • Use sendTransaction for the raw transactions yield.xyz returns; callContract is for a single ABI call you encode yourself.
  • Check isSentTransactionResponse before reporting a hash: a failed simulation is never broadcast.

Power Trails Earn with yield.xyz

Trails Earn lets users deposit into DeFi protocols and RWA vaults from any token on any chain. Trails handles the cross-chain routing, bridging and swapping. yield.xyz supplies the three things Trails Earn needs underneath: which yields to show, the calldata to enter and exit them, and the user’s positions afterwards. New yields, protocols and issuers added to yield.xyz become available to Trails without new integration work.

1. Populate the Earn UI

2. Build the deposit

When the user picks a yield and an amount, build the enter action for the user’s address on the destination chain:
For a KYC-gated RWA yield, check GET /v1/yields/{yieldId}/kyc/status for the destination address before the user starts a cross-chain deposit, so they don’t bridge funds and then hit a 412 on enter.

3. Track positions

Trails doesn’t need to understand each protocol’s balance model, including RWA redemptions that settle over days.

4. Build the withdrawal

Monetization

How you earn depends on the yield type. Each yield’s mechanics.possibleFeeTakingMechanisms says which fees you can configure on it.
  • Staking: deposit fees, deducted atomically in the same transaction, and a share of validator revenue through yield.xyz’s validator agreements. See Preferred validators.
  • DeFi: revenue share from some protocols and curators, and user-facing deposit, performance and management fees through OAVs.
  • RWAs: issuer fees are set by the issuer and passed through. Where an RWA is wrapped in an OAV, you can add your own fees on top.
OAVs also improve the user experience: incentive tokens are sold into the deposit asset and reinvested automatically, wrapping and swapping are handled for the user, and users only ever see their deposit token. See Earn monetization for fee configuration, and Plans for commercial terms.

Next steps

Enter and exit flows

The full request, sign and poll loop.

Yield metadata

Every field returned on a yield.

Shield

Verify each transaction before Sequence signs it.

Embedded wallets

The same flow with other wallet providers.