|
| 1 | +using IotaWalletNet.Application.AccountContext.Commands.BuildBasicOutput; |
| 2 | +using IotaWalletNet.Application.AccountContext.Commands.BuildNftOutput; |
| 3 | +using IotaWalletNet.Application.AccountContext.Commands.SendOutputs; |
| 4 | +using IotaWalletNet.Application.Common.Extensions; |
| 5 | +using IotaWalletNet.Application.Common.Interfaces; |
| 6 | +using IotaWalletNet.Domain.Common.Extensions; |
| 7 | +using IotaWalletNet.Domain.Common.Interfaces; |
| 8 | +using IotaWalletNet.Domain.Common.Models.Address.AddressTypes; |
| 9 | +using IotaWalletNet.Domain.Common.Models.Coin; |
| 10 | +using IotaWalletNet.Domain.Common.Models.Network; |
| 11 | +using IotaWalletNet.Domain.Common.Models.Output.FeatureTypes; |
| 12 | +using IotaWalletNet.Domain.Common.Models.Output.OutputDataTypes; |
| 13 | +using IotaWalletNet.Domain.Common.Models.Output.OutputTypes; |
| 14 | +using IotaWalletNet.Domain.Common.Models.Output.UnlockConditionTypes; |
| 15 | +using Microsoft.Extensions.DependencyInjection; |
| 16 | +using static IotaWalletNet.Application.WalletContext.Queries.GetAccount.GetAccountQueryHandler; |
| 17 | + |
| 18 | +namespace IotaWalletNet.Main.Examples.NFTs.Mint |
| 19 | +{ |
| 20 | + public static class MintNftUsingBuildOutputExample |
| 21 | + { |
| 22 | + public static async Task Run() |
| 23 | + { |
| 24 | + //Register all of the dependencies into a collection of services |
| 25 | + IServiceCollection services = new ServiceCollection().AddIotaWalletServices(); |
| 26 | + |
| 27 | + //Install services to service provider which is used for dependency injection |
| 28 | + IServiceProvider serviceProvider = services.BuildServiceProvider(); |
| 29 | + |
| 30 | + //Use serviceprovider to create a scope, which disposes of all services at end of scope |
| 31 | + using (IServiceScope scope = serviceProvider.CreateScope()) |
| 32 | + { |
| 33 | + //Request IWallet service from service provider |
| 34 | + IWallet wallet = scope.ServiceProvider.GetRequiredService<IWallet>(); |
| 35 | + |
| 36 | + //Build wallet using a fluent-style configuration api |
| 37 | + wallet = wallet |
| 38 | + .ConfigureWalletOptions() |
| 39 | + .SetCoinType(TypeOfCoin.Shimmer) |
| 40 | + .SetStoragePath("./walletdb") |
| 41 | + .Then() |
| 42 | + .ConfigureClientOptions() |
| 43 | + .AddNodeUrl("https://api.testnet.shimmer.network") |
| 44 | + .SetFaucetUrl("https://faucet.testnet.shimmer.network") |
| 45 | + .IsFallbackToLocalPow() |
| 46 | + .IsLocalPow() |
| 47 | + .Then() |
| 48 | + .ConfigureSecretManagerOptions() |
| 49 | + .SetPassword("password") |
| 50 | + .SetSnapshotPath("./mystronghold") |
| 51 | + .Then() |
| 52 | + .Initialize(); |
| 53 | + |
| 54 | + |
| 55 | + //Let's retrieve our cookiemonster account |
| 56 | + (GetAccountResponse accountResponse, IAccount? account) = await wallet.GetAccountAsync("cookiemonster"); |
| 57 | + Console.WriteLine($"GetAccountAsync: {accountResponse}"); |
| 58 | + |
| 59 | + if (account == null) |
| 60 | + { |
| 61 | + Console.WriteLine("There was a problem retreiving the account."); |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + //Sync account |
| 66 | + await account.SyncAccountAsync(); |
| 67 | + string walletAddress = (await account.GetAddressesAsync()).Payload!.First().Address; |
| 68 | + |
| 69 | + //Ed25519Address ed25519Address = new Ed25519Address(walletAddress.DecodeBech32(NetworkType.Testnet, TypeOfCoin.Shimmer)); |
| 70 | + //AddressUnlockCondition addressUnlockCondition = new AddressUnlockCondition(ed25519Address); |
| 71 | + |
| 72 | + //BuildBasicOutputData buildBasicOutputData = new BuildBasicOutputData( |
| 73 | + // amount: "1000000", |
| 74 | + // nativeTokens: null, |
| 75 | + // unlockConditions: new() { addressUnlockCondition }, |
| 76 | + // features: null); |
| 77 | + //BuildBasicOutputResponse buildBasicOutputResponse = await account.BuildBasicOutputAsync(buildBasicOutputData); |
| 78 | + //BasicOutput basicOutput = buildBasicOutputResponse.Payload!; |
| 79 | + |
| 80 | + //SendOutputsResponse sendOutputsResponse = await account.SendOutputsAsync(new() { basicOutput }); |
| 81 | + //string transactionId = sendOutputsResponse.Payload!.TransactionId; |
| 82 | + |
| 83 | + Ed25519Address ed25519Address = new Ed25519Address(walletAddress.DecodeBech32(NetworkType.Testnet, TypeOfCoin.Shimmer)); |
| 84 | + |
| 85 | + string? amount = "500000"; |
| 86 | + |
| 87 | + List<IFeatureType>? features = null; |
| 88 | + |
| 89 | + IssuerFeature issuerFeature = new IssuerFeature(ed25519Address); |
| 90 | + MetadataFeature immutableMetadataFeature = new MetadataFeature("Hello".ToHexString()); |
| 91 | + List<IFeatureType> immutableFeatures = new List<IFeatureType> { issuerFeature, immutableMetadataFeature }; |
| 92 | + |
| 93 | + NativeToken? nativeToken = null; |
| 94 | + |
| 95 | + AddressUnlockCondition addressUnlockCondition = new AddressUnlockCondition(ed25519Address); |
| 96 | + StorageDepositReturnUnlockCondition storageDepositReturnUnlockCondition = new StorageDepositReturnUnlockCondition(ed25519Address, amount); |
| 97 | + List<IUnlockConditionType> unlockConditions = new List<IUnlockConditionType>() { addressUnlockCondition, storageDepositReturnUnlockCondition }; |
| 98 | + |
| 99 | + BuildNftOutputData buildNftOutputData = new BuildNftOutputData(amount, nativeToken, unlockConditions, null, immutableFeatures, "0x0000000000000000000000000000000000000000000000000000000000000000"); |
| 100 | + BuildNftOutputResponse buildNftOutputResponse = await account.BuildNftOutputAsync(buildNftOutputData); |
| 101 | + NftOutput nftOutput = buildNftOutputResponse.Payload!; |
| 102 | + SendOutputsResponse sendOutputsResponse = await account.SendOutputsAsync(new List<IOutputType>() { nftOutput }); |
| 103 | + string transactionId = sendOutputsResponse.Payload!.TransactionId; |
| 104 | + |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + } |
| 109 | +} |
0 commit comments