Optimism
Pronto para usar isso em produção?
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
Optimism
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
Nethereum is the go-to .NET library for talking to OP Mainnet. It targets .NET Standard 2.0+, so the same code runs across Unity3D games, Xamarin mobile apps, ASP.NET Core services, and Blazor front ends. Because OP Mainnet is an OP Stack rollup that stays byte-for-byte EVM-equivalent with Ethereum L1, the standard JSON-RPC surface Nethereum speaks works unchanged — you simply point it at https://optimism.therpc.io/YOUR_API_KEY (chain ID 10, ETH as the gas token). Add it to a project with dotnet add package Nethereum.Web3.
Nethereum builds against .NET Standard 2.0+, which keeps it compatible with Unity3D, Xamarin, ASP.NET Core, and Blazor — one dependency covers desktop, mobile, web, and game runtimes that need OP Mainnet access. Pull it in from NuGet with dotnet add package Nethereum.Web3.
Create a client by passing the OP Mainnet endpoint URL to new Web3(url) — that single object exposes the full Eth API surface. Every method that touches the network returns a Task, so always await it. With OP Mainnet producing blocks roughly every 2 seconds, calls return quickly, but you should still avoid blocking on .Result or .Wait() in UI or ASP.NET request threads, since that pattern deadlocks the synchronization context.
To work with a deployed contract — say a Velodrome pool or a Synthetix module on OP Mainnet — get a handle from _web3.Eth.GetContract(abi, contractAddress). From there, grab a function with GetFunction(name), then call CallAsync<T>(...) for read-only views (no gas, no signature) and SendTransactionAsync(...) for state-changing writes that submit an ETH-paid transaction to the network.
In an ASP.NET Core app, register EthereumService in the dependency-injection container in Program.cs (or Startup) and let the framework resolve it into your controllers — that keeps one configured OP Mainnet client shared across requests. Wrap each await in a try/catch so a dropped connection or a reverted call surfaces as a clean BadRequest rather than an unhandled 500.
To watch contract events on OP Mainnet, model the event as a DTO and use GetEvent<TEventDTO>(contractAddress) together with CreateFilterInput() to define which logs to pull. Polling GetFilterChanges returns new matching events as they land — handy for tracking, say, swap or transfer events emitted by a Superchain dApp.
For a Unity3D game integrating OP Mainnet, build the Web3 client once in Start() or Awake() against https://optimism.therpc.io/YOUR_API_KEY and reuse it. Be careful with async void: it is only acceptable on top-level MonoBehaviour entry points like Start() because exceptions inside it cannot be awaited or caught upstream. Keep the real work in Task-returning helper methods and call them from those entry points so errors stay catchable.