UniqueSDK 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package UniqueSDK --version 0.0.1
NuGet\Install-Package UniqueSDK -Version 0.0.1
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.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UniqueSDK --version 0.0.1
#r "nuget: UniqueSDK, 0.0.1"
#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.0.1

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

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.

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 SubstrateClientExt(
        new System.Uri(Constants.UNIQUE_NODE_URL),
        ChargeTransactionPayment.Default());

await client.ConnectAsync();
  • Feel free to change the Constants.UNIQUE_NODE_URL for any other websocket 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 net8.0 is compatible.  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. 
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