Skip to content

web3 SDK for Unity - Let's buidl our fine art meta gallery

Notifications You must be signed in to change notification settings

unbanksytv/unity-sdk

 
 

Repository files navigation



thirdweb Unity SDK

Join our Discord!

Best in class Web3 SDK for Unity games

Live Demo


Supported platforms

supported_platforms

Installation

Head over to the releases page and download the latest .unitypackage file.

Drag and drop the file into your project.

The package comes with a sample Scene and Prefab examples showcasing the different capabilities of the SDK.

Note: The Newtonsoft DLL is included as part of the Unity Package, feel free to deselect it if you already have it installed as a dependency to avoid conflicts.

Build

WebGL

  • Open your Build settings, select WebGL as the target platform.
  • Open Player settings > Resolution and Presentation and under WebGLTemplate choose Thirdweb.
  • Use Smaller (faster) Builds in the Build Settings.
  • Save and click Build and Run to test out your game in a browser.

If you're uploading your build, set Compression Format to Disabled in Player Settings > Publishing Settings.

Note that in order to communicate with the SDK on WebGL, you need to Build and run your project so it runs in a browser context.

Other Platforms

  • Requires a ThirdwebManager prefab in your scene.
  • Multiple networks are not supported.
  • Use IL2CPP over Mono when possible in the Player Settings.
  • Using the SDK in the editor (pressing Play) is an accurate reflection of what you can expect to see on native platforms.
  • If building to mobile and running into RPC issues, it is best to run Force Resolve from the Assets menu > External Dependency Manager > Android Resolver > Force Resolve for example.
  • In some cases, setting Managed Stripping Level to minimal when using IL2CPP is also helpful - you can find it under Player Settings > Other Settings > Optimization

Usage

// instantiate a read only SDK on any EVM chain
var sdk = new ThirdwebSDK("goerli");

// connect the user's wallet - supports Metamask, Coinbase Wallet, WalletConnect and more
var walletAddress = await sdk.wallet.Connect();

// interact with the wallet
CurrencyValue balance = await sdk.wallet.GetBalance();
var signature = await sdk.wallet.Sign("message to sign");

// get an instance of a deployed contract (no ABI required!)
var contract = sdk.GetContract("0x...");

// fetch data from any ERC20/721/1155 or marketplace contract
CurrencyValue currencyValue = await contract.ERC20.TotalSupply();
NFT erc721NFT = await contract.ERC721.Get(tokenId);
List<NFT> erc1155NFTs = await contract.ERC1155.GetAll();
List<Listing> listings = await marketplace.GetAllListings();

// execute transactions from the connected wallet
await contract.ERC20.Mint("1.2");
await contract.ERC721.signature.Mint(signedPayload);
await contract.ERC1155.Claim(tokenId, quantity);
await marketplace.BuyListing(listingId, quantity);

// deploy contracts from the connected wallet
var address = await sdk.deployer.DeployNFTCollection(new NFTContractDeployMetadata {
    name = "My Personal Unity Collection",
    primary_sale_recipient = await sdk.wallet.GetAddress(),
});

Prefabs

The Examples folder contains a demo scene using our user-friendly prefabs, check it out!

All Prefabs require the ThirdwebManager prefab to get the SDK Instance, drag and drop it into your scene and select the networks you want to support from the Inspector.

Connect Wallet - All-in-one drag & drop wallet supporting multiple wallet providers, network switching, balance displaying and more!

  • Drag and drop it into your scene.
  • Set up the networks you want to support from the ThirdwebManager prefab.
  • You can add callbacks from the inspector for when the wallet is connected, disconnected, fails to connect or disconnect, as well as callbacks when the network is switched or fails to do so.
  • For native platforms: some wallet providers may not be supported, and multiple networks in the ThirdwebManager is not supported.

NFT Loader - Standalone drag & drop grid/scroll view of NFTs you ask it to display!

  • Go to the prefab's Settings in the Inspector.
  • Load specific NFTs with token ID.
  • Load a specific range of NFTs.
  • Load NFTs owned by a specific wallet.
  • Or any combination of the above - they will all be displayed automatically in a grid view with vertical scroll!
  • Customize the prefab's ScrollView and Content gameobjects if you want your content to behave differently.

NFT - Displays an NFT by calling LoadNFT through script!

  • Instantiate this Prefab through script.
  • Get its Prefab_NFT component.
  • Call the LoadNFT function and pass it your NFT struct to display your fetched NFT's images automatically.
  • Customize the prefab to add text/decorations and customize LoadNFT to use your NFT's metadata if you want to populate that text.
NFT nft = await contract.ERC721.Get(0);
Prefab_NFT nftPrefabScript = Instantiate(nftPrefab);
nftPrefabScript.LoadNFT(nft);

Events - Fetch and manipulate Contract Events with a simple API!

  • Get specific events from any contract.
  • Get all events from any contract.
  • Event listener support with callback actions.
  • Optional query filters.

Reading - Reading from a contract!

  • Fetch ERC20 Token(s).
  • Fetch ERC721 NFT(s).
  • Fetch ERC1155 NFT(s).
  • Fetch Marketplace Listing(s).
  • Fetch Pack contents.

Writing - Writing to a contract!

  • Mint ERC20 Token(s).
  • Mint ERC721 NFT(s).
  • Mint ERC1155 NFT(s).
  • Buy Marketplace Listing(s).
  • Buy a Pack.

Miscellaneous - More examples!

  • Get (Native) Balance.
  • Custom Contract Read/Write Calls.
  • Authentication.
  • Deployment.

See full documentation on the thirdweb portal.

About

web3 SDK for Unity - Let's buidl our fine art meta gallery

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 80.2%
  • C# 17.0%
  • ASP.NET 1.3%
  • Objective-C++ 0.6%
  • ShaderLab 0.6%
  • Objective-C 0.2%
  • Other 0.1%