Coder Social home page Coder Social logo

iota-net / iotawallet.net Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 2.0 85.98 MB

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

Home Page: https://iota-net.github.io/iotawalletnet

License: Apache License 2.0

C# 100.00%
iota csharp firefly wallet core net netcore rust shimmer walletrust

iotawallet.net's Introduction

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

[!] Note the following two packages must be installed explicitly, do not skip it. !!! ๐Ÿ˜ก

dotnet add package IotaWallet.Net.Domain --prerelease

Or download from here.

dotnet add package IotaWallet.Net --prerelease

Or download from here.

Architecture support ๐Ÿ˜

It currently supports Windows x64 and Linux x86_64.

Additional Instructions for Linux ๐Ÿ˜ฎ

After installing IotaWallet.Net.Domain, when you build using dotnet build, you would see a file libiota_wallet.so. This is the precompiled rust bindings. You need to add it to your lib path.

Example...

export LD_LIBRARY_PATH=""

Note that its the folder path, not the filepath.

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")
				.Then()
			.ConfigureClientOptions()
				.AddNodeUrl("https://api.testnet.shimmer.network")
				.SetFaucetUrl("https://faucet.testnet.shimmer.network")
				.IsFallbackToLocalPow()
				.IsLocalPow()
				.Then()
			.ConfigureSecretManagerOptions()
				.SetPassword("password")
				.SetSnapshotPath("./mystronghold")
				.Then()
			.Initialize();

		//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.RequestFromFaucetAsync(generatedAddress);
        
		//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, followed by 2 shimmer, which is 2000000 glow, via a single transaction
                //The below creates 2 outputs to the receiver address and 1 more output for your balance.

                string receiverAddress = "rms1qp8rknypruss89dkqnnuedm87y7xmnmdj2tk3rrpcy3sw3ev52q0vzl42tr";

                SendAmountResponse sendAmountResponse = await account.SendAmountUsingBuilder()
                                                                        .AddAddressAndAmount(receiverAddress, 1000000)
                                                                        .AddAddressAndAmount(receiverAddress, 2000000)
                                                                        .SendAmountAsync();


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

Examples ๐Ÿ˜

For more examples, see the Examples directory.

Supported Commands/Queries ๐Ÿ“‘

Wallet

Commands

  • CreateAccount
  • StoreMnemonic
  • VerifyMnemonic

Queries

  • GetAccount
  • GetAccounts
  • GetNewMnemonic

Account

Commands

  • BuildBasicOutput
  • BuildNftOutput
  • BurnNativeTokens
  • BurnNft
  • ClaimOutputs
  • ConsolidateOutputs
  • CreateAliasOutput
  • DestroyFoundry
  • EnablePeriodicSyncing
  • GenerateAddresses
  • MeltNativeTokens
  • MintNativeTokens
  • MintNfts
  • RequestFromFaucet
  • SendAmount
  • SendMicroAmount
  • SendNativeTokens
  • SendNfts
  • SendOutputs
  • SyncAccount

Queries

  • GetAddresses
  • GetAddressesWithUnspentOutputs
  • GetBalance
  • GetFoundryOutput
  • GetMinimumStorageDepositRequired
  • GetOutputs
  • GetPendingTransactions
  • GetTransaction
  • GetTransactions
  • GetUnspentOutputs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.