Skip to content

Commit 067009e

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

File tree

5 files changed

+696
-466
lines changed

5 files changed

+696
-466
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/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">

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

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
UnityIcon,
1818
DotNetIcon,
1919
UnrealEngineIcon,
20+
EngineIcon,
2021
} from "@/icons";
2122
import { ExternalLink } from "lucide-react";
2223

@@ -31,10 +32,19 @@ export const metadata = createMetadata({
3132

3233
# Get Started
3334

34-
Create wallets for your users, authenticate with your backend, connect to external wallets, and more.
35+
Create user or server wallets, authenticate with your backend, connect to external wallets, and more. User wallets can be created using different authentication methods:
3536

36-
<Tabs defaultValue="typescript">
37+
- verification code (email, phone, etc.)
38+
- oauth (google, apple, etc.)
39+
- passkey
40+
- sign in with ethereum
41+
42+
<Tabs defaultValue="http">
3743
<TabsList>
44+
<TabsTrigger value="http" className="flex items-center gap-2 [&>p]:mb-0">
45+
<EngineIcon className="w-4 h-4 mr-2" />
46+
HTTP
47+
</TabsTrigger>
3848
<TabsTrigger value="typescript" className="flex items-center gap-2 [&>p]:mb-0">
3949
<TypeScriptIcon className="w-4 h-4 mr-2" />
4050
TypeScript
@@ -61,6 +71,62 @@ Create wallets for your users, authenticate with your backend, connect to extern
6171
</TabsTrigger>
6272
</TabsList>
6373

74+
<TabsContent value="http">
75+
76+
### API Usage
77+
78+
You can use the [thirdweb API](https://api.thirdweb.com/reference) to create user wallets.
79+
80+
Authentication requires either `x-secret-key` (backend) or `x-client-id` (frontend) to be set in the request headers.
81+
82+
#### Send a login code to the user
83+
84+
```http
85+
POST https://api.thirdweb.com/v1/wallet/user/code
86+
Content-Type: application/json
87+
x-client-id: <your-project-client-id>
88+
89+
{
90+
"type": "email",
91+
"email": "user@example.com"
92+
}
93+
```
94+
95+
#### Verify the code and authenticate the user
96+
97+
```http
98+
POST https://api.thirdweb.com/v1/wallet/user/code/verify
99+
Content-Type: application/json
100+
x-client-id: <your-project-client-id>
101+
102+
{
103+
"type": "email",
104+
"email": "user@example.com",
105+
"code": "123456",
106+
}
107+
```
108+
109+
Once authenticated, the endpoint will return the wallet address and a JWT token for usage with the rest of the API.
110+
111+
</TabsContent>
112+
113+
<TabsContent value="server">
114+
You can create a server wallet with your project secret key and an identifier for the wallet:
115+
116+
```http
117+
POST https://api.thirdweb.com/v1/wallet/server
118+
Content-Type: application/json
119+
x-secret-key: <your-project-secret-key>
120+
121+
{
122+
"identifier": "treasury-wallet", // your identifier
123+
}
124+
```
125+
126+
This will return the server wallet address to use with the rest of the API. If the wallet already exists, the same wallet will be returned.
127+
128+
</TabsContent>
129+
64130
<TabsContent value="typescript">
65131
### Installation
66132

apps/portal/src/app/wallets/server/page.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ Server wallets are wallets that are managed by your own application, like a trea
3232

3333
### Use an existing Server Wallet
3434

35-
Once created, you can use your server wallet by passing it as the `from` field of the `executionOptions` of the [transactions API](https://engine.thirdweb.com/reference).
35+
Once created, you can use your server wallet by passing it as the `from` field of the [thirdweb API](https://api.thirdweb.com/reference#tag/transactions/post/v1/transactions).
3636

3737
### Create a new Server Wallet Programmatically
3838

3939
```http
40-
POST /v1/accounts
40+
POST https://api.thirdweb.com/v1/wallets/server
4141
Content-Type: application/json
4242
x-secret-key: <your-project-secret-key>
4343
4444
{
45-
"label": "My Server Wallet"
45+
"identifier": "My Server Wallet"
4646
}
4747
```
4848

4949
### List all Server Wallets
5050

5151
```http
52-
GET /v1/accounts
52+
GET https://api.thirdweb.com/v1/wallets/server
5353
Content-Type: application/json
5454
x-secret-key: <your-project-secret-key>
5555
```

0 commit comments

Comments
 (0)