BNB Smart Chain
C#
Nethereum is the established .NET gateway to BNB Smart Chain. By building against .NET Standard 2.0, it slots into nearly every corner of the ecosystem — Unity3D games, Xamarin mobile apps, ASP.NET Core backends, and Blazor front-ends can all read BNB balances and call BEP-20 contracts on chain 56 through the same API. Pull it into a project with dotnet add package Nethereum.Web3.
That .NET Standard 2.0 baseline is what gives Nethereum its reach across Unity3D, Xamarin, ASP.NET Core, and Blazor without per-platform forks. Installation never varies: dotnet add package Nethereum.Web3 pulls it from NuGet, and from there the connection code to BSC is identical regardless of which host you target.
Nethereum
A single constructor call connects you: new Web3("https://bsc.therpc.io/YOUR_API_KEY") hands you a client bound to BNB Smart Chain. Every I/O operation it exposes returns a Task, so always await your balance reads and transaction sends on chain 56. Resist the temptation to call .Result or .Wait() to make them synchronous: on a context with a synchronization context, like ASP.NET or Unity's main thread, that pattern deadlocks.
- GitHub: https://github.com/Nethereum/Nethereum
- Docs: https://docs.nethereum.com
- Full BNB Smart Chain integration across the .NET stack
- Smart-contract deployment and interaction for BEP-20 and beyond
- HD wallet generation and key management
- Targets Unity3D and Xamarin alongside server runtimes
- Transports for IPC, RPC, and WebSocket connections to chain 56
Smart Contract Integration
Obtain a contract handle by passing the ABI and deployed address to _web3.Eth.GetContract(abi, contractAddress) — for instance to wrap a BEP-20 token on chain 56. From that handle you grab individual functions with GetFunction, then choose the call shape by intent: CallAsync<T> runs a read-only view and decodes the result into your chosen type, while SendTransactionAsync broadcasts a signed state-changing call to BNB Smart Chain.
ASP.NET Integration
In ASP.NET Core, register your EthereumService wrapper with the dependency-injection container in Program.cs (or Startup) so controllers receive it through constructor injection rather than newing up a Web3 per request. Inside each action, guard the awaited BSC call with a try/catch: return the data on success, and on a failure talking to chain 56 translate the exception into a BadRequest with a clear message instead of letting it bubble up as a 500.
Event Handling
To track contract activity on BNB Smart Chain, model the log as a strongly typed event DTO and fetch its handler with GetEvent<TEventDTO>. Build a CreateFilterInput to scope which logs you want — by contract address and block range — and Nethereum decodes each matching entry into your DTO. That turns raw BEP-20 Transfer logs on chain 56 into ordinary C# objects you can query and store.
Unity3D Integration
In a Unity3D project, create your Web3 instance once during Awake() or Start() with the BSC endpoint and hold it on the MonoBehaviour, rather than rebuilding it each frame. Be deliberate about async: async void event handlers swallow exceptions and are hard to cancel when a scene unloads, so prefer Task-returning helper methods and await them from a controlled entry point — invoked out of Start() or marshalled through a coroutine — so chain-56 calls never stall the game loop.