Use MetaMask with Blazor WebAssembly
Last updated Jan 9, 2026
45
Stars
22
Forks
2
Issues
0
Stars/day
Attention Score
32
Language breakdown
No language data available.
▸ Files
click to expand
README
MetaMask.Blazor
Use MetaMask with Blazor WebAssemblyThis library provides an easy helper to use MetaMask with Blazor WebAssembly.
Real world implementation, login with MetaMask: SkyDocs
How to use
See included Blazor sample app.Install: MetaMask.Blazor on NuGet
Register in Program.cs:
builder.Services.AddMetaMaskBlazor();
Inject the MetaMaskService in your Razor page
@using MetaMask.Blazor @inject IMetaMaskService MetaMaskService
or class when using a .razor.cs file:
[Inject] public IMetaMaskService MetaMaskService { get; set; } = default!;
Use the MetaMaskService:
Check if the user has MetaMask installed:
bool hasMetaMask = await MetaMaskService.HasMetaMask();
Check if the user has previously connected to your site.
bool isSiteConnected = await MetaMaskService.IsSiteConnected();
Initialize a new connection with MetaMask
try { await MetaMaskService.ConnectMetaMask(); } catch (UserDeniedException) { //Handle "User Denied" case; } This can throw exceptions if the user decides to not allow the connection.
Once there is a connection, you can use other method calls like:
GetSelectedAddressGetTransactionCountSignTypedDataSendTransaction- or use the generic RPC method:
GenericRpc
Events
Listen to events:await MetaMaskService.ListenToEvents();
You can subscribe to two events:
IMetaMaskService.AccountChangedEventIMetaMaskService.NetworkChangedEvent
Reference
- https://docs.metamask.io
- https://metamask.io
- Logging in with MetaMask in a Blazor WebAssembly app
Acknowledgements
Development of MetaMask.Blazor has been made possible with a grant from The Graph.🔗 More in this category