Skip to content

Commit 31a136d

Browse files
[Docs] Update API endpoints and add frontend/backend examples
1 parent 8260af3 commit 31a136d

File tree

6 files changed

+699
-554
lines changed

6 files changed

+699
-554
lines changed

apps/portal/src/app/contracts/page.mdx

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export const metadata = createMetadata({
3434

3535
Read, write, and deploy smart contracts on any EVM compatible blockchain.
3636

37-
---
38-
3937
<Tabs defaultValue="http">
4038
<TabsList>
4139
<TabsTrigger value="http" className="flex items-center gap-2 [&>p]:mb-0">
@@ -71,19 +69,16 @@ Read, write, and deploy smart contracts on any EVM compatible blockchain.
7169
<TabsContent value="http">
7270
### Read a Contract
7371

74-
You can read contract data efficiently using the [contract read API](https://engine.thirdweb.com/reference).
72+
You can read contract data efficiently using the [contract read API](https://api.thirdweb.com/reference#tag/contracts/post/v1/contracts/read).
7573

7674
```http
77-
GET /v1/contract/read
75+
GET https://api.thirdweb.com/v1/contract/read
7876
Content-Type: application/json
79-
x-secret-key: <your-project-secret-key>
77+
x-client-id: <your-project-client-id>
8078
8179
{
82-
"readOptions": {
83-
"chainId": "1" // your chain id
84-
"from": "0x...", // optional, if you want to read from a specific address
85-
},
86-
"params": [{
80+
"chainId": "1" // your chain id
81+
"calls": [{
8782
"contractAddress": "0x...",
8883
"method": "function allowance(address owner, address spender)",
8984
"params": ["0x...", "0x..."],
@@ -93,33 +88,65 @@ Read, write, and deploy smart contracts on any EVM compatible blockchain.
9388

9489
You can batch multiple contract reads in a single request, and the response will be an array of results or errors.
9590

91+
Authentication requires either `x-secret-key` (backend) or `x-client-id` (frontend) to be set in the request headers.
92+
9693
### Write to a Contract
9794

98-
You can write to a contract using the [contract write API](https://engine.thirdweb.com/reference).
99-
100-
```http
101-
POST /v1/contract/write
102-
Content-Type: application/json
103-
x-secret-key: <your-project-secret-key>
104-
105-
{
106-
"executionOptions": {
107-
"from": "0x...", // your server wallet address
108-
"chainId": "1" // your chain id
109-
},
110-
"params": [{
111-
"contractAddress": "0x...",
112-
"method": "function transfer(address to, uint256 amount)",
113-
"params": ["0x...", "1000000000000000000"],
114-
}]
115-
}
116-
```
95+
You can write to a contract using the [contract write API](https://api.thirdweb.com/reference#tag/contracts/post/v1/contracts/write).
11796

118-
You can batch multiple contract writes in a single request, and the transactions will be batched atomically onchain.
97+
<Tabs defaultValue="frontend">
98+
<TabsList>
99+
<TabsTrigger value="frontend">Frontend</TabsTrigger>
100+
<TabsTrigger value="backend">Backend</TabsTrigger>
101+
</TabsList>
119102

120-
### Deploy a Contract
103+
<TabsContent value="frontend">
104+
105+
On the frontend, use your project client ID and the users's auth token to send a transaction on their behalf.
106+
107+
```http
108+
POST https://api.thirdweb.com/v1/contract/write
109+
Content-Type: application/json
110+
x-client-id: <your-project-client-id>
111+
Authorization: Bearer <user-auth-token>
112+
113+
{
114+
"from": "0x...", // the user wallet address
115+
"chainId": "1" // the chain id
116+
"calls": [{
117+
"contractAddress": "0x...",
118+
"method": "function transfer(address to, uint256 amount)",
119+
"params": ["0x...", "1000000000000000000"],
120+
}],
121+
}
122+
```
123+
124+
</TabsContent>
121125

122-
You can deploy a contract using the [contract deploy API](https://engine.thirdweb.com/reference).
126+
<TabsContent value="backend">
127+
128+
On the backend, use your project secret key to send a transaction from any of your server wallets.
129+
130+
```http
131+
POST https://api.thirdweb.com/v1/contract/write
132+
Content-Type: application/json
133+
x-secret-key: <your-project-secret-key>
134+
135+
{
136+
"from": "0x...", // your server wallet address
137+
"chainId": "1" // your chain id
138+
"calls": [{
139+
"contractAddress": "0x...",
140+
"method": "function transfer(address to, uint256 amount)",
141+
"params": ["0x...", "1000000000000000000"],
142+
}],
143+
}
144+
```
145+
146+
</TabsContent>
147+
</Tabs>
148+
149+
You can batch multiple contract writes in a single request, and the transactions will be batched atomically onchain.
123150

124151
</TabsContent>
125152

apps/portal/src/app/payments/page.mdx

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ thirdweb Payments allow developers to create advanced payment flows to monetize
8484

8585
```typescript
8686
import { Bridge, NATIVE_TOKEN_ADDRESS, toWei } from "thirdweb";
87-
const preparedQuote = await Bridge.Buy.prepare({
87+
88+
// Quote to buy 10 USDC on Optimism, paid with USDT on Arbitrum
89+
const preparedQuote = await Bridge.Buy.prepare({
8890
originChainId: 42161,
8991
originTokenAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", // USDT on Arbitrum
9092
destinationChainId: 10,
@@ -98,93 +100,6 @@ thirdweb Payments allow developers to create advanced payment flows to monetize
98100

99101
The prepared quote will contain details about the payment, including the transactions needed to execute it.
100102

101-
```typescript
102-
{
103-
blockNumber: 359092559n,
104-
destinationAmount: 10000000n,
105-
estimatedExecutionTimeMs: 4000,
106-
intent: {
107-
amount: 10000000n,
108-
destinationChainId: 10,
109-
destinationTokenAddress: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
110-
originChainId: 42161,
111-
originTokenAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
112-
receiver: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
113-
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709"
114-
},
115-
originAmount: 10090837n,
116-
steps: [
117-
{
118-
originToken: {
119-
chainId: 42161,
120-
address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
121-
symbol: "USDT",
122-
name: "Tether USD",
123-
decimals: 6,
124-
priceUsd: 1.000466,
125-
iconUri: "https://coin-images.coingecko.com/coins/images/39963/large/usdt.png?1724952731",
126-
prices: {
127-
USD: 1.000466,
128-
EUR: 0.8609646893353334,
129-
// ...more currencies
130-
}
131-
},
132-
destinationToken: {
133-
chainId: 10,
134-
address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
135-
symbol: "USDC",
136-
name: "USD Coin",
137-
decimals: 6,
138-
priceUsd: 0.999859,
139-
iconUri: "https://ethereum-optimism.github.io/data/USDC/logo.png",
140-
prices: {
141-
USD: 0.999859,
142-
EUR: 0.8604423271896667,
143-
// ...more currencies
144-
}
145-
},
146-
transactions: [
147-
{
148-
chainId: 42161,
149-
to: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
150-
data: "0x095ea7b3000000000000000000000000f8ab2dbe6c43bf1a856471182290f91d621ba76d00000000000000000000000000000000000000000000000000000000009d0695",
151-
type: "eip1559",
152-
id: "0x2354360325ff8315dad5673894207d90c28cb898788025202b6a6f8c2bd8220a",
153-
action: "approval",
154-
chain: {
155-
// ...chain details
156-
},
157-
client: {
158-
clientId: "...",
159-
}
160-
},
161-
{
162-
type: "eip1559",
163-
to: "0xF8Ab2dBE6c43bf1a856471182290f91D621Ba76d",
164-
from: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
165-
value: 0n,
166-
data: "0x...",
167-
chainId: 42161,
168-
action: "buy",
169-
id: "0xc4fd6ecdbbf6fb0780c87779adff09ea7f480fac385b8db4873fc1a0d3309264",
170-
spender: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
171-
chain: {
172-
// ...chain details
173-
},
174-
client: {
175-
clientId: "...",
176-
}
177-
}
178-
],
179-
originAmount: 10090837n,
180-
destinationAmount: 10000000n,
181-
estimatedExecutionTimeMs: 4000
182-
}
183-
],
184-
timestamp: 1752866509083
185-
}
186-
```
187-
188103
You can execute the included transactions using the wallet of your choice. To learn how to send it using thirdweb Wallets, checkout the [Send a Payment](/payments/send) guide.
189104

190105
</TabsContent>

apps/portal/src/app/transactions/page.mdx

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export const metadata = createMetadata({
3434

3535
Send, monitor, and manage transactions. Send transactions from user or server wallets, sponsor gas, monitor transaction status, and more.
3636

37-
---
38-
3937
<Tabs defaultValue="http">
4038
<TabsList>
4139
<TabsTrigger value="http" className="flex items-center gap-2 [&>p]:mb-0">
@@ -69,28 +67,89 @@ Send, monitor, and manage transactions. Send transactions from user or server wa
6967
</TabsList>
7068

7169
<TabsContent value="http">
70+
7271
### Send a Transaction
7372

74-
You can send transactions with your [server wallets](/wallets/server) using the [transactions API](https://engine.thirdweb.com/reference).
73+
Send a transaction from a [user wallet](/wallets/users) from the frontend, or [server wallet](/wallets/server) from the backend using the [thirdweb API](https://api.thirdweb.com/reference#tag/transactions/post/v1/transactions).
74+
75+
Transactions can be of type `contract-call`, `encoded` or `native-transfer`, and will be batched atomically onchain.
76+
77+
<Tabs defaultValue="frontend">
78+
<TabsList>
79+
<TabsTrigger value="frontend">Frontend</TabsTrigger>
80+
<TabsTrigger value="backend">Backend</TabsTrigger>
81+
</TabsList>
82+
83+
<TabsContent value="frontend">
84+
85+
On the frontend, use your project client ID and the users's auth token to send a transaction on their behalf.
86+
87+
```http
88+
POST https://api.thirdweb.com/v1/transactions
89+
Content-Type: application/json
90+
x-client-id: <your-project-client-id>
91+
Authorization: Bearer <user-auth-token>
92+
93+
{
94+
"from": "0x...", // the user wallet address
95+
"chainId": "1" // the chain id
96+
"transactions": [{
97+
// contract call
98+
"type": "contract-call",
99+
"contractAddress": "0x...",
100+
"method": "function transfer(address to, uint256 amount)",
101+
"params": ["0x...", "1000000000000000000"],
102+
}, {
103+
// encoded transaction
104+
"type": "encoded",
105+
"to": "0x...",
106+
"data": "0x...",
107+
}, {
108+
// native transfer
109+
"type": "native-transfer",
110+
"to": "0x...",
111+
"value": "1000000000000000000", // in wei
112+
}],
113+
}
114+
```
115+
116+
</TabsContent>
117+
118+
<TabsContent value="backend">
119+
120+
On the backend, use your project secret key to send a transaction from any of your server wallets.
75121

76-
```http
77-
POST /v1/contract/write
122+
```http
123+
POST https://api.thirdweb.com/v1/contract/write
78124
Content-Type: application/json
79125
x-secret-key: <your-project-secret-key>
80126
81-
{
82-
"executionOptions": {
83-
"from": "0x...", // your server wallet address
84-
"chainId": "1" // your chain id
85-
},
86-
"params": [{
127+
{
128+
"from": "0x...", // the server wallet address
129+
"chainId": "1" // the chain id
130+
"transactions": [{
131+
// contract call
132+
"type": "contract-call",
87133
"contractAddress": "0x...",
88134
"method": "function transfer(address to, uint256 amount)",
89135
"params": ["0x...", "1000000000000000000"],
136+
}, {
137+
// encoded transaction
138+
"type": "encoded",
139+
"to": "0x...",
140+
"data": "0x...",
141+
}, {
142+
// native transfer
143+
"type": "native-transfer",
144+
"to": "0x...",
145+
"value": "1000000000000000000", // in wei
90146
}],
91-
}
147+
}
92148
```
93149

150+
</TabsContent>
151+
</Tabs>
152+
94153
</TabsContent>
95154

96155
<TabsContent value="typescript">

0 commit comments

Comments
 (0)