|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { |
| 4 | + type CodeEnvironment, |
| 5 | + CodeSegment, |
| 6 | +} from "@/components/blocks/code-segment.client"; |
| 7 | +import { useState } from "react"; |
| 8 | + |
| 9 | +export function SDKSection() { |
| 10 | + const [codeEnvironment, setCodeEnvironment] = |
| 11 | + useState<CodeEnvironment>("javascript"); |
| 12 | + |
| 13 | + return ( |
| 14 | + <div> |
| 15 | + <h2 className="mb-2 font-semibold text-lg tracking-tight"> |
| 16 | + Integrate into your app |
| 17 | + </h2> |
| 18 | + |
| 19 | + <CodeSegment |
| 20 | + snippet={storageSnippets} |
| 21 | + environment={codeEnvironment} |
| 22 | + setEnvironment={setCodeEnvironment} |
| 23 | + /> |
| 24 | + </div> |
| 25 | + ); |
| 26 | +} |
| 27 | + |
| 28 | +const storageSnippets = { |
| 29 | + react: `// Check out the latest docs here: https://portal.thirdweb.com/typescript/v5/storage |
| 30 | +
|
| 31 | +import { ThirdwebProvider } from "thirdweb/react"; |
| 32 | +import { upload } from "thirdweb/storage"; |
| 33 | +import { MediaRenderer } from "thirdweb/react"; |
| 34 | +
|
| 35 | +// Wrap your app in ThirdwebProvider |
| 36 | +function Providers() { |
| 37 | + return ( |
| 38 | + <ThirdwebProvider |
| 39 | + > |
| 40 | + <App /> |
| 41 | + </ThirdwebProvider> |
| 42 | + ); |
| 43 | +} |
| 44 | +
|
| 45 | +function UploadFiles() { |
| 46 | + const uploadData = async () => { |
| 47 | + const uri = await upload({ |
| 48 | + client, // thirdweb client |
| 49 | + files: [ |
| 50 | + new File(["hello world"], "hello.txt"), |
| 51 | + ], |
| 52 | + }); |
| 53 | + } |
| 54 | +
|
| 55 | + return <div> ... </div> |
| 56 | +} |
| 57 | +
|
| 58 | + // Supported types: image, video, audio, 3d model, html |
| 59 | +function ShowFiles() { |
| 60 | + return ( |
| 61 | + <MediaRenderer src="ipfs://QmamvVM5kvsYjQJYs7x8LXKYGFkwtGvuRvqZsuzvpHmQq9/0" /> |
| 62 | + ); |
| 63 | +}`, |
| 64 | + javascript: `// Check out the latest docs here: https://portal.thirdweb.com/typescript/v5/storage |
| 65 | +
|
| 66 | +import { upload } from "thirdweb/storage"; |
| 67 | +
|
| 68 | +// Here we get the IPFS URI of where our metadata has been uploaded |
| 69 | +const uri = await upload({ |
| 70 | + client, |
| 71 | + files: [ |
| 72 | + new File(["hello world"], "hello.txt"), |
| 73 | + ], |
| 74 | +}); |
| 75 | +
|
| 76 | +// This will log a URL like ipfs://QmWgbcjKWCXhaLzMz4gNBxQpAHktQK6MkLvBkKXbsoWEEy/0 |
| 77 | +console.info(uri); |
| 78 | +
|
| 79 | +// Here we a URL with a gateway that we can look at in the browser |
| 80 | +const url = await download({ |
| 81 | + client, |
| 82 | + uri, |
| 83 | +}).url; |
| 84 | +
|
| 85 | +// This will log a URL like https://ipfs.thirdwebstorage.com/ipfs/QmWgbcjKWCXhaLzMz4gNBxQpAHktQK6MkLvBkKXbsoWEEy/0 |
| 86 | +console.info(url);`, |
| 87 | + |
| 88 | + unity: `using Thirdweb; |
| 89 | +
|
| 90 | +// Reference the SDK |
| 91 | +var sdk = ThirdwebManager.Instance.SDK; |
| 92 | +
|
| 93 | +// Create data |
| 94 | +NFTMetadata meta = new NFTMetadata() |
| 95 | +{ |
| 96 | + name = "Unity NFT", |
| 97 | + description = "Minted From Unity", |
| 98 | + image = "ipfs://QmbpciV7R5SSPb6aT9kEBAxoYoXBUsStJkMpxzymV4ZcVc", |
| 99 | +}; |
| 100 | +string metaJson = Newtonsoft.Json.JsonConvert.SerializeObject(meta); |
| 101 | +
|
| 102 | +// Upload raw text or from a file path |
| 103 | +var response = await ThirdwebManager.Instance.SDK.storage.UploadText(metaJson);`, |
| 104 | +}; |
0 commit comments