Skip to content

Commit 64dc55e

Browse files
committed
updated examples
1 parent c1acef0 commit 64dc55e

File tree

5 files changed

+173
-5
lines changed

5 files changed

+173
-5
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Send a Micro Transaction
2+
3+
## Code Example
4+
5+
The following example will:
6+
7+
1. Initialize your wallet
8+
2. Retrieve an account
9+
3. Send your micro transaction!
10+
11+
```cs
12+
public static class SendMicroTransactionExample
13+
{
14+
public static async Task Run()
15+
{
16+
//Register all of the dependencies into a collection of services
17+
IServiceCollection services = new ServiceCollection().AddIotaWalletServices();
18+
19+
//Install services to service provider which is used for dependency injection
20+
IServiceProvider serviceProvider = services.BuildServiceProvider();
21+
22+
//Use serviceprovider to create a scope, which disposes of all services at end of scope
23+
using (IServiceScope scope = serviceProvider.CreateScope())
24+
{
25+
//Request IWallet service from service provider
26+
IWallet wallet = scope.ServiceProvider.GetRequiredService<IWallet>();
27+
28+
//Build wallet using a fluent-style configuration api
29+
wallet = wallet
30+
.ConfigureWalletOptions()
31+
.SetCoinType(TypeOfCoin.Shimmer)
32+
.SetStoragePath("./walletdb")
33+
.Then()
34+
.ConfigureClientOptions()
35+
.AddNodeUrl("https://api.testnet.shimmer.network")
36+
.SetFaucetUrl("https://faucet.testnet.shimmer.network")
37+
.IsFallbackToLocalPow()
38+
.IsLocalPow()
39+
.Then()
40+
.ConfigureSecretManagerOptions()
41+
.SetPassword("password")
42+
.SetSnapshotPath("./mystronghold")
43+
.Then()
44+
.Initialize();
45+
46+
47+
//Let's retrieve our cookiemonster account
48+
(GetAccountResponse accountResponse, IAccount? account) = await wallet.GetAccountAsync("cookiemonster");
49+
Console.WriteLine($"GetAccountAsync: {accountResponse}");
50+
51+
if (account == null)
52+
{
53+
Console.WriteLine("There was a problem retreiving the account.");
54+
return;
55+
}
56+
57+
await account.SyncAccountAsync();
58+
59+
//Let's send 1 Glow, followed by 2 glow, via a single transaction
60+
//The below creates 2 outputs to the receiver address and 1 more output for your balance.
61+
//Since a micro transaction creates dust for the receiver, the sender first pays a temporary storage deposit along with the sending micro amount.
62+
// The receiver now bears the burden of whether to accept this transaction, as if he accepts it he needs to pay storage deposit and the sender's storage deposit
63+
// would be returned back to the sender.
64+
//Thus the receiver is given a choice of whether to acccept this transaction within the stipulated time as indicated
65+
//by [expirationInSeconds].
66+
//[1]If it expired, both the amount sent and storage deposit sent is returned back to the sender.
67+
//[2]If receiver rejects the transaction, both the amount sent and storage deposit sent is returned back to the sender.
68+
//[3]If the receiver accepts the transaction, the sender's storage deposit is returned. In turn, the receiver now has to put in the storage deposit
69+
// to claim the micro amount.
70+
string receiverAddress = "rms1qp8rknypruss89dkqnnuedm87y7xmnmdj2tk3rrpcy3sw3ev52q0vzl42tr";
71+
72+
SendMicroAmountResponse sendMicroAmountResponse = await account.SendMicroAmountUsingBuilder()
73+
.AddAddressAndAmount(receiverAddress, 1, expirationInSeconds:120)
74+
.AddAddressAndAmount(receiverAddress, 2, expirationInSeconds:60)
75+
.SendMicroAmountAsync();
76+
77+
78+
Console.WriteLine($"SendMicroAmountAsync: {sendMicroAmountResponse}");
79+
80+
}
81+
}
82+
83+
84+
}
85+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using IotaWalletNet.Application.AccountContext.Commands.SendMicroAmount;
2+
using IotaWalletNet.Application.Common.Extensions;
3+
using IotaWalletNet.Application.Common.Interfaces;
4+
using IotaWalletNet.Domain.Common.Models.Coin;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using static IotaWalletNet.Application.WalletContext.Queries.GetAccount.GetAccountQueryHandler;
7+
8+
namespace IotaWalletNet.Main.Examples.Outputs_and_Transactions.Send_a_Transaction
9+
{
10+
public static class SendMicroTransactionExample
11+
{
12+
public static async Task Run()
13+
{
14+
//Register all of the dependencies into a collection of services
15+
IServiceCollection services = new ServiceCollection().AddIotaWalletServices();
16+
17+
//Install services to service provider which is used for dependency injection
18+
IServiceProvider serviceProvider = services.BuildServiceProvider();
19+
20+
//Use serviceprovider to create a scope, which disposes of all services at end of scope
21+
using (IServiceScope scope = serviceProvider.CreateScope())
22+
{
23+
//Request IWallet service from service provider
24+
IWallet wallet = scope.ServiceProvider.GetRequiredService<IWallet>();
25+
26+
//Build wallet using a fluent-style configuration api
27+
wallet = wallet
28+
.ConfigureWalletOptions()
29+
.SetCoinType(TypeOfCoin.Shimmer)
30+
.SetStoragePath("./walletdb")
31+
.Then()
32+
.ConfigureClientOptions()
33+
.AddNodeUrl("https://api.testnet.shimmer.network")
34+
.SetFaucetUrl("https://faucet.testnet.shimmer.network")
35+
.IsFallbackToLocalPow()
36+
.IsLocalPow()
37+
.Then()
38+
.ConfigureSecretManagerOptions()
39+
.SetPassword("password")
40+
.SetSnapshotPath("./mystronghold")
41+
.Then()
42+
.Initialize();
43+
44+
45+
//Let's retrieve our cookiemonster account
46+
(GetAccountResponse accountResponse, IAccount? account) = await wallet.GetAccountAsync("cookiemonster");
47+
Console.WriteLine($"GetAccountAsync: {accountResponse}");
48+
49+
if (account == null)
50+
{
51+
Console.WriteLine("There was a problem retreiving the account.");
52+
return;
53+
}
54+
55+
await account.SyncAccountAsync();
56+
57+
//Let's send 1 Glow, followed by 2 glow, via a single transaction
58+
//The below creates 2 outputs to the receiver address and 1 more output for your balance.
59+
//Since a micro transaction creates dust for the receiver, the sender first pays a temporary storage deposit along with the sending micro amount.
60+
// The receiver now bears the burden of whether to accept this transaction, as if he accepts it he needs to pay storage deposit and the sender's storage deposit
61+
// would be returned back to the sender.
62+
//Thus the receiver is given a choice of whether to acccept this transaction within the stipulated time as indicated
63+
//by [expirationInSeconds].
64+
//[1]If it expired, both the amount sent and storage deposit sent is returned back to the sender.
65+
//[2]If receiver rejects the transaction, both the amount sent and storage deposit sent is returned back to the sender.
66+
//[3]If the receiver accepts the transaction, the sender's storage deposit is returned. In turn, the receiver now has to put in the storage deposit
67+
// to claim the micro amount.
68+
string receiverAddress = "rms1qp8rknypruss89dkqnnuedm87y7xmnmdj2tk3rrpcy3sw3ev52q0vzl42tr";
69+
70+
SendMicroAmountResponse sendMicroAmountResponse = await account.SendMicroAmountUsingBuilder()
71+
.AddAddressAndAmount(receiverAddress, 1, expirationInSeconds:120)
72+
.AddAddressAndAmount(receiverAddress, 2, expirationInSeconds:60)
73+
.SendMicroAmountAsync();
74+
75+
76+
Console.WriteLine($"SendMicroAmountAsync: {sendMicroAmountResponse}");
77+
78+
}
79+
}
80+
81+
82+
}
83+
}

csharp/IotaWalletNet/IotaWalletNet.Main/Examples/Outputs and Transactions/Send a Transaction/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ The following example will:
66

77
1. Initialize your wallet
88
2. Retrieve an account
9-
3. Prepare SendAmountCommandMessageData
10-
4. Send your transaction!
9+
3. Send your transaction!
1110

1211
```cs
1312
public static class SendTransactionExample
@@ -63,7 +62,6 @@ The following example will:
6362
SendAmountResponse sendAmountResponse = await account.SendAmountUsingBuilder()
6463
.AddAddressAndAmount(receiverAddress, 1000000)
6564
.AddAddressAndAmount(receiverAddress, 2000000)
66-
.SetTaggedDataPayload(tag: "iotawallet.net", data: "hello world")
6765
.SendAmountAsync();
6866

6967

csharp/IotaWalletNet/IotaWalletNet.Main/Examples/Outputs and Transactions/Send a Transaction/SendTransactionExample.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public static async Task Run()
6262
SendAmountResponse sendAmountResponse = await account.SendAmountUsingBuilder()
6363
.AddAddressAndAmount(receiverAddress, 1000000)
6464
.AddAddressAndAmount(receiverAddress, 2000000)
65-
.SetTaggedDataPayload(tag: "iotawallet.net", data: "hello world")
6665
.SendAmountAsync();
6766

6867

csharp/IotaWalletNet/IotaWalletNet.Main/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ private static async Task Main(string[] args)
1111
//await RequestTokensFromFaucetExample.Run();
1212

1313
//await CheckBalanceExample.Run();
14-
await SendTransactionExample.Run();
1514

15+
//await SendTransactionExample.Run();
16+
17+
await SendMicroTransactionExample.Run();
18+
1619
//await GenerateAnAddressExample.Run();
1720
//await MintNftExample.Run();
1821

0 commit comments

Comments
 (0)