Base
هل أنت مستعد لاستدعاء هذا في الإنتاج؟
الخطة المجانية تغطي المشاريع الشخصية. الدفع حسب الاستخدام يتوسع دون بطاقة.
Base
الخطة المجانية تغطي المشاريع الشخصية. الدفع حسب الاستخدام يتوسع دون بطاقة.
Nethereum is the primary .NET library for talking to Base, the Coinbase-built OP Stack rollup that settles to Ethereum L1. It targets .NET Standard 2.0+, so the same code reaches Base from Unity3D games, Xamarin mobile apps, ASP.NET Core services, and Blazor front-ends. Because Base is a fully EVM-equivalent chain with ETH as its gas token, every Nethereum call you already know from Ethereum works unchanged against https://base.therpc.io/YOUR_API_KEY. Install it with dotnet add package Nethereum.Web3.
Nethereum targets .NET Standard 2.0+ and is compatible with Unity3D, Xamarin, ASP.NET Core, and Blazor, so a single Base integration can serve a game client, a mobile wallet, and a backend API. Add it from NuGet with dotnet add package Nethereum.Web3.
Connect by passing your Base endpoint URL to new Web3("https://base.therpc.io/YOUR_API_KEY"). Every network method on Base is an async Task — GetBalance.SendRequestAsync, TransferEtherAsync, and the rest — so always await them. Avoid blocking on .Result or .Wait(), which can deadlock in ASP.NET and Unity synchronization contexts. With ~2s Base block times, awaited calls return quickly enough for responsive UIs.
To work with a deployed contract on Base — say an Aerodrome pool or a Uniswap router — obtain a handle from _web3.Eth.GetContract(abi, contractAddress). Use GetFunction(name) then CallAsync<T>(...) for read-only views, which cost no gas, and SendTransactionAsync(...) for state-changing writes, which spend ETH for gas. You can verify the contract address and ABI on https://basescan.org before wiring it up.
In ASP.NET Core, register EthereumService in the DI container in Program.cs (or Startup.cs) and let the framework inject it into your controllers, so the Base connection is configured once and reused. Wrap each awaited call in try/catch and return BadRequest(ex.Message) on failure — this keeps a dropped RPC request or an invalid Base address from throwing an unhandled 500.
To watch contract events on Base — for example ERC-20 Transfer logs or a DEX Swap event — define an event DTO and call _web3.Eth.GetEvent<TEventDTO>(contractAddress). Build a filter with CreateFilterInput() and poll with GetFilterChanges, or subscribe to the returned stream. Given Base's ~2s blocks, a short polling interval keeps your log feed close to real time.
For Unity3D games on Base, initialize Web3 once in Start() or Awake() with your https://base.therpc.io/YOUR_API_KEY endpoint. async void is only safe on Unity lifecycle hooks like Start(); for everything else prefer async Task helpers and await them from those hooks, since an unhandled exception in async void cannot be caught and can crash the frame. Base's low fees and ETH gas make it a practical settlement layer for in-game assets and on-chain rewards.