Skip to content

michielpost/AElfBlazor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aelf Blazor SDK

aef Blazor SDK

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.

Live Demo

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!

Features

  • 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

How to use

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 AElfService

or 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);

Video

https://vimeo.com/712063828

Screenshots

Initialize the connection Initialize the connection

Interact with the extension Interact with the extension

Easy usage from C#
Easy usage from C#

Reference

About

aelf Blazor SDK

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors