Skip to content

Commit bc06cf6

Browse files
committed
initial commit of API ref, get started guide
1 parent 3f0f90e commit bc06cf6

12 files changed

+64
-114
lines changed

api-reference/endpoints/commit-intent.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The `CommitIntent` step is crucial because it:
4242

4343
```typescript
4444
// First, get a quote
45-
const quoteResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/QuoteIntent', {
45+
const quoteResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/QuoteIntent', {
4646
method: 'POST',
4747
headers: {
4848
'Content-Type': 'application/json',
@@ -54,7 +54,7 @@ const quoteResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/Qu
5454
const { intent, gasFeeOptions } = await quoteResponse.json();
5555

5656
// Then commit the intent
57-
const commitResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/CommitIntent', {
57+
const commitResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/CommitIntent', {
5858
method: 'POST',
5959
headers: {
6060
'Content-Type': 'application/json',

api-reference/endpoints/execute-intent.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The response includes:
5151
If you've already executed the deposit transaction on-chain:
5252

5353
```typescript
54-
const executeResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/ExecuteIntent', {
54+
const executeResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/ExecuteIntent', {
5555
method: 'POST',
5656
headers: {
5757
'Content-Type': 'application/json',
@@ -72,7 +72,7 @@ For gasless execution using meta-transactions:
7272
// Prepare signature
7373
const signature = await signIntent(intent, walletClient);
7474

75-
const executeResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/ExecuteIntent', {
75+
const executeResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/ExecuteIntent', {
7676
method: 'POST',
7777
headers: {
7878
'Content-Type': 'application/json',

api-reference/endpoints/get-intent-receipt.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Each transaction object includes:
7272
## Example
7373

7474
```typescript
75-
const receiptResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/GetIntentReceipt', {
75+
const receiptResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/GetIntentReceipt', {
7676
method: 'POST',
7777
headers: {
7878
'Content-Type': 'application/json',

api-reference/endpoints/get-intent-transaction-history.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Lightweight summary object containing:
7676

7777
```typescript
7878
const historyResponse = await fetch(
79-
'https://api.trails.sequence.app/rpc/Trails/GetIntentTransactionHistory',
79+
'https://trails-api.sequence.app/rpc/Trails/GetIntentTransactionHistory',
8080
{
8181
method: 'POST',
8282
headers: {
@@ -122,7 +122,7 @@ async function loadAllHistory() {
122122

123123
while (page) {
124124
const { intents, nextPage } = await fetch(
125-
'https://api.trails.sequence.app/rpc/Trails/GetIntentTransactionHistory',
125+
'https://trails-api.sequence.app/rpc/Trails/GetIntentTransactionHistory',
126126
{
127127
method: 'POST',
128128
headers: {
@@ -166,7 +166,7 @@ function IntentTransactionHistory() {
166166
setLoading(true);
167167
try {
168168
const response = await fetch(
169-
'https://api.trails.sequence.app/rpc/Trails/GetIntentTransactionHistory',
169+
'https://trails-api.sequence.app/rpc/Trails/GetIntentTransactionHistory',
170170
{
171171
method: 'POST',
172172
headers: {
@@ -317,7 +317,7 @@ function IntentCard({ intent }: { intent: IntentSummary }) {
317317
```typescript
318318
async function getCompletedIntents() {
319319
const { intents } = await fetch(
320-
'https://api.trails.sequence.app/rpc/Trails/GetIntentTransactionHistory',
320+
'https://trails-api.sequence.app/rpc/Trails/GetIntentTransactionHistory',
321321
{
322322
method: 'POST',
323323
headers: {

api-reference/endpoints/get-intent.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The intent object contains comprehensive information:
9191
## Example
9292

9393
```typescript
94-
const intentResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/GetIntent', {
94+
const intentResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/GetIntent', {
9595
method: 'POST',
9696
headers: {
9797
'Content-Type': 'application/json',

api-reference/endpoints/quote-intent.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ The `QuoteIntent` endpoint allows you to request a quote for a cross-chain inten
2525
- **destinationTokenAddress** (string): Contract address of the destination token
2626
- **destinationToAddress** (string): Recipient address on the destination chain
2727

28+
2829
### Optional Fields
2930

31+
- **tradeType** (TradeType): Either `EXACT_INPUT` or `EXACT_OUTPUT`
32+
- **destinationTokenAmount** (number): Amount of destination tokens (only for EXACT_OUTPUT)
33+
- **originTokenAmount** (number): Amount of origin tokens (only for EXACT_INPUT)
3034
- **destinationCallData** (string): Custom calldata for contract interactions on destination chain
3135
- **destinationCallValue** (string): Value to send with the destination call
32-
- **originTokenAmount** (number): Amount of origin tokens (for EXACT_INPUT)
33-
- **destinationTokenAmount** (number): Amount of destination tokens (for EXACT_OUTPUT)
34-
- **tradeType** (TradeType): Either `EXACT_INPUT` or `EXACT_OUTPUT`
3536
- **options** (QuoteIntentRequestOptions):
3637
- **quoteProvider** (QuoteProviderType): Preferred quote provider (`RELAY`, `CCTPV2`, or `LIFI`)
3738
- **slippageTolerance** (number): Maximum acceptable slippage percentage
@@ -73,7 +74,7 @@ const quoteRequest = {
7374
}
7475
};
7576

76-
const response = await fetch('https://api.trails.sequence.app/rpc/Trails/QuoteIntent', {
77+
const response = await fetch('https://trails-api.sequence.app/rpc/Trails/QuoteIntent', {
7778
method: 'POST',
7879
headers: {
7980
'Content-Type': 'application/json',

api-reference/endpoints/search-intents.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Each intent in the array contains all the standard intent fields as described in
3939
Find all intents created by a specific wallet:
4040

4141
```typescript
42-
const searchResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/SearchIntents', {
42+
const searchResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/SearchIntents', {
4343
method: 'POST',
4444
headers: {
4545
'Content-Type': 'application/json',
@@ -63,7 +63,7 @@ intents.forEach(intent => {
6363
Look up an intent using its deposit transaction:
6464

6565
```typescript
66-
const searchResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/SearchIntents', {
66+
const searchResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/SearchIntents', {
6767
method: 'POST',
6868
headers: {
6969
'Content-Type': 'application/json',
@@ -89,7 +89,7 @@ if (intents.length > 0) {
8989
Find all intents using a specific intent contract:
9090

9191
```typescript
92-
const searchResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/SearchIntents', {
92+
const searchResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/SearchIntents', {
9393
method: 'POST',
9494
headers: {
9595
'Content-Type': 'application/json',
@@ -110,7 +110,7 @@ Create a user-friendly transaction history:
110110

111111
```typescript
112112
async function getTransactionHistory(userAddress: string) {
113-
const { intents } = await fetch('https://api.trails.sequence.app/rpc/Trails/SearchIntents', {
113+
const { intents } = await fetch('https://trails-api.sequence.app/rpc/Trails/SearchIntents', {
114114
method: 'POST',
115115
headers: {
116116
'Content-Type': 'application/json',
@@ -157,7 +157,7 @@ function IntentHistory({ userAddress }: { userAddress: string }) {
157157
async function loadIntents() {
158158
try {
159159
const response = await fetch(
160-
'https://api.trails.sequence.app/rpc/Trails/SearchIntents',
160+
'https://trails-api.sequence.app/rpc/Trails/SearchIntents',
161161
{
162162
method: 'POST',
163163
headers: {

api-reference/endpoints/wait-intent-receipt.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ This endpoint will:
4343

4444
```typescript
4545
async function waitForCompletion(intentId: string) {
46-
const response = await fetch('https://api.trails.sequence.app/rpc/Trails/WaitIntentReceipt', {
46+
const response = await fetch('https://trails-api.sequence.app/rpc/Trails/WaitIntentReceipt', {
4747
method: 'POST',
4848
headers: {
4949
'Content-Type': 'application/json',
@@ -122,7 +122,7 @@ async function waitWithProgress(intentId: string, onProgress?: (status: string)
122122

123123
const wait = async (): Promise<IntentReceipt> => {
124124
const { intentReceipt, done } = await fetch(
125-
'https://api.trails.sequence.app/rpc/Trails/WaitIntentReceipt',
125+
'https://trails-api.sequence.app/rpc/Trails/WaitIntentReceipt',
126126
{
127127
method: 'POST',
128128
headers: {
@@ -170,7 +170,7 @@ async function waitWithTimeout(intentId: string, timeoutMs = 300000) {
170170

171171
while (!done) {
172172
const response = await fetch(
173-
'https://api.trails.sequence.app/rpc/Trails/WaitIntentReceipt',
173+
'https://trails-api.sequence.app/rpc/Trails/WaitIntentReceipt',
174174
{
175175
method: 'POST',
176176
headers: {

api-reference/introduction.mdx

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ description: "Learn how to integrate the Trails API for cross-chain transactions
55

66
## Welcome to the Trails API
77

8-
The Trails API enables seamless cross-chain token swaps, bridges, and payments. This guide walks you through the complete flow from requesting a quote to executing a transaction.
8+
The Trails API enables seamless cross-chain token swaps, deposits, payments, and smart contract executions. This guide walks you through the complete flow from requesting a quote to executing a transaction.
99

1010
## Core Workflow
1111

12-
Every cross-chain transaction follows this four-step process:
12+
Every interaction through Trails follows this four-step process:
1313

1414
```mermaid
1515
flowchart LR
@@ -23,14 +23,13 @@ flowchart LR
2323
Request a quote to see rates, fees, and routing options for your transaction.
2424

2525
```typescript
26-
const quoteResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/QuoteIntent', {
26+
const quoteResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/QuoteIntent', {
2727
method: 'POST',
2828
headers: {
2929
'Content-Type': 'application/json',
30-
'X-Access-Key': 'YOUR_ACCESS_KEY'
3130
},
3231
body: JSON.stringify({
33-
ownerAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
32+
ownerAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb', // sender address
3433
originChainId: 1, // Ethereum
3534
originTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
3635
originTokenAmount: 100000000, // 100 USDC (6 decimals)
@@ -57,7 +56,7 @@ console.log('Quote received:', {
5756

5857
**Key Parameters:**
5958

60-
- **ownerAddress**: Your wallet address
59+
- **ownerAddress**: User's sender address
6160
- **originChainId** & **destinationChainId**: Source and destination chains
6261
- **originTokenAddress** & **destinationTokenAddress**: Token contracts
6362
- **originTokenAmount**: Amount to swap (in token's smallest unit)
@@ -69,14 +68,13 @@ Use `EXACT_INPUT` when you know how much you want to spend, and `EXACT_OUTPUT` w
6968

7069
### Step 2: Commit the Intent
7170

72-
Lock in the quote by committing the intent. This reserves the rates and generates an intent ID.
71+
Lock in the quote by committing the intent from the previous response which will reserve the rates.
7372

7473
```typescript
75-
const commitResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/CommitIntent', {
74+
const commitResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/CommitIntent', {
7675
method: 'POST',
7776
headers: {
7877
'Content-Type': 'application/json',
79-
'X-Access-Key': 'YOUR_ACCESS_KEY'
8078
},
8179
body: JSON.stringify({ intent })
8280
});
@@ -99,24 +97,23 @@ Now we can execute the intent. First, send tokens to the intent address then cal
9997
const depositTx = await walletClient.sendTransaction({
10098
to: intent.depositTransaction.toAddress,
10199
value: 0n,
102-
data: encodeERC20Transfer(
100+
data: encodeERC20Transfer( // Use your favorite library such as viem to encode if ERC20 transfer
103101
intent.depositTransaction.tokenAddress,
104102
intent.depositTransaction.toAddress,
105103
intent.depositTransaction.amount
106104
)
107105
});
108106

109-
// Wait for transaction confirmation
107+
// Wait for transaction confirmation using viem
110108
const receipt = await publicClient.waitForTransactionReceipt({
111109
hash: depositTx
112110
});
113111

114-
// Then execute the intent
115-
const executeResponse = await fetch('https://api.trails.sequence.app/rpc/Trails/ExecuteIntent', {
112+
// Then execute the intent with the deposit transaction hash and intentId
113+
const executeResponse = await fetch('https://trails-api.sequence.app/rpc/Trails/ExecuteIntent', {
116114
method: 'POST',
117115
headers: {
118116
'Content-Type': 'application/json',
119-
'X-Access-Key': 'YOUR_ACCESS_KEY'
120117
},
121118
body: JSON.stringify({
122119
intentId,
@@ -130,51 +127,50 @@ console.log('Execution started:', intentStatus);
130127

131128
### Step 4: Monitor Completion
132129

133-
Track the transaction status via polling:
130+
Wait for the transaction to complete using the streaming endpoint:
134131

135132
```typescript
136-
async function pollForCompletion(intentId: string) {
133+
async function waitForCompletion(intentId: string) {
137134
while (true) {
138-
const receiptResponse = await fetch(
139-
'https://api.trails.sequence.app/rpc/Trails/GetIntentReceipt',
135+
const waitResponse = await fetch(
136+
'https://trails-api.sequence.app/rpc/Trails/WaitIntentReceipt',
140137
{
141138
method: 'POST',
142139
headers: {
143140
'Content-Type': 'application/json',
144-
'X-Access-Key': 'YOUR_ACCESS_KEY'
145141
},
146142
body: JSON.stringify({ intentId })
147143
}
148144
);
149145

150-
const { intentReceipt } = await receiptResponse.json();
146+
const { intentReceipt, done } = await waitResponse.json();
151147

152148
console.log('Status:', intentReceipt.status);
153149

154-
if (intentReceipt.status === 'SUCCEEDED') {
155-
console.log('✅ Transaction completed!');
156-
console.log('Deposit TX:', intentReceipt.depositTransaction.txnHash);
157-
console.log('Origin TX:', intentReceipt.originTransaction.txnHash);
158-
console.log('Destination TX:', intentReceipt.destinationTransaction.txnHash);
159-
return intentReceipt;
160-
}
161-
162-
if (intentReceipt.status === 'FAILED') {
163-
throw new Error('Transaction failed: ' + intentReceipt.originTransaction.statusReason);
150+
// If done is true, the intent has reached a terminal state
151+
if (done) {
152+
if (intentReceipt.status === 'SUCCEEDED') {
153+
console.log('✅ Transaction completed!');
154+
console.log('Deposit TX:', intentReceipt.depositTransaction.txnHash);
155+
console.log('Origin TX:', intentReceipt.originTransaction.txnHash);
156+
console.log('Destination TX:', intentReceipt.destinationTransaction.txnHash);
157+
return intentReceipt;
158+
} else {
159+
throw new Error('Transaction failed: ' + intentReceipt.originTransaction.statusReason);
160+
}
164161
}
165-
166-
// Wait 2 seconds before next poll
167-
await new Promise(resolve => setTimeout(resolve, 2000));
162+
163+
// If not done, the endpoint will have waited internally before returning until completion
168164
}
169165
}
170166

171-
const receipt = await pollForCompletion(intentId);
167+
const receipt = await waitForCompletion(intentId);
172168
```
173169

174170
## Support
175171

176172
Need help? Join our community:
177173

178174
- **Telegram**: [https://t.me/build_with_trails](https://t.me/build_with_trails)
179-
- **Documentation**: Browse the endpoint references for detailed information
175+
- **Documentation**: Browse the endpoint references for detailed information and advanced use cases
180176
- **Demo**: Try the [interactive playground](https://demo.trails.build/widget)

0 commit comments

Comments
 (0)