Skip to main content

Unity

Integrate Ethereum blockchain features into Unity games. Nethereum provides Unity-compatible libraries that work with both the async Web3 API (preferred) and Unity's coroutine model, supporting WebGL browser wallet connectivity via EIP-6963 multi-wallet discovery.

Getting Started

Install via OpenUPM by adding to your Packages/manifest.json:

{
"scopedRegistries": [
{
"name": "package.openupm.com",
"url": "https://package.openupm.com",
"scopes": ["com.nethereum.unity"]
}
],
"dependencies": {
"com.nethereum.unity": "5.0.0",
"com.unity.nuget.newtonsoft-json": "3.2.1"
}
}

Package source: https://github.com/Nethereum/Nethereum.Unity

The Simple Path

Once installed, use the standard Web3 API — the same API available in any .NET application:

var web3 = new Web3(new UnityWebRequestRpcTaskClient(new Uri(url)));
var blockNumber = await web3.Eth.Blocks.GetBlockNumber.SendRequestAsync();
TaskSimple Path
Query block numberweb3.Eth.Blocks.GetBlockNumber.SendRequestAsync()
Get ETH balanceweb3.Eth.GetBalance.SendRequestAsync(address)
Send ETHweb3.Eth.GetEtherTransferService().TransferEtherAndWaitForReceiptAsync(to, amount)
ERC-20 balanceweb3.Eth.ERC20.GetContractService(addr).BalanceOfQueryAsync(owner)
Connect wallet (WebGL)EIP6963WebglHostProvider.CreateOrGetCurrentInstance()
Deploy contractweb3.Eth.GetContractDeploymentHandler<T>().SendRequestAndWaitForReceiptAsync(deployment)

Nethereum handles gas estimation, nonce management, EIP-1559 fee calculation, and transaction signing automatically. You only override when you need to.

Cross-Platform Architecture

Unity games typically need to work on both desktop (private key signing) and WebGL (browser wallet signing). Use conditional compilation:

#if UNITY_WEBGL
var walletProvider = EIP6963WebglHostProvider.CreateOrGetCurrentInstance();
await walletProvider.EnableProviderAsync();
var web3 = await walletProvider.GetWeb3Async();
#else
var account = new Account(privateKey, chainId);
var web3 = new Web3(account, url);
#endif

Once you have a Web3 instance, all web3.Eth.* calls work identically regardless of platform.

Guides

Getting Started

GuideWhat You'll Learn
QuickstartInstall Nethereum, query blocks, send ETH, and set up cross-platform architecture
WebGL Wallet ConnectionConnect browser wallets via EIP-6963 and MetaMask in WebGL builds

Smart Contracts & Code Sharing

GuideWhat You'll Learn
Smart Contracts & ERC-20Deploy contracts, transfer tokens, query balances, decode events, and control fee estimation
Code Generation & Shared ProjectsGenerate typed C# contract services from Solidity and share code between Unity and .NET test projects

Packages

PackageDescription
Nethereum.UnityCore Unity integration: async RPC client, coroutine wrappers, fee strategies, IPFS utilities
Nethereum.Unity.EIP6963EIP-6963 multi-wallet discovery for Unity WebGL
Nethereum.Unity.MetamaskMetaMask integration for Unity WebGL

Platform Support

PlatformWallet ConnectionSigning
WebGLEIP-6963 (all wallets), MetaMaskBrowser wallet signs
Windows / macOS / LinuxRPC endpointPrivate key
Android / iOSRPC endpointPrivate key

Resources