Use the Night Elf Extension with Blazor WebAssembly to communicate with the aelf Blockchain
This library provides an easy helper to use aelf with Blazor WebAssembly.
This project was created for the aelf Legend X Hackathon and allows C# developers to use Blazor to create web3 dapps for the aelf Blockchain!
- Install with a single line of C# code
- Easily connect to the Night Elf extension from your C# Blazor WebAssembly App
- Detect if the extension is installed
- Get the user's address and balance
- Call and execute smart contracts
- Get the transaction status
See included Blazor sample app.
Install: AElfBlazor from NuGet
Register in Program.cs:
builder.Services.AddAElfBlazor();Inject the AElfService in your Razor page
@using AElfBlazor
@inject AElfService AElfServiceor class when using a .razor.cs file:
[Inject]
public AElfService AElfService { get; set; } = default!;Use the AElfService:
Check if the user has Night Elf installed:
bool hasExtension = await AElfService.HasNightElfAsync();If the user has the extension installed, initialize the connection:
var nodeUrl = "https://explorer-test.aelf.io/chain";
bool hasExtension = await AElfService.InitializeNightElfAsync("Your App Name", nodeUrl);Check if the user has connected to your site.
bool isSiteConnected = await AElfService.IsConnectedAsync();Initialize a new connection with the extension
await AElfService.LoginAsync();Remove the connection with the extension
await AElfService.LogoutAsync();Get the address from the connected wallet
var address = await AElfService.GetSelectedAddress();Get the balance from the connected wallet
var balance = await AElfService.GetBalanceAsync();Read from or execute smart contracts
var address = "address";
string functionName = "Method";
dynamic payload = new ExpandoObject();
payload.property = "value";
//Read values
var result = await AElfService.ReadSmartContractAsync<MyResultObject>(address, functionName, payload);
//Execute a method and receive a transaction id back:
var txId = await AElfService.ExecuteSmartContractAsync(address, functionName, payload);


