UniqueSDK 0.1.0

dotnet add package UniqueSDK --version 0.1.0
NuGet\Install-Package UniqueSDK -Version 0.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UniqueSDK" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UniqueSDK --version 0.1.0
#r "nuget: UniqueSDK, 0.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UniqueSDK as a Cake Addin
#addin nuget:?package=UniqueSDK&version=0.1.0

// Install UniqueSDK as a Cake Tool
#tool nuget:?package=UniqueSDK&version=0.1.0

Unique C# SDK

Simple to use nuget package (standard for C# packages) that abstracts the use of simple NFT operations (minting, transferring, querying..).

The ideal goal of this abstraction is to make it understandable to non-web3 developers.

Instalation

Just add the following NuGet package to your project: https://www.nuget.org/packages/uniquesdk

SDK config

SdkConfig takes care of the default values used. Its point is to simplify the use.

For this case, instead of specifying the netword to use every single time, you can just configure it once and forget about it for the rest of your life.

// Change the sdk configuration to use Opal testnet by default.
SdkConfig.UseDefaultNetwork = NetworkEnum.Opal;

Create a new account

// Generate new mnemonics
var mnemonics = Mnemonic.GenerateMnemonic(MnemonicSize.Words12);

// Show these mnemonics to the user.
// Careful, mnemonics are private data, which should never be leaked.
Console.WriteLine(mnemonics);

var keyring = new Keyring();

var firstWallet = keyring.AddFromMnemonic(mnemonics, new Meta() { Name = "Test account" }, KeyType.Ed25519);

// Your account that you can use
var account = firstWallet.Account;

Use existing account

// Use existing mnemonics
var mnemonics = "collect salad honey track clerk energy agent empty edit devote mixed injury";

var keyring = new Keyring();

var firstWallet = keyring.AddFromMnemonic(mnemonics, new Meta() { Name = "Test account" }, KeyType.Ed25519);

// Your account that you can use
var account = firstWallet.Account;

Connect to a Substrate node

// Connect to a Substrate node
var client = new Substrate.Opal.NET.NetApiExt.Generated.SubstrateClientExt(
        new System.Uri(Constants.OPAL_NODE_URL),
        ChargeTransactionPayment.Default());

await client.ConnectAsync();
  • Feel free to change the Constants.OPAL_NODE_URL for any other websocket node URL.
  • You can also use the provided websocket URLs in the Constants class, like Constants.UNIQUE_NODE_URL

Query Free Balance Example

AccountInfo accountInfo = await client.GetAccountInfoAsync(account);

Console.WriteLine($"Free balance: {accountInfo.Data.Free.Amount} {accountInfo.Data.Free.Unit}");
string destinationAddress = "5EU6EyEq6RhqYed1gCYyQRVttdy6FC9yAtUUGzPe3gfpFX8y";

AccountInfo accountInfo = await client.GetAccountInfoAsync(destinationAddress);

Console.WriteLine($"Free balance: {accountInfo.Data.Free.Amount} {accountInfo.Data.Free.Unit}");

Balance Transfer Example

var nonce = await client.System.AccountNextIndexAsync(account.Value, CancellationToken.None);

Response response = await BalancesModel.TransferRestAsync(
account.Value,
"5EU6EyEq6RhqYed1gCYyQRVttdy6FC9yAtUUGzPe3gfpFX8y",
(decimal)1.5,
nonce,
withFee: true
);

Console.WriteLine($"Fee: {response.Fee.Amount} {response.Fee.Unit}");

var result = await client.SignAndSubmitExtrinsicAsync(await response.SignerPayloadJSON.ToExtrinsicAsync(account));

Assert.That(result == ExtrinsicResult.Success);

Create Collection Example

Action<string, ExtrinsicStatus> myCallback = (string id, ExtrinsicStatus status) =>
{
    if (status.ExtrinsicState == ExtrinsicState.Ready)
    {
        Console.WriteLine("Ready");
    }
    else if (status.ExtrinsicState == ExtrinsicState.Dropped)
    {
        Console.WriteLine("Dropped");
    }
    else if (status.ExtrinsicState == ExtrinsicState.InBlock)
    {
        Console.WriteLine("In block");
    }
    else if (status.ExtrinsicState == ExtrinsicState.Finalized)
    {
        Console.WriteLine("Finalized");
    }
};

Collection collection = new Collection
{
    Address = account.Value, // Or any other string SS58 address
    CoverImage = new Image
    {
        Url = "https://ipfs.unique.network/ipfs/QmcAcH4F9HYQtpqKHxBFwGvkfKb8qckXj2YWUrcc8yd24G/image1.png",
    },
    Name = "Test Collection 5",
    PotentialAttributes = new List<PotentialAttribute> {
        new PotentialAttribute{
            TraitType = "color",
            Values = new List<string>
            {
                "red",
                "green",
                "blue"
            }
        }
    }
};

uint? collectionId = await CollectionModel.SignAndSubmitCreateCollectionExtrinsicAsync(client, account, collection, myCallback);

Console.WriteLine("Collection id: " + collectionId);

Mint NFT (Full example)

// Use existing mnemonics
var mnemonics = "collect salad honey track clerk energy agent empty edit devote mixed injury";

var keyring = new Keyring();

var firstWallet = keyring.AddFromMnemonic(mnemonics, new Meta() { Name = "Test account" }, KeyType.Ed25519);

// Your account that you can use
var account = firstWallet.Account;

// Connect to a Substrate node
var client = new SubstrateClientExt(
        new System.Uri(Constants.UNIQUE_NODE_URL),
        ChargeTransactionPayment.Default());

await client.ConnectAsync();

// Nft data
var nft = new Nft
{
    CollectionId = 2753,
    Owner = account.Value, // Or any other string SS58 address
    TokenName = "Unified 2",
    ImageSource = "https://bafybeie5r4xjzjn3x6tl7anncjg62yhjzirpzucve4bwpfjhmblzsfpsuy.ipfs.nftstorage.link/",
};

// Custom callback to react on the extrinsic status change
Action<string, ExtrinsicStatus> myCallback = (string id, ExtrinsicStatus status) =>
{
    if (status.ExtrinsicState == ExtrinsicState.Ready)
    {
        Console.WriteLine("Ready");
    }
    else if (status.ExtrinsicState == ExtrinsicState.Dropped)
    {
        Console.WriteLine("Dropped");
    }
    else if (status.ExtrinsicState == ExtrinsicState.InBlock)
    {
        Console.WriteLine("In block");
    }
    else if (status.ExtrinsicState == ExtrinsicState.Finalized)
    {
        Console.WriteLine("Finalized");
    }
};

// Sign and Submit the Mint Nft extrinsic
uint? nftId = await client.SignAndSubmitMintNftExtrinsicAsync(account, nft, myCallback);

// Your newly minted Nft id
Console.WriteLine("Nft id: " + nftId);

Mint NFT and get Fee details (Full example)

// Use existing mnemonics
var mnemonics = "collect salad honey track clerk energy agent empty edit devote mixed injury";

var keyring = new Keyring();

var firstWallet = keyring.AddFromMnemonic(mnemonics, new Meta() { Name = "Test account" }, KeyType.Ed25519);

// Your account that you can use
var account = firstWallet.Account;

// Connect to a Substrate node
var client = new SubstrateClientExt(
        new System.Uri(Constants.UNIQUE_NODE_URL),
        ChargeTransactionPayment.Default());

await client.ConnectAsync();

// Get Account nonce
var nonce = await client.System.AccountNextIndexAsync(account.Value, CancellationToken.None);

// Nft data
var nft = new Nft
{
    CollectionId = 2753,
    Owner = account.Value, // Or any other string SS58 address
    TokenName = "Unified",
    ImageSource = "https://bafybeie5r4xjzjn3x6tl7anncjg62yhjzirpzucve4bwpfjhmblzsfpsuy.ipfs.nftstorage.link/",
};

// Get extrinsic details from REST api
var response = await NftModel.MintNftRestAsync(
    nft,
    nonce,
    withFee: true
);

// Show the Fee to the user
Console.WriteLine($"Fee: {response.Fee.Amount} {response.Fee.Unit}");

// Custom callback to react on the extrinsic status change
Action<string, ExtrinsicStatus> myCallback = (string id, ExtrinsicStatus status) =>
{
    if (status.ExtrinsicState == ExtrinsicState.Ready)
    {
        Console.WriteLine("Ready");
    }
    else if (status.ExtrinsicState == ExtrinsicState.Dropped)
    {
        Console.WriteLine("Dropped");
    }
    else if (status.ExtrinsicState == ExtrinsicState.InBlock)
    {
        Console.WriteLine("In block");
    }
    else if (status.ExtrinsicState == ExtrinsicState.Finalized)
    {
        Console.WriteLine("Finalized");
    }
};

// Sign and Submit the Mint Nft extrinsic
uint? nftId = await client.SignAndSubmitMintNftExtrinsicAsync(account, response, myCallback);

// Your newly minted Nft id
Console.WriteLine("Nft id: " + nftId);

Query Collection data

var collectionId = 2753;

var collection = await CollectionModel.GetCollectionByIdAsync(collectionId);
var collectionName = "C# is BEST";

var collections = await CollectionModel.GetCollectionsByNameAsync(collectionName, limit: 2);
var owner = account.Value;

var collections = await CollectionModel.GetCollectionsByOwnerAsync(owner);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.0 59 5/13/2024
0.0.3 48 5/13/2024
0.0.2 42 5/13/2024
0.0.1 46 5/13/2024