IotaWallet.NET
1.0.0
该钱包利用 IOTA 的官方 wallet.rs 绑定并将其移植到 .Net。
现在.Net 开发者也有机会尝试 IOTA/Shimmer!
dotnet 添加包 IotaWallet.Net.Domain --prerelease
或者从这里下载。
dotnet 添加包 IotaWallet.Net --prerelease
或者从这里下载。
目前支持Windows x64
和Linux x86_64
。
安装IotaWallet.Net.Domain
后,当您使用dotnet build
进行构建时,您将看到一个文件libiota_wallet.so
。这是预编译的 Rust 绑定。您需要将其添加到您的 lib 路径中。
例子...
导出 LD_LIBRARY_PATH=""
请注意,它是文件夹路径,而不是文件路径。
您可以从 github 存储库本身下载 nuget。查看右侧的Packages
下。
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 } " ) ;
}
有关更多示例,请参阅示例目录。