Skip to content

Commit da82426

Browse files
committed
add api snippets to explorer section
1 parent b8f4966 commit da82426

File tree

3 files changed

+108
-7
lines changed

3 files changed

+108
-7
lines changed

apps/dashboard/src/@/components/blocks/code/code-segment.client.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export type CodeEnvironment =
1010
| "typescript"
1111
| "react"
1212
| "react-native"
13-
| "unity";
13+
| "unity"
14+
| "api";
1415

1516
type SupportedEnvironment = {
1617
environment: CodeEnvironment;
@@ -36,6 +37,10 @@ const Environments: SupportedEnvironment[] = [
3637
environment: "react-native",
3738
title: "React Native",
3839
},
40+
{
41+
environment: "api",
42+
title: "API",
43+
},
3944
{
4045
environment: "unity",
4146
title: "Unity",
@@ -124,7 +129,9 @@ export const CodeSegment: React.FC<CodeSegmentProps> = ({
124129
? "tsx"
125130
: activeEnvironment === "unity"
126131
? "cpp"
127-
: activeEnvironment
132+
: activeEnvironment === "api"
133+
? "bash"
134+
: activeEnvironment
128135
}
129136
/>
130137
)}

apps/dashboard/src/@/components/contracts/code-overview.tsx

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ export default function Component() {
6565
events: [preparedEvent]
6666
});
6767
}`,
68+
unity: `using Thirdweb;
69+
70+
// Get your contract
71+
var contract = await ThirdwebManager.Instance.GetContract(
72+
address: "{{contract_address}}",
73+
chainId: {{chainId}},
74+
abi: "optional-abi"
75+
);
76+
77+
// Listen to contract events
78+
var events = await contract.Events("{{function}}");`,
6879
},
6980
install: {
7081
javascript: "npm i thirdweb",
@@ -100,6 +111,17 @@ export default function Component() {
100111
params: [{{args}}]
101112
});
102113
}`,
114+
unity: `using Thirdweb;
115+
116+
// Get your contract
117+
var contract = await ThirdwebManager.Instance.GetContract(
118+
address: "{{contract_address}}",
119+
chainId: {{chainId}},
120+
abi: "optional-abi"
121+
);
122+
123+
// Read from the contract
124+
var result = await contract.Read<T>(contract, "{{function}}", {{args}});`,
103125
},
104126
setup: {
105127
javascript: `import { createThirdwebClient, getContract } from "thirdweb";
@@ -165,11 +187,12 @@ function App() {
165187
`,
166188
unity: `using Thirdweb;
167189
168-
// Reference the SDK
169-
var sdk = ThirdwebManager.Instance.SDK;
170-
171190
// Get your contract
172-
var contract = sdk.GetContract("{{contract_address}}");`,
191+
var contract = await ThirdwebManager.Instance.GetContract(
192+
address: "{{contract_address}}",
193+
chainId: {{chainId}},
194+
abi: "optional-abi"
195+
);`,
173196
},
174197
write: {
175198
javascript: `import { prepareContractCall, sendTransaction } from "thirdweb";
@@ -213,6 +236,58 @@ export default function Component() {
213236
sendTransaction(transaction);
214237
}
215238
}`,
239+
unity: `using Thirdweb;
240+
241+
// Get your contract
242+
var contract = await ThirdwebManager.Instance.GetContract(
243+
address: "{{contract_address}}",
244+
chainId: {{chainId}},
245+
abi: "optional-abi"
246+
);
247+
248+
// Write to the contract
249+
var transactionReceipt = await contract.Write(wallet, contract, "{{function}}", weiValue, {{args}});`,
250+
},
251+
api: {
252+
read: `curl https://api.thirdweb.com/v1/contracts/read \\
253+
--request POST \\
254+
--header 'Content-Type: application/json' \\
255+
--header 'x-client-id: YOUR_CLIENT_ID' \\
256+
# OR use secret key (backend only, not frontend): --header 'x-secret-key: YOUR_SECRET_KEY' \\
257+
--data '{
258+
"calls": [
259+
{
260+
"contractAddress": "{{contract_address}}",
261+
"method": "{{function}}"
262+
}
263+
],
264+
"chainId": {{chainId}}
265+
}'`,
266+
write: `curl -X POST https://api.thirdweb.com/v1/contracts/write \\
267+
-H "Content-Type: application/json" \\
268+
-H "x-secret-key: YOUR_SECRET_KEY" \\
269+
# Note: Secret key should only be used in backend environments, not frontend \\
270+
-d '{
271+
"calls": [
272+
{
273+
"contractAddress": "{{contract_address}}",
274+
"method": "{{function}}",
275+
"params": [{{args}}]
276+
}
277+
],
278+
"chainId": {{chainId}},
279+
"from": "0x1234567890123456789012345678901234567890"
280+
}'`,
281+
events: `curl https://api.thirdweb.com/v1/contracts/events \\
282+
--request POST \\
283+
--header 'Content-Type: application/json' \\
284+
--header 'x-client-id: YOUR_CLIENT_ID' \\
285+
# OR use secret key (backend only, not frontend): --header 'x-secret-key: YOUR_SECRET_KEY' \\
286+
--data '{
287+
"contractAddress": "{{contract_address}}",
288+
"eventName": "{{function}}",
289+
"chainId": {{chainId}}
290+
}'`,
216291
},
217292
};
218293

@@ -490,6 +565,9 @@ export function formatSnippet(
490565
: "event",
491566
});
492567
break;
568+
case "api":
569+
// For API, we don't need special extension handling, just use the standard templates
570+
break;
493571
}
494572
}
495573
// end hacks on hacks on hacks -- now just hacks on hacks from here on out

apps/dashboard/src/@/components/contracts/functions/contract-function.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,30 @@ function ContractFunctionInner(props: ContractFunctionProps) {
112112
: "write"
113113
: ("events" as const);
114114

115-
const codeSnippet = formatSnippet(COMMANDS[commandsKey], {
115+
const baseSnippet = formatSnippet(COMMANDS[commandsKey], {
116116
args: fn.inputs?.map((i) => i.name || ""),
117117
chainId: contract.chain.id,
118118
contractAddress: contract.address,
119119
extensionNamespace,
120120
fn,
121121
});
122122

123+
const apiSnippet = formatSnippet(
124+
{ api: COMMANDS.api[commandsKey] },
125+
{
126+
args: fn.inputs?.map((i) => i.name || ""),
127+
chainId: contract.chain.id,
128+
contractAddress: contract.address,
129+
extensionNamespace,
130+
fn,
131+
},
132+
);
133+
134+
const codeSnippet = {
135+
...baseSnippet,
136+
...apiSnippet,
137+
};
138+
123139
return (
124140
<div className="flex flex-col gap-1.5">
125141
<div className="flex items-center flex-wrap gap-2 border-b pb-3 mb-3">

0 commit comments

Comments
 (0)