Skip to content

Commit 724b457

Browse files
committed
updated apikey and removed gasless
1 parent c0f6539 commit 724b457

File tree

15 files changed

+126
-43
lines changed

15 files changed

+126
-43
lines changed

api-reference/introduction.mdx

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ description: "Learn how to integrate the Trails API for cross-chain transactions
77

88
The Trails API enables seamless cross-chain token swaps, deposits, payments, and smart contract executions in a simplified interface with the Trails protocol. This guide walks you through the complete flow from requesting a quote to executing a transaction.
99

10+
<Note>
11+
**Get Your API Key**: Join the [Trails Telegram group](https://t.me/build_with_trails) to request your API access key.
12+
</Note>
13+
1014
## Core Workflow
1115

1216
Every interaction through Trails follows this four-step process:
@@ -27,7 +31,7 @@ const balancesResponse = await fetch('https://indexer.sequence.app/rpc/IndexerGa
2731
method: 'POST',
2832
headers: {
2933
'Content-Type': 'application/json',
30-
'X-Access-Key': 'AQAAAAAAAF_JvPALhBthL7VGn6jV0YDqaFY' // example access key
34+
'X-Access-Key': 'YOUR_API_KEY'
3135
},
3236
body: JSON.stringify({
3337
accountAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
@@ -50,6 +54,7 @@ const quoteResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/Qu
5054
method: 'POST',
5155
headers: {
5256
'Content-Type': 'application/json',
57+
'X-Access-Key': 'YOUR_API_KEY'
5358
},
5459
body: JSON.stringify({
5560
ownerAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb', // sender address
@@ -79,7 +84,7 @@ console.log('Quote received:', {
7984

8085
**Key Parameters:**
8186

82-
- **ownerAddress**: User's sender address
87+
- **ownerAddress**: User's wallet address
8388
- **originChainId** & **destinationChainId**: Source and destination chains
8489
- **originTokenAddress** & **destinationTokenAddress**: Token contracts
8590
- **originTokenAmount**: Amount to swap (in token's smallest unit)
@@ -98,6 +103,7 @@ const commitResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/C
98103
method: 'POST',
99104
headers: {
100105
'Content-Type': 'application/json',
106+
'X-Access-Key': 'YOUR_API_KEY'
101107
},
102108
body: JSON.stringify({ intent })
103109
});
@@ -140,31 +146,36 @@ const publicClient = createPublicClient({
140146
</Accordion>
141147

142148
```typescript
143-
// send tokens to the intent address
144-
const depositTx = await walletClient.sendTransaction({
145-
to: intent.depositTransaction.toAddress,
149+
// Send tokens to the intent address (where Trails will execute from)
150+
const intentAddress = intent.depositTransaction.toAddress;
151+
const tokenAddress = intent.depositTransaction.tokenAddress;
152+
const amount = intent.depositTransaction.amount;
153+
154+
const depositTxHash = await walletClient.sendTransaction({
155+
to: intentAddress,
146156
value: 0n, // No native ETH sent (0 for ERC20 transfers, or ETH amount if sending native token)
147157
data: encodeERC20Transfer( // Use your favorite library such as viem to encode ERC20 transfer
148-
intent.depositTransaction.tokenAddress,
149-
intent.depositTransaction.toAddress,
150-
intent.depositTransaction.amount
158+
tokenAddress,
159+
intentAddress,
160+
amount
151161
)
152162
});
153163

154164
// Wait for transaction confirmation using viem
155165
const receipt = await publicClient.waitForTransactionReceipt({
156-
hash: depositTx
166+
hash: depositTxHash
157167
});
158168

159169
// Then execute the intent with the deposit transaction hash and intentId
160170
const executeResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/ExecuteIntent', {
161171
method: 'POST',
162172
headers: {
163173
'Content-Type': 'application/json',
174+
'X-Access-Key': 'YOUR_API_KEY'
164175
},
165176
body: JSON.stringify({
166177
intentId,
167-
depositTransactionHash: depositTx
178+
depositTransactionHash: depositTxHash
168179
})
169180
});
170181

@@ -195,10 +206,10 @@ const publicClient = createPublicClient({
195206
</Accordion>
196207

197208
```typescript
198-
import { erc20Abi } from 'viem';
209+
import { erc20Abi, parseAbi } from 'viem';
199210

200211
// Select a gas fee option from the quote response
201-
const selectedGasFeeOption = gasFeeOptions[0]; // Choose based on user preference
212+
const selectedGasFeeOption = gasFeeOptions.feeOptions[0]; // Choose based on user preference
202213

203214
// Constants for the flow
204215
const INTENT_ENTRYPOINT_ADDRESS = '0x9470d883bac170116d397db3da71b2e57d567583'; // Trails Intent Entrypoint (same on all chains)
@@ -207,20 +218,17 @@ const deadline = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
207218
// 1. Get user nonce from Intent Entrypoint contract
208219
const userNonce = await publicClient.readContract({
209220
address: INTENT_ENTRYPOINT_ADDRESS,
210-
abi: [{
211-
name: 'nonces',
212-
type: 'function',
213-
stateMutability: 'view',
214-
inputs: [{ name: 'user', type: 'address' }],
215-
outputs: [{ name: '', type: 'uint256' }]
216-
}],
221+
abi: parseAbi([
222+
'function nonces(address user) view returns (uint256)'
223+
]),
217224
functionName: 'nonces',
218225
args: [intent.ownerAddress]
219226
});
220227

221228
// 2. Check if approval is needed for the deposit token
229+
const tokenAddress = intent.depositTransaction.tokenAddress;
222230
const currentAllowance = await publicClient.readContract({
223-
address: intent.depositTransaction.tokenAddress,
231+
address: tokenAddress,
224232
abi: erc20Abi,
225233
functionName: 'allowance',
226234
args: [intent.ownerAddress, INTENT_ENTRYPOINT_ADDRESS]
@@ -236,21 +244,19 @@ let permitAmount;
236244
if (needsApproval) {
237245
// Read token metadata for permit signature
238246
const tokenNonce = await publicClient.readContract({
239-
address: intent.depositTransaction.tokenAddress,
240-
abi: [{
241-
name: 'nonces',
242-
type: 'function',
243-
stateMutability: 'view',
244-
inputs: [{ name: 'owner', type: 'address' }],
245-
outputs: [{ name: '', type: 'uint256' }]
246-
}],
247+
address: tokenAddress,
248+
abi: parseAbi([
249+
'function nonces(address owner) view returns (uint256)'
250+
]),
247251
functionName: 'nonces',
248252
args: [intent.ownerAddress]
249253
});
250254

251255
const tokenName = await publicClient.readContract({
252-
address: intent.depositTransaction.tokenAddress,
253-
abi: [{ name: 'name', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ name: '', type: 'string' }] }],
256+
address: tokenAddress,
257+
abi: parseAbi([
258+
'function name() view returns (string)'
259+
]),
254260
functionName: 'name'
255261
});
256262

@@ -262,7 +268,7 @@ if (needsApproval) {
262268
name: tokenName,
263269
version: '1',
264270
chainId: intent.originChainId,
265-
verifyingContract: intent.depositTransaction.tokenAddress
271+
verifyingContract: tokenAddress
266272
},
267273
types: {
268274
Permit: [
@@ -285,6 +291,7 @@ if (needsApproval) {
285291
}
286292

287293
// 4. Sign the intent signature (ERC712) with fee payment authorization
294+
const intentAddress = intent.depositTransaction.toAddress;
288295
const intentSignature = await walletClient.signTypedData({
289296
domain: {
290297
name: 'TrailsIntentEntrypoint',
@@ -308,13 +315,13 @@ const intentSignature = await walletClient.signTypedData({
308315
primaryType: 'TrailsIntent',
309316
message: {
310317
user: intent.ownerAddress,
311-
token: intent.depositTransaction.tokenAddress,
318+
token: tokenAddress,
312319
amount: intent.depositTransaction.amount,
313-
intentAddress: intent.depositTransaction.toAddress,
320+
intentAddress: intentAddress,
314321
deadline: BigInt(deadline),
315322
chainId: BigInt(intent.originChainId),
316323
nonce: userNonce,
317-
feeAmount: BigInt(selectedGasFeeOption.amount), // Note: 'amount' not 'feeAmount'
324+
feeAmount: BigInt(selectedGasFeeOption.amount),
318325
feeCollector: selectedGasFeeOption.feeCollectorAddress
319326
}
320327
});
@@ -324,6 +331,7 @@ const executeResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/
324331
method: 'POST',
325332
headers: {
326333
'Content-Type': 'application/json',
334+
'X-Access-Key': 'YOUR_API_KEY'
327335
},
328336
body: JSON.stringify({
329337
intentId,
@@ -389,6 +397,7 @@ async function waitForCompletion(intentId: string) {
389397
method: 'POST',
390398
headers: {
391399
'Content-Type': 'application/json',
400+
'X-Access-Key': 'YOUR_API_KEY'
392401
},
393402
body: JSON.stringify({ intentId })
394403
}
@@ -420,7 +429,13 @@ const receipt = await waitForCompletion(intentId);
420429
</Step>
421430
</Steps>
422431

423-
Now you have an end to end API integration with Trails!
432+
Now you have an end to end API integration with Trails for seamless chain abstraction flows! You can continue this initial integration for specific use cases such as:
433+
434+
- x402 Payments
435+
- AI Agents
436+
- Server-side currency conversion & settlement
437+
- Fund, Swap, Earn, or Pay for any application
438+
- Pass in optional calldata to call any smart contract function
424439

425440
## Next Steps
426441

api-reference/trails-api.gen.json

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ApiKeyAuth": {
1616
"type": "apiKey",
1717
"in": "header",
18-
"description": "Project access key for authenticating requests, get an access key at https://sequence.build",
18+
"description": "apiKey for authenticating requests, get an access key at https://t.me/build_with_trails",
1919
"name": "X-Access-Key"
2020
}
2121
},
@@ -2502,6 +2502,11 @@
25022502
"summary": "Quote Intent",
25032503
"description": "Get a quote for a cross-chain intent transaction including gas fees and optimal routing",
25042504
"operationId": "QuoteIntent",
2505+
"security": [
2506+
{
2507+
"ApiKeyAuth": []
2508+
}
2509+
],
25052510
"requestBody": {
25062511
"required": true,
25072512
"content": {
@@ -2531,6 +2536,11 @@
25312536
"summary": "Commit Intent",
25322537
"description": "Commit an intent to execute a cross-chain transaction",
25332538
"operationId": "CommitIntent",
2539+
"security": [
2540+
{
2541+
"ApiKeyAuth": []
2542+
}
2543+
],
25342544
"requestBody": {
25352545
"required": true,
25362546
"content": {
@@ -2560,6 +2570,11 @@
25602570
"summary": "Execute Intent",
25612571
"description": "Execute a committed intent transaction",
25622572
"operationId": "ExecuteIntent",
2573+
"security": [
2574+
{
2575+
"ApiKeyAuth": []
2576+
}
2577+
],
25632578
"requestBody": {
25642579
"required": true,
25652580
"content": {
@@ -2589,6 +2604,11 @@
25892604
"summary": "Get Intent Receipt",
25902605
"description": "Retrieve the receipt for a completed intent transaction",
25912606
"operationId": "GetIntentReceipt",
2607+
"security": [
2608+
{
2609+
"ApiKeyAuth": []
2610+
}
2611+
],
25922612
"requestBody": {
25932613
"required": true,
25942614
"content": {
@@ -2618,6 +2638,11 @@
26182638
"summary": "Wait for Intent Receipt",
26192639
"description": "Wait for an intent transaction to complete and return the receipt",
26202640
"operationId": "WaitIntentReceipt",
2641+
"security": [
2642+
{
2643+
"ApiKeyAuth": []
2644+
}
2645+
],
26212646
"requestBody": {
26222647
"required": true,
26232648
"content": {
@@ -2647,6 +2672,11 @@
26472672
"summary": "Get Intent",
26482673
"description": "Retrieve details of a specific intent by ID",
26492674
"operationId": "GetIntent",
2675+
"security": [
2676+
{
2677+
"ApiKeyAuth": []
2678+
}
2679+
],
26502680
"requestBody": {
26512681
"required": true,
26522682
"content": {
@@ -2676,6 +2706,11 @@
26762706
"summary": "Search Intents",
26772707
"description": "Search for intents by various criteria including owner address, intent address, or transaction hash",
26782708
"operationId": "SearchIntents",
2709+
"security": [
2710+
{
2711+
"ApiKeyAuth": []
2712+
}
2713+
],
26792714
"requestBody": {
26802715
"required": true,
26812716
"content": {
@@ -2705,6 +2740,11 @@
27052740
"summary": "Get Intent Transaction History",
27062741
"description": "Retrieve transaction history for intents with pagination support",
27072742
"operationId": "GetIntentTransactionHistory",
2743+
"security": [
2744+
{
2745+
"ApiKeyAuth": []
2746+
}
2747+
],
27082748
"requestBody": {
27092749
"required": true,
27102750
"content": {
@@ -2734,6 +2774,11 @@
27342774
"summary": "Get Token Prices",
27352775
"description": "Retrieve current USD prices for specified tokens",
27362776
"operationId": "GetTokenPrices",
2777+
"security": [
2778+
{
2779+
"ApiKeyAuth": []
2780+
}
2781+
],
27372782
"requestBody": {
27382783
"required": true,
27392784
"content": {

api-reference/trails-api.gen.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ servers:
1111
- url: https://trails-api.sequence.app
1212
description: Trails API Server
1313
components:
14-
securitySchemes: {'ApiKeyAuth': {'type': 'apiKey', 'in': 'header', 'description': 'Project access key for authenticating requests, get an access key at https://sequence.build', 'name': 'X-Access-Key'}}
14+
securitySchemes: {'ApiKeyAuth': {'type': 'apiKey', 'in': 'header', 'description': 'apiKey for authenticating requests, get an access key at https://t.me/build_with_trails', 'name': 'X-Access-Key'}}
1515
schemas:
1616
ErrorWebrpcEndpoint:
1717
type: object

examples/alt-fee-tokens.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { TrailsWidget } from '0xtrails/widget'
1515

1616
export const PayWithAnyToken = () => (
1717
<TrailsWidget
18+
apiKey="YOUR_API_KEY"
1819
mode="pay"
19-
gasless={true}
2020
toAddress="0x1234567890123456789012345678901234567890"
2121
toAmount="1"
2222
toChainId={8453} // Base

examples/gasless.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { TrailsWidget } from '0xtrails/widget'
1515

1616
export const GaslessWithPaymaster = () => (
1717
<TrailsWidget
18+
apiKey="YOUR_API_KEY"
1819
mode="pay"
19-
gasless={true}
2020
paymasterUrls={[
2121
{ chainId: 8453, url: 'https://paymaster.example.com' }
2222
]}
@@ -37,8 +37,8 @@ import { TrailsWidget } from '0xtrails/widget'
3737

3838
export const GaslessWithSequence = () => (
3939
<TrailsWidget
40+
apiKey="YOUR_API_KEY"
4041
mode="pay"
41-
gasless={true}
4242
toAddress="0x1234567890123456789012345678901234567890"
4343
toAmount="0.1"
4444
toChainId={8453}

examples/receive.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { TrailsWidget } from '0xtrails/widget'
1818
export const FixedQRPayment = () => {
1919
return (
2020
<TrailsWidget
21+
apiKey="YOUR_API_KEY"
2122
mode="receive"
2223
toAddress="0x97c4A952b46bEcaD0663f76357d3776ba11566E1" // Your address
2324
toAmount="25"
@@ -43,6 +44,7 @@ import { TrailsWidget } from '0xtrails/widget'
4344
export const FlexibleQRPayment = () => {
4445
return (
4546
<TrailsWidget
47+
apiKey="YOUR_API_KEY"
4648
mode="receive"
4749
toAddress="0x97c4A952b46bEcaD0663f76357d3776ba11566E1"
4850
toChainId={8453}

0 commit comments

Comments
 (0)