Skip to content

Commit 438027a

Browse files
[Docs] Replace custom API endpoint with OpenAPI component (#7829)
Co-authored-by: 0xFirekeeper <[email protected]>
1 parent 66c7df9 commit 438027a

File tree

37 files changed

+1466
-1006
lines changed

37 files changed

+1466
-1006
lines changed

apps/playground-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"next": "15.3.5",
2323
"next-themes": "^0.4.6",
2424
"nextjs-toploader": "^1.6.12",
25-
"openapi-types": "^12.1.3",
25+
"openapi-types": "12.1.3",
2626
"posthog-js": "1.256.1",
2727
"prettier": "3.6.2",
2828
"react": "19.1.0",

apps/portal/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"nextjs-toploader": "^1.6.12",
2525
"node-html-markdown": "^1.3.0",
2626
"node-html-parser": "^6.1.13",
27+
"openapi-types": "12.1.3",
2728
"posthog-js": "1.256.1",
2829
"prettier": "3.6.2",
2930
"react": "19.1.0",

apps/portal/src/app/ai/chat/EndpointMetadata.tsx

Lines changed: 0 additions & 91 deletions
This file was deleted.

apps/portal/src/app/ai/chat/page.mdx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
import { EndpointMetadata } from "./EndpointMetadata";
2-
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@doc";
1+
import { Tabs, TabsContent, TabsList, TabsTrigger, OpenApiEndpoint } from "@doc";
32

43
# Chat API
54

6-
The thirdweb AI chat API is a standard OpenAI-compatible chat completion API that allows you to interact with the thirdweb AI model, specialized for blockchain interactions.
7-
8-
The thirdweb proprietary model is optimized for blockchain interactions and can:
5+
The thirdweb AI chat API is a standard OpenAI-compatible chat completion API that allows you to interact with the thirdweb AI model, optimized for blockchain interactions.
96

107
- Query real-time data from the blockchain
118
- Analyze transactions
129
- Fetch token balances, prices and metadata
1310
- Prepare any contract call or transaction for signing
14-
- Prepare swaps from any token pair
11+
- Prepare swaps from/to any token pair
1512
- Deploy contracts
1613
- Generate images
17-
- Search the web for information
14+
- Search the web
1815
- And more!
1916

20-
You can use the API with the API directly, or with any OpenAI-compatible client library.
17+
You can use the API with the HTTP API directly, or with any OpenAI-compatible client library.
2118

2219
<Tabs defaultValue="api">
2320
<TabsList>
2421
<TabsTrigger value="api">HTTP API</TabsTrigger>
2522
<TabsTrigger value="openai">OpenAI Client</TabsTrigger>
2623
</TabsList>
2724
<TabsContent value="api">
28-
<EndpointMetadata />
25+
<OpenApiEndpoint path="/ai/chat" method="POST" specUrl="https://api.thirdweb-dev.com/openapi.json" />
2926
</TabsContent>
3027
<TabsContent value="openai">
3128

@@ -50,4 +47,9 @@ chat_completion = client.chat.completions.create(
5047
print(chat_completion)
5148
```
5249
</TabsContent>
53-
</Tabs>
50+
</Tabs>
51+
52+
### Going further
53+
54+
- [Handle streaming responses](/ai/chat/streaming)
55+
- [Full API Reference](https://api.thirdweb-dev.com/reference#tag/ai/post/ai/chat)
File renamed without changes.

apps/portal/src/app/ai/sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export const sidebar: SideBar = {
1313
icon: <ZapIcon />,
1414
},
1515
{
16-
name: "Response Handling",
17-
href: "/ai/chat/handling-responses",
16+
name: "Streaming Responses",
17+
href: "/ai/chat/streaming",
1818
},
1919
{
2020
name: "API Reference",
Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
import { OpenApiEndpoint, createMetadata } from "@doc";
2+
3+
export const metadata = createMetadata({
4+
image: {
5+
title: "Deploy contracts",
6+
icon: "contracts",
7+
},
8+
title: "Deploy Contracts",
9+
description: "Deploy contracts on any EVM chain.",
10+
});
11+
112
# Deploy Contracts
213

314
You can deploy contracts via CLI or programatically.
@@ -16,8 +27,6 @@ You can also publish your contract to be deployable by anyone on any chain.
1627
npx thirdweb publish -k <project-secret-key>
1728
```
1829

19-
20-
2130
## Deploying via SDK
2231

2332
You can deploy contracts from ABI and bytecode.
@@ -26,15 +35,15 @@ You can deploy contracts from ABI and bytecode.
2635
import { deployContract } from "thirdweb/deploys";
2736

2837
const address = await deployContract({
29-
client,
30-
chain,
31-
bytecode: "0x...",
32-
abi: contractAbi,
33-
constructorParams: {
34-
param1: "value1",
35-
param2: 123,
36-
},
37-
salt, // optional: salt enables deterministic deploys
38+
client,
39+
chain,
40+
bytecode: "0x...",
41+
abi: contractAbi,
42+
constructorParams: {
43+
param1: "value1",
44+
param2: 123,
45+
},
46+
salt, // optional: salt enables deterministic deploys
3847
});
3948
```
4049

@@ -44,14 +53,26 @@ Or alternatively, you can deploy a contract from a previously published contract
4453
import { deployPublishedContract } from "thirdweb/deploys";
4554

4655
const address = await deployPublishedContract({
47-
client,
48-
chain,
49-
account,
50-
contractId: "MyPublishedContract",
51-
contractParams: {
52-
param1: "value1",
53-
param2: 123,
54-
},
55-
publisher: "0x...", // optional, defaults to the thirdweb deployer
56+
client,
57+
chain,
58+
account,
59+
contractId: "MyPublishedContract",
60+
contractParams: {
61+
param1: "value1",
62+
param2: 123,
63+
},
64+
publisher: "0x...", // optional, defaults to the thirdweb deployer
5665
});
57-
```
66+
```
67+
68+
## Deploy via API
69+
70+
You can also deploy contracts via API by passing the contract bytecode and ABI. This will automatically verify the contract on block explorers and add it to your project dashboard.
71+
72+
<OpenApiEndpoint path="/v1/contracts" method="POST" />
73+
74+
## List all deployed contracts
75+
76+
You can list all deployed contracts for your project.
77+
78+
<OpenApiEndpoint path="/v1/contracts" method="GET" />

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
TabsList,
44
TabsTrigger,
55
TabsContent,
6+
OpenApiEndpoint,
67
} from "@doc";
78
import {
89
ReactIcon,
@@ -31,27 +32,7 @@ Query and listen to contract events for any deployed contract on any EVM chain.
3132
</TabsList>
3233

3334
<TabsContent value="http">
34-
### Get Contract Events
35-
36-
You can fetch contract events using the [contract events API](https://api.thirdweb.com/reference#tag/contracts/get/v1/contracts/{address}/events).
37-
38-
```http
39-
GET /v1/contracts/{address}/events?chainId=<chain_id>&decode=true
40-
Host: api.thirdweb.com
41-
x-secret-key: <project-secret-key>
42-
```
43-
44-
Authentication requires either `x-secret-key` (backend) or `x-client-id` (frontend) to be set in the request headers.
45-
46-
#### Parameters
47-
48-
- `address` - The contract address
49-
- `chainId` - The chain ID where the contract is deployed
50-
- `decode` - Whether to decode the event data (optional, defaults to false)
51-
52-
#### Response
53-
54-
The API returns a list of events that have been emitted by the specified contract, including event details and decoded function calls when `decode=true` is specified.
35+
<OpenApiEndpoint path="/v1/contracts/{chainId}/{address}/events" method="GET" />
5536

5637
</TabsContent>
5738

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

Lines changed: 7 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
TabsList,
1111
TabsTrigger,
1212
TabsContent,
13+
OpenApiEndpoint,
1314
} from "@doc";
1415
import {
1516
ReactIcon,
@@ -67,89 +68,18 @@ Read, write, and deploy smart contracts on any EVM compatible blockchain.
6768
</TabsList>
6869

6970
<TabsContent value="http">
70-
### Read a Contract
71-
72-
You can read contract data efficiently using the [contract read API](https://api.thirdweb.com/reference#tag/contracts/post/v1/contracts/read).
73-
74-
```http
75-
GET /v1/contracts/read
76-
Host: api.thirdweb.com
77-
Content-Type: application/json
78-
x-client-id: <your-project-client-id>
79-
80-
{
81-
"chainId": "1" // your chain id
82-
"calls": [{
83-
"contractAddress": "0x...",
84-
"method": "function allowance(address owner, address spender)",
85-
"params": ["0x...", "0x..."],
86-
}],
87-
}
88-
```
8971

90-
You can batch multiple contract reads in a single request, and the response will be an array of results or errors.
72+
### Read from Contracts
9173

92-
Authentication requires either `x-secret-key` (backend) or `x-client-id` (frontend) to be set in the request headers.
74+
You can efficiently read data from multiple functions or contracts in a single request.
9375

94-
### Write to a Contract
76+
<OpenApiEndpoint path="/v1/contracts/read" method="POST" />
9577

96-
You can write to a contract using the [contract write API](https://api.thirdweb.com/reference#tag/contracts/post/v1/contracts/write).
97-
98-
<Tabs defaultValue="frontend">
99-
<TabsList>
100-
<TabsTrigger value="frontend">Frontend</TabsTrigger>
101-
<TabsTrigger value="backend">Backend</TabsTrigger>
102-
</TabsList>
103-
104-
<TabsContent value="frontend">
78+
### Write to Contracts
10579

106-
On the frontend, use your project client ID and the users's auth token to send a transaction on their behalf.
107-
108-
```http
109-
POST /v1/contracts/write
110-
Host: api.thirdweb.com
111-
Content-Type: application/json
112-
x-client-id: <your-project-client-id>
113-
Authorization: Bearer <user-auth-token>
114-
115-
{
116-
"from": "0x...", // the user wallet address
117-
"chainId": "1" // the chain id
118-
"calls": [{
119-
"contractAddress": "0x...",
120-
"method": "function transfer(address to, uint256 amount)",
121-
"params": ["0x...", "1000000000000000000"],
122-
}],
123-
}
124-
```
125-
126-
</TabsContent>
127-
128-
<TabsContent value="backend">
129-
130-
On the backend, use your project secret key to send a transaction from any of your server wallets.
131-
132-
```http
133-
POST /v1/contracts/write
134-
Host: api.thirdweb.com
135-
Content-Type: application/json
136-
x-secret-key: <your-project-secret-key>
137-
138-
{
139-
"from": "0x...", // your server wallet address
140-
"chainId": "1" // your chain id
141-
"calls": [{
142-
"contractAddress": "0x...",
143-
"method": "function transfer(address to, uint256 amount)",
144-
"params": ["0x...", "1000000000000000000"],
145-
}],
146-
}
147-
```
148-
149-
</TabsContent>
150-
</Tabs>
80+
You can write multiple functions to multiple contracts on the same chain in a single request atomically, which will result in a single transaction for optimal gas efficiency.
15181

152-
You can batch multiple contract writes in a single request, and the transactions will be batched atomically onchain.
82+
<OpenApiEndpoint path="/v1/contracts/write" method="POST" />
15383

15484
</TabsContent>
15585

0 commit comments

Comments
 (0)