/IotaWallet.NET

Iota or Shimmer Wallet Library focusing on Stardust. For C# CSharp .NET implementation of wallet.rs using rust bindings and P/Invoke

Primary LanguageC#

status

Continuous Integration Deploy to Github NuGet Deploy to NuGet.org

Introduction

This wallet leverages IOTA's official wallet.rs bindings and ports it over to .Net.

Now .Net developers can have a chance trying out IOTA/Shimmer as well!

Installation from Nuget.org

Install-Package IotaWallet.Net.Domain

Or download from here.

Install-Package IotaWallet.Net

Or download from here.

Alternative Installation

You can download the nugets from the github repo itself. Look to your right under Packages.

Usage Example

Setting up your wallet and sending a command

static async Task Main(string[] args)
{
    	//Register all of the dependencies into a collection of services
	IServiceCollection services = new ServiceCollection().AddIotaWalletServices();

	//Install services to service provider which is used for dependency injection
	IServiceProvider serviceProvider = services.BuildServiceProvider();

	//Use serviceprovider to create a scope, which safely disposes of all services at end of scope
	using (IServiceScope scope = serviceProvider.CreateScope())
	{
		//Request IWallet service from service provider
		IWallet wallet = scope.ServiceProvider.GetRequiredService<IWallet>();

		//Build wallet using a fluent-style configuration api
		wallet = wallet
			.ConfigureWalletOptions()
				.SetCoinType(WalletOptions.TypeOfCoin.Shimmer)
				.SetStoragePath("./walletdb")
				.ThenBuild()
			.ConfigureClientOptions()
				.AddNodeUrl("https://api.testnet.shimmer.network")
				.IsFallbackToLocalPow()
				.IsLocalPow()
				.ThenBuild()
			.ConfigureSecretManagerOptions()
				.SetPassword("password")
				.SetSnapshotPath("./mystronghold")
				.ThenBuild()
			.ThenInitialize();

		//Let's generate a Mnemonic
		GetNewMnemonicResponse getNewMnemonicResponse = await wallet.GetNewMnemonicAsync();
		Console.WriteLine($"GetNewMnemonicAsync: {getNewMnemonicResponse}");
		string newMnemonic = getNewMnemonicResponse.Payload;
		
		//Store into stronghold
		//Remember, Generation and storage of mnemonic only is needed to do done the first time!
		StoreMnemonicResponse storeMnemonicResponse = await wallet.StoreMnemonicAsync(newMnemonic);
		Console.WriteLine($"StoreMnemonicAsync: {storeMnemonicResponse}");

		//Let's create an accounts, with username "cookiemonster"
		(CreateAccountResponse createAccountResponse, IAccount? account) = await wallet.CreateAccountAsync("cookiemonster");
		Console.WriteLine($"CreateAccountAsync: {createAccountResponse}");

		if (account == null)
		{
			Console.WriteLine("There was a problem creating the account.");
			return;
		}
		
		//Lets generate 1 new address!
		GenerateAddressesResponse generateAddressesResponse = await account.GenerateAddressesAsync(numberOfAddresses: 1, NetworkType.Testnet);
		Console.WriteLine($"GenerateAddressesAsync: {generateAddressesResponse}");
		string? generatedAddress = generateAddressesResponse.Payload?.FirstOrDefault()?.Address;
			
		//Let's request some Shimmer from the faucet
        	await account.RequestFromFaucet(generatedAddress, @"https://faucet.testnet.shimmer.network");
        
		//Let's Checkout our balance. We will sync the account, followed by checking the balance.
		//Sync the account with the tangle
		await account.SyncAccountAsync();
		//Retrieve balance
		GetBalanceResponse getBalanceResponse = await account.GetBalanceAsync();
		Console.WriteLine($"GetBalanceAsync: {getBalanceResponse}");
		
		//Great, now that we have some test shimmer tokens to send, send to me!
		//Let's send 1 shimmer, which is 1,000,000 Glow
		(string receiverAddress, string amount) = ("rms1qz9f7vecqscfynnxacyzefwvpza0wz3r0lnnwrc8r7qhx65s5x7rx2fln5q", "1000000");
		
		//You can attach as many (address,amount) pairs as you want
		AddressesWithAmountAndTransactionOptions addressesWithAmountAndTransactionOptions = new AddressesWithAmountAndTransactionOptions();
		addressesWithAmountAndTransactionOptions
				.AddAddressAndAmount(receiverAddress, amount);

		//Start sending
		SendAmountResponse sendAmountResponse = await account.SendAmountAsync(addressesWithAmountAndTransactionOptions);

		Console.WriteLine($"SendAmountAsync: {sendAmountResponse}");
}

For more examples, see the Examples directory.

Supported Commands/Queries

Wallet

Commands
CreateAccount
StoreMnemonic
VerifyMnemonic
Queries
GetAccount
GetAccounts
GetNewMnemonic

Account

Commands
BurnNativeTokens
BurnNft
ClaimOutputs
CreateAliasOutput
GenerateAddresses
MeltNativeTokens
MintNativeTokens
MintNfts
RequestFromFaucet
SendAmount
SendNativeTokens
SendNfts
SyncAccount