1- import { CodeServer } from "@/components/ui/code/code.server ";
1+ "use client ";
22import { THIRDWEB_ENGINE_CLOUD_URL } from "@/constants/env" ;
33import Link from "next/link" ;
4+ import { useState } from "react" ;
45import { Button } from "../../../../../../../../@/components/ui/button" ;
6+ import { CodeClient } from "../../../../../../../../@/components/ui/code/code.client" ;
7+ import { TabButtons } from "../../../../../../../../@/components/ui/tabs" ;
58import type { Wallet } from "../wallet-table/types" ;
69
710export function TryItOut ( props : {
@@ -10,6 +13,8 @@ export function TryItOut(props: {
1013 team_slug : string ;
1114 project_slug : string ;
1215} ) {
16+ const [ activeTab , setActiveTab ] = useState < string > ( "curl" ) ;
17+
1318 return (
1419 < div className = "flex flex-col gap-6 overflow-hidden rounded-lg border border-border bg-card p-6" >
1520 < div className = "flex flex-row items-center gap-4" >
@@ -25,11 +30,66 @@ export function TryItOut(props: {
2530 </ div >
2631 </ div >
2732 < div >
28- < CodeServer
29- lang = "ts"
30- code = { sendTransactionExample ( ) }
31- className = "bg-background"
33+ < TabButtons
34+ tabs = { [
35+ {
36+ name : "curl" ,
37+ onClick : ( ) => setActiveTab ( "curl" ) ,
38+ isActive : activeTab === "curl" ,
39+ } ,
40+ {
41+ name : "JavaScript" ,
42+ onClick : ( ) => setActiveTab ( "js" ) ,
43+ isActive : activeTab === "js" ,
44+ } ,
45+ {
46+ name : "Python" ,
47+ onClick : ( ) => setActiveTab ( "python" ) ,
48+ isActive : activeTab === "python" ,
49+ } ,
50+ {
51+ name : "Go" ,
52+ onClick : ( ) => setActiveTab ( "go" ) ,
53+ isActive : activeTab === "go" ,
54+ } ,
55+ {
56+ name : "C#" ,
57+ onClick : ( ) => setActiveTab ( "csharp" ) ,
58+ isActive : activeTab === "csharp" ,
59+ } ,
60+ ] }
3261 />
62+
63+ < div className = "h-4" />
64+
65+ { activeTab === "curl" && (
66+ < CodeClient
67+ lang = "bash"
68+ code = { curlExample ( ) }
69+ className = "bg-background"
70+ />
71+ ) }
72+ { activeTab === "js" && (
73+ < CodeClient lang = "js" code = { jsExample ( ) } className = "bg-background" />
74+ ) }
75+ { activeTab === "python" && (
76+ < CodeClient
77+ lang = "python"
78+ code = { pythonExample ( ) }
79+ className = "bg-background"
80+ />
81+ ) }
82+ { activeTab === "go" && (
83+ < CodeClient lang = "go" code = { goExample ( ) } className = "bg-background" />
84+ ) }
85+ { activeTab === "csharp" && (
86+ < CodeClient
87+ lang = "csharp"
88+ code = { csharpExample ( ) }
89+ className = "bg-background"
90+ />
91+ ) }
92+
3393 < div className = "h-4" />
3494 < div className = "flex flex-row justify-end gap-4" >
3595 < Button variant = { "secondary" } asChild >
@@ -56,30 +116,188 @@ export function TryItOut(props: {
56116 ) ;
57117}
58118
59- const sendTransactionExample = ( ) => `\
60- const response = fetch(
61- "${ THIRDWEB_ENGINE_CLOUD_URL } /write/contract",
62- {
63- method: "POST",
64- headers: {
65- "Content-Type": "application/json",
66- "x-secret-key": "<your-project-secret-key>",
67- "x-vault-access-token": "<your-vault-access-token>",
119+ const curlExample = ( ) => `\
120+ curl -X POST "${ THIRDWEB_ENGINE_CLOUD_URL } /write/contract" \\
121+ -H "Content-Type: application/json" \\
122+ -H "x-secret-key: <your-project-secret-key>" \\
123+ -H "x-vault-access-token: <your-vault-access-token>" \\
124+ -d '{
125+ "executionOptions": {
126+ "type": "AA",
127+ "signerAddress": "<your-signer-address>",
128+ "chainId": "84532"
129+ },
130+ "params": [
131+ {
132+ "contractAddress": "0x...",
133+ "method": "function mintTo(address to, uint256 amount)",
134+ "params": ["0x...", "100"]
135+ }
136+ ]
137+ }'` ;
138+
139+ const jsExample = ( ) => `\
140+ const response = await fetch(
141+ "${ THIRDWEB_ENGINE_CLOUD_URL } /write/contract",
142+ {
143+ method: "POST",
144+ headers: {
145+ "Content-Type": "application/json",
146+ "x-secret-key": "<your-project-secret-key>",
147+ "x-vault-access-token": "<your-vault-access-token>"
148+ },
149+ body: JSON.stringify({
150+ "executionOptions": {
151+ "type": "AA",
152+ "signerAddress": "<your-signer-address>",
153+ "chainId": "84532"
154+ },
155+ "params": [
156+ {
157+ "contractAddress": "0x...",
158+ "method": "function mintTo(address to, uint256 amount)",
159+ "params": ["0x...", "100"]
160+ }
161+ ]
162+ })
163+ }
164+ );` ;
165+
166+ const pythonExample = ( ) => `\
167+ import requests
168+ import json
169+
170+ url = "${ THIRDWEB_ENGINE_CLOUD_URL } /write/contract"
171+ headers = {
172+ "Content-Type": "application/json",
173+ "x-secret-key": "<your-project-secret-key>",
174+ "x-vault-access-token": "<your-vault-access-token>"
175+ }
176+ payload = {
177+ "executionOptions": {
178+ "type": "AA",
179+ "signerAddress": "<your-signer-address>",
180+ "chainId": "84532"
181+ },
182+ "params": [
183+ {
184+ "contractAddress": "0x...",
185+ "method": "function mintTo(address to, uint256 amount)",
186+ "params": ["0x...", "100"]
187+ }
188+ ]
189+ }
190+
191+ response = requests.post(url, headers=headers, json=payload)
192+ result = response.json()` ;
68193
69- },
70- body: JSON.stringify({
71- "executionOptions": {
72- "type": "AA",
73- "signerAddress": "<your-signer-address>",
74- "chainId": "84532"
194+ const goExample = ( ) => `\
195+ package main
196+
197+ import (
198+ "bytes"
199+ "encoding/json"
200+ "fmt"
201+ "net/http"
202+ )
203+
204+ func main() {
205+ url := "${ THIRDWEB_ENGINE_CLOUD_URL } /write/contract"
206+
207+ // Create the request payload
208+ type Param struct {
209+ ContractAddress string \`json:"contractAddress"\`
210+ Method string \`json:"method"\`
211+ Params []string \`json:"params"\`
212+ }
213+
214+ type RequestBody struct {
215+ ExecutionOptions struct {
216+ Type string \`json:"type"\`
217+ SignerAddress string \`json:"signerAddress"\`
218+ ChainId string \`json:"chainId"\`
219+ } \`json:"executionOptions"\`
220+ Params []Param \`json:"params"\`
221+ }
222+
223+ requestBody := RequestBody{
224+ Params: []Param{
225+ {
226+ ContractAddress: "0x...",
227+ Method: "function mintTo(address to, uint256 amount)",
228+ Params: []string{"0x...", "100"},
229+ },
230+ },
231+ }
232+ requestBody.ExecutionOptions.Type = "AA"
233+ requestBody.ExecutionOptions.SignerAddress = "<your-signer-address>"
234+ requestBody.ExecutionOptions.ChainId = "84532"
235+
236+ jsonData, _ := json.Marshal(requestBody)
237+
238+ // Create the HTTP request
239+ req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
240+ req.Header.Set("Content-Type", "application/json")
241+ req.Header.Set("x-secret-key", "<your-project-secret-key>")
242+ req.Header.Set("x-vault-access-token", "<your-vault-access-token>")
243+
244+ // Send the request
245+ client := &http.Client{}
246+ resp, err := client.Do(req)
247+ if err != nil {
248+ fmt.Println("Error:", err)
249+ return
250+ }
251+ defer resp.Body.Close()
252+
253+ // Process the response
254+ var result map[string]interface{}
255+ json.NewDecoder(resp.Body).Decode(&result)
256+ fmt.Println("Response:", result)
257+ }` ;
258+
259+ const csharpExample = ( ) => `\
260+ using System;
261+ using System.Net.Http;
262+ using System.Text;
263+ using System.Text.Json;
264+ using System.Threading.Tasks;
265+
266+ class Program
267+ {
268+ static async Task Main()
269+ {
270+ var url = "${ THIRDWEB_ENGINE_CLOUD_URL } /write/contract";
271+
272+ var requestData = new
273+ {
274+ executionOptions = new
275+ {
276+ type = "AA",
277+ signerAddress = "<your-signer-address>",
278+ chainId = "84532"
75279 },
76- "params": [
77- {
78- "contractAddress": "0x...",
79- "method": "function mintTo(address to, uint256 amount)",
80- "params": ["0x...", "100"],
81- },
82- ],
83- }),
280+ @params = new[]
281+ {
282+ new
283+ {
284+ contractAddress = "0x...",
285+ method = "function mintTo(address to, uint256 amount)",
286+ @params = new[] { "0x...", "100" }
287+ }
288+ }
289+ };
290+
291+ var json = JsonSerializer.Serialize(requestData);
292+ var content = new StringContent(json, Encoding.UTF8, "application/json");
293+
294+ using var httpClient = new HttpClient();
295+ httpClient.DefaultRequestHeaders.Add("x-secret-key", "<your-project-secret-key>");
296+ httpClient.DefaultRequestHeaders.Add("x-vault-access-token", "<your-vault-access-token>");
297+
298+ var response = await httpClient.PostAsync(url, content);
299+ var responseContent = await response.Content.ReadAsStringAsync();
300+
301+ Console.WriteLine(responseContent);
84302 }
85- ); `;
303+ } `;
0 commit comments