Methods

Collection

Get collection by Id new

Overview

The method returns collection info with parsed unique schema.

Brief example

import { CollectionIdArguments, CollectionInfoWithSchema } from '@unique-nft/substrate-client/types';
const getCollectionArgs: CollectionIdArguments = { collectionId: 123 };

const collection: CollectionInfoWithSchema = await sdk.collections.get(getCollectionArgs);

Arguments

collectionId: number — collection id

Behaviour and errors

Returns null if the collection does not exist.

If collection properties can not be presented as unique schema, schema property will be empty.

Returns

interface CollectionInfoWithSchema {
    id: number;
    owner: string;
    mode: CollectionMode;
    decimals?: number;
    name: string;
    description: string;
    tokenPrefix: string;
    sponsorship?: CollectionSponsorship;
    limits?: CollectionLimits;
    metaUpdatePermission?: MetaUpdatePermission;
    readOnly?: boolean;
    permissions?: CollectionPermissions;
    schema?: UniqueCollectionSchemaDecoded;
    properties: CollectionProperty[];
}

Examples

import { CollectionIdArguments, CollectionInfoWithSchema } from '@unique-nft/substrate-client/types';
const getCollectionArgs: CollectionIdArguments = { collectionId: 123 };

const collection: CollectionInfo = await sdk.collections.get(getCollectionArgs);
curl -X 'GET' \
  'https://rest.unique.network/opal/collection?collectionId=1' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const collection = await sdk.collections.get({ collectionId: 1 });

Get collection properties

Overview

Gets the array of Collection properties. More details about Collection properties can be found in Set collection propertiesopen in new window.

Brief example

import {
  CollectionPropertiesArguments,
  CollectionPropertiesResult,
} from '@unique-nft/substrate-client';

const args: CollectionPropertiesArguments = {
  collectionId: 1,
  // propertyKeys: ['foo', 'bar'],
};

const result: CollectionPropertiesResult = await sdk.collections.properties(args);

Arguments

collectionId - number

propertyKeys - string[] - optional

Behaviour and errors

Returns array of collection properties

Returns

interface CollectionProperty {
    key: string;
    value: string;
} 

interface CollectionPropertiesResult {
    properties: CollectionProperty[];
};

Examples

import {
  CollectionPropertiesArguments,
  CollectionPropertiesResult,
} from '@unique-nft/substrate-client';

const args: CollectionPropertiesArguments = {
  collectionId: 1,
  // propertyKeys: ['foo', 'bar'],
};

const result: CollectionPropertiesResult = await sdk.collections.properties(args);
curl -X 'GET' \
  'https://rest.unique.network/opal/collection/properties?collectionId=1' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const { properties } = await sdk.collections.properties({ collectionId: 1 });

Create collection with unique schema

Overview

The method creates a new collection with the Unique schema.

Brief example

import { CreateCollectionNewArguments } from '@unique-nft/substrate-client/tokens';

const result = await sdk.collections.creation.submitWaitResult({
  address: '<your address>',
  name: 'Foo',
  description: 'Bar',
  tokenPrefix: 'Baz',
  schema: {
    schemaName: 'unique',
    schemaVersion: '1.0.0',
    image: { urlTemplate: '{infix}' },
    coverPicture: { ipfsCid: '<ipfs cid>' },
  },
});

const {
  parsed: { collectionId },
} = result;

console.log(`Created new collection with id ${collectionId}`);

Arguments

address - The address of the collection owner

name - Collection name (text, up to 64 characters)

description - Collection description (text, up to 256 characters)

mode - The collection type (Nft, Fungible, or ReFungible)

tokenPrefix - Token prefix (text, up to 4 characters)

sponsorship - This field tells if sponsorship is enabled and what address is the current collection sponsor.

limits - Collection limitsopen in new window

metaUpdatePermission - Permission for update meta (ItemOwner, Admin, None)

permissions - Collection permissions

schema - Collection schema

Behaviour and errors

Throws common errors on insufficient balance and so on.

Returns

interface CollectionIdArguments {
  collectionId: number;
}

Examples

import { CreateCollectionNewArguments } from '@unique-nft/substrate-client/tokens';

const result = await sdk.collections.creation.submitWaitResult({
  address: '<your address>',
  name: 'Foo',
  description: 'Bar',
  tokenPrefix: 'Baz',
  schema: {
    schemaName: 'unique',
    schemaVersion: '1.0.0',
    image: { urlTemplate: '{infix}' },
    coverPicture: { ipfsCid: '<ipfs cid>' },
  },
});

const {
  parsed: { collectionId },
} = result;

console.log(`Created new collection with id ${collectionId}`);
curl -X 'POST' \
  'https://rest.unique.network/opal/collection' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "mode": "Nft",
  "name": "Sample collection name",
  "description": "sample collection description",
  "tokenPrefix": "TEST",
  "address": "yGCyN3eydMkze4EPtz59Tn7obwbUbYNZCz48dp8FRdemTaLwm",
  "schema": {
    "coverPicture": {
"ipfsCid": ""
    },
    "image": {
      "urlTemplate": "{infix}"
    },
    "schemaName": "unique",
    "schemaVersion": "1.0.0"
  }
}'

# then we sign, then we call

curl -X 'POST' \
'https://rest.unique.network/opal/extrinsic/submit' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"signerPayloadJSON": { *from previous response* },
"signature": "0x_your_signature_in_hex"
}'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const result = await sdk.collections.creation.submitWaitResult({
  address: '<your address>',
  name: 'Foo',
  description: 'Bar',
  tokenPrefix: 'Baz',
  schema: {
    schemaName: 'unique',
    schemaVersion: '1.0.0',
    image: { urlTemplate: '{infix}' },
    coverPicture: { ipfsCid: '<ipfs cid>' },
  },
});

const {
  parsed: { collectionId },
} = result;

console.log(`Created collection with id ${collectionId}`);

Delete collection properties

Overview

This method deletes collection properties.

Brief example

import { DeleteCollectionPropertiesArguments} from '@unique-nft/substrate-client/tokens';

const args: DeleteCollectionPropertiesArguments = {
    address: '<your address>',
    collectionId: 1,
    propertyKeys: ['foo', 'bar'],
};

const result = await sdk.collections.deleteProperties.submitWaitResult(args);
const deletedKeys = result.parsed.properties.map((property) => property.propertyKey);

console.log(`Deleted ${deletedKeys.join()}`);

Arguments

address - string

collectionId - number

propertyKeys - string[]

Behaviour and errors

Throws common errors on insufficient balance and so on.

Returns

interface CollectionPropertyDeletedEvent {
  collectionId: number;
  propertyKey: string;
}

interface DeleteCollectionPropertiesResult {
  properties: CollectionPropertyDeletedEvent[];
}

Examples

import { DeleteCollectionPropertiesArguments} from '@unique-nft/substrate-client/tokens';

const args: DeleteCollectionPropertiesArguments = {
    address: '<your address>',
    collectionId: 1,
    propertyKeys: ['foo', 'bar'],
};

const result = await sdk.collections.deleteProperties.submitWaitResult(args);
const deletedKeys = result.parsed.properties.map((property) => property.propertyKey);

console.log(`Deleted ${deletedKeys.join()}`);
curl -X 'DELETE' \
  'https://rest.unique.network/opal/collection/properties' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "address": "yGCyN3eydMkze4EPtz59Tn7obwbUbYNZCz48dp8FRdemTaLwm",
  "collectionId": 1,
  "propertyKeys": [
    "foo", "bar"
  ]
}'

# then we sign, then we call

curl -X 'POST' \
'https://rest.unique.network/opal/extrinsic/submit' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"signerPayloadJSON": { *from previous response* },
"signature": "0x_your_signature_in_hex"
}'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

await sdk.collections.deleteProperties.submitWaitResult({
    address: '<your address>',
    collectionId: 1,
    propertyKeys: ['foo', 'bar'],
});

Destroy collection

Overview

The method destroys collection if no tokens within this collection.

Brief example

import { DestroyCollectionArguments } from '@unique-nft/substrate-client/tokens/types';

const destroyArgs: DestroyCollectionArguments = {
    address: '<Account address>',
    collectionId: '<ID of the collection>'
};

const result = await sdk.collections.destroy.submitWaitResult(destroyArgs);
const { success } = result.parsed;

Arguments

address - string

collectionId - number

Behaviour and errors

Throws common errors on insufficient balance and so on.

Returns

interface DestroyCollectionResult {
    success: boolean;
}

Examples

import { DestroyCollectionArguments } from '@unique-nft/substrate-client/tokens/types';

const destroyArgs: DestroyCollectionArguments = {
    address: '<Account address>',
    collectionId: '<ID of the collection>'
};

const result = await sdk.collections.destroy.submitWaitResult(destroyArgs);
const { success } = result.parsed;
curl -X 'DELETE' \
  'https://rest.unique.network/opal/collection' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "address": "yGCyN3eydMkze4EPtz59Tn7obwbUbYNZCz48dp8FRdemTaLwm",
  "collectionId": 1
}'
### then we sign, then we call

curl -X 'POST' \
'https://rest.unique.network/opal/extrinsic/submit' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"signerPayloadJSON": { *from previous response* },
"signature": "0x_your_signature_in_hex"
}'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

client.collections.destroy.submitWaitResult({
    address: '<your address>',
    collectionId: 1,
});

Get effective limits by collection Id

Overview

The method gets collection effective limits.

Brief example

import { CollectionIdArguments, GetCollectionLimitsResult } from '@unique-nft/substrate-client/types';

const { collectionId, limits }: GetCollectionLimitsResult = await sdk.collections.getLimits({ collectionId: 123 });

console.log(`Collection ${collectionId} limits: ${JSON.stringify(limits)}`);

Arguments

collectionId - number

Behaviour and errors

By default, the collection limit is not set (their value is null).

This limit value can be seen when requesting a collection using the Get collection by IDopen in new window method.

If the limit is not set by the user, then the default limit is actually applied to the collection.

The values of the limits actually applied to the collection (default and user-set) can be obtained using Get effective limits by collection ID.

Returns

interface CollectionLimits {
    accountTokenOwnershipLimit: number | null;
    sponsoredDataSize: number | null;
    sponsoredDataRateLimit: number | null;
    tokenLimit: number | null;
    sponsorTransferTimeout: number | null;
    sponsorApproveTimeout: number | null;
    ownerCanTransfer: boolean | null;
    ownerCanDestroy: boolean | null;
    transfersEnabled: boolean | null;
}

interface GetCollectionLimitsResult {
    collectionId: number;
    limits: CollectionLimits;
}

Examples

import { CollectionIdArguments, GetCollectionLimitsResult } from '@unique-nft/substrate-client/types';

const { collectionId, limits }: GetCollectionLimitsResult = await sdk.collections.getLimits({ collectionId: 123 });

console.log(`Collection ${collectionId} limits: ${JSON.stringify(limits)}`);
curl -X 'GET' \
  'https://rest.unique.network/opal/collection/limits?collectionId=1' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const { collectionId, limits } = await sdk.collections.getLimits({ collectionId: 1 });

console.log(`Collection ${collectionId} limits: ${JSON.stringify(limits)}`);

Property permissions

Overview

The method gets an array of collection property permissions (see Set token property permissionsopen in new window).

Brief example

  import {
    PropertyPermissionsArguments,
    PropertyPermissionsResult,
  } from '@unique-nft/substrate-client/tokens/types';
  
  const args: PropertyPermissionsArguments = {
    collectionId: 1,
    // propertyKeys: ['foo', 'bar'],
  };
  
  const result: PropertyPermissionsResult =
    await sdk.collections.propertyPermissions(args);

Arguments

collectionId: number - Collection ID

propertyKeys?: string[] - Array of property keys to get values for

at?: HexString; - Allows specifying at which moment of the chain (block hash) you need to perform the check. If you leave it empty, the result will be for the last block of the chain.

Behaviour and errors

Throw errors:

  • Collection not found

Returns

This method returns PropertyPermissionsResult

  type PropertyPermissionsResult = {
    propertyPermissions: Array<{  
      key: string;
      permission: {
        mutable: boolean;
        collectionAdmin: boolean;
        tokenOwner: boolean;
      };
    }>;
  }

Examples

  import {
    PropertyPermissionsArguments,
    PropertyPermissionsResult,
  } from '@unique-nft/substrate-client/tokens/types';
  
  const args: PropertyPermissionsArguments = {
    collectionId: 1,
    // propertyKeys: ['foo', 'bar'],
  };
  
  const result: PropertyPermissionsResult =
    await sdk.collections.propertyPermissions(args);

    curl -X 'GET' \
      'http://rest.unique.network/opal/collection/property-permissions?collectionId=1' \
      -H 'accept: application/json'
      
  const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
  
  const result = await sdk.collections.propertyPermissions({
    collectionId: 1,
  });

Set collection limits

Overview

The method sets some collection limits and starts enforcing them immediately.

You can get the current collection limits using the Get effective limits by collection Idopen in new window method.

Only the Collection Owner has permission to call this method.

Brief example

    import '@unique-nft/substrate-client/tokens';
    import { SetCollectionLimitsArguments } from '@unique-nft/substrate-client/tokens/types';
    const limitsArgs: SetCollectionLimitsArguments = {
      address: '<your account address>',
      collectionId: '<ID of the collection>',
      limits: {
        accountTokenOwnershipLimit: 1000,
        sponsoredDataSize: 1024,
        sponsoredDataRateLimit: 30,
        tokenLimit: 1000000,
        sponsorTransferTimeout: 6,
        sponsorApproveTimeout: 6,
        ownerCanTransfer: false,
        ownerCanDestroy: false,
        transfersEnabled: false,
      }
    };
    const setResult = await sdk.collections.setLimits.submitWaitResult(limitsArgs);
    const { parsed: { collectionId, limits } } = result;

Arguments

address: string- Signer, the address of the Collection Owner

collectionId: number - ID of the collection to set limits for

limits: CollectionLimits* - The Effective Limits of the collection. The difference between the Effective Limits and the limits returned by Get collection by Idopen in new window is explained in the effective limits of the collectionopen in new window.

* Interface CollectionLimits

  • accountTokenOwnershipLimit?: number | null - Maximum number of tokens that one address can own
  • sponsoredDataSize?: number | null - Maximum byte size of custom token data that can be sponsored when tokens are minted in sponsored mode
  • sponsoredDataRateLimit?: number | null - Defines how many blocks need to pass between setVariableMetadata transactions in order for them to be sponsored
  • tokenLimit?: number | null - Total amount of tokens that can be minted in this collection.
  • sponsorTransferTimeout?: number | null - Time interval in blocks that defines once per how long a non-privileged user transfer or the mint transaction can be sponsored
  • sponsorApproveTimeout?: number | null - Time interval in blocks that defines once per how long a non-privileged user approve transaction can be sponsored
  • ownerCanTransfer?: boolean | null - A boolean value that tells if collection owner or admins can transfer or burn tokens owned by other non-privileged users
  • ownerCanDestroy?: boolean | null - A boolean value that tells if collection owner can destroy it
  • transfersEnabled?: boolean | null - Flag that defines whether token transfers between users are currently enabled

Behaviour and errors

Attention! Total amount of tokens includes also the tokens that have been minted and burned after that. So if tokenLimit=3, 2 tokens were minted and 1 of them was burned, only 1 more token can be minted.

Throw errors:

  • Collection not found
  • Signer is not Collection Owner

Returns

This method returns SetCollectionLimitsResult

    interface SetCollectionLimitsResult {
      collectionId: number;
      limits: CollectionLimits;
    }

Examples

    import '@unique-nft/substrate-client/tokens';
    import { SetCollectionLimitsArguments } from '@unique-nft/substrate-client/tokens/types';
    const limitsArgs: SetCollectionLimitsArguments = {
      address: '<your account address>',
      collectionId: '<ID of the collection>',
      limits: {
        accountTokenOwnershipLimit: 1000,
        sponsoredDataSize: 1024,
        sponsoredDataRateLimit: 30,
        tokenLimit: 1000000,
        sponsorTransferTimeout: 6,
        sponsorApproveTimeout: 6,
        ownerCanTransfer: false,
        ownerCanDestroy: false,
        transfersEnabled: false,
      }
    };
    const setResult = await sdk.collections.setLimits.submitWaitResult(limitsArgs);
    const { parsed: { collectionId, limits } } = result;

    curl -X 'POST' \
      'https://rest.unique.network/opal/collection/set-limits?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "limits": {
        "accountTokenOwnershipLimit": 1000,
        "sponsoredDataSize": 1024,
        "sponsoredDataRateLimit": 30,
        "tokenLimit": 1000000,
        "sponsorTransferTimeout": 6,
        "sponsorApproveTimeout": 6,
        "ownerCanTransfer": false,
        "ownerCanDestroy": false,
        "transfersEnabled": false
      },
      "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
      "collectionId": 1
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.setLimits.submitWaitResult({
      "limits": {
        "accountTokenOwnershipLimit": 1000,
        "sponsoredDataSize": 1024,
        "sponsoredDataRateLimit": 30,
        "tokenLimit": 1000000,
        "sponsorTransferTimeout": 6,
        "sponsorApproveTimeout": 6,
        "ownerCanTransfer": false,
        "ownerCanDestroy": false,
        "transfersEnabled": false
      },
      "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
      "collectionId": 1
    });
    
    const { parsed: { collectionId, limits } } = result;

Set collection permissions

Overview

This method sets on-chain permissions for collection

Brief example

    import {
      SetCollectionPermissionsArguments,
      CollectionAccess,
    } from '@unique-nft/substrate-client/tokens';
    
    const args: SetCollectionPermissionsArguments = {
      address: account.address,
      collectionId,
      permissions: {
        access: CollectionAccess.Normal,
        mintMode: true,
        nesting: {
          collectionAdmin: true,
          tokenOwner: true,
        },
      },
    };
    
    const result = await sdk.collections.setPermissions.submitWaitResult(args);
    
    console.log(
      `Collection #${result.parsed.collectionId} permissions successfully updated`,
    );

Arguments

address: string - Owner address

collectionId: number - Collection id

permissions: CollectionPermissions - Struct that contains the permissions for a collection

  • access?: CollectionAccess - 'Normal' (for public access) or 'WhiteList' (for restricted access)
  • mintMode?: boolean- True, if anyone is allowed to mint. False otherwise
  • nesting?:
    • tokenOwner?: boolean
    • collectionAdmin?: boolean
    • restricted?: number[]

Behaviour and errors

Throw errors:

  • Collection not found

Returns

This method returns SetCollectionPermissionsResult

  type SetCollectionPermissionsResult = {
    collectionId: number;
  }

Examples

  import {
    SetCollectionPermissionsArguments,
    CollectionAccess,
  } from '@unique-nft/substrate-client/tokens';
  
  const args: SetCollectionPermissionsArguments = {
    address: account.address,
    collectionId,
    permissions: {
      access: CollectionAccess.Normal,
      mintMode: true,
      nesting: {
        collectionAdmin: true,
        tokenOwner: true,
      },
    },
  };
  
  const result = await sdk.collections.setPermissions.submitWaitResult(args);
  
  console.log(
    `Collection #${result.parsed.collectionId} permissions successfully updated`,
  );
    curl -X 'POST' \
      'https://rest.unique.network/opal/collection/permissions?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "collectionId": 1,
      "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
      "permissions": {
        "access": "Normal",
        "mintMode": true,
        "nesting": {
          "tokenOwner": true,
          "collectionAdmin": true
        }
      }
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
  const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
  
  const result = await sdk.collections.setPermissions.submitWaitResult({
    "collectionId": 1,
    "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
    "permissions": {
      "access": "Normal",
      "mintMode": true,
      "nesting": {
        "tokenOwner": true,
        "collectionAdmin": true
      }
    }
  });
  
  console.log(
    `Collection #${result.parsed.collectionId} permissions successfully updated`,
  );

Set collection properties

Overview

Collection properties are a unique set of keys and values. The maximum number of keys is 64. The maximum size of a parameter data block (keys and values) is 40kB.

Only the Collection Owner and Collection Admin can modify the Collection properties.

Property keys can only be added, they cannot be removed.

The naming of keys is restricted to a limited set of the following characters: Latin letter any case, numbers, dot, hyphen and underscore (regex: ^[0-9a-zA-Z.-_]).

Brief example

    const args: SetCollectionPropertiesArguments = {
      address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
      collectionId: 1,
      properties: [
        {
          key: 'foo',
          value: 'bar',
        },
      ],
    };
    
    const result = await sdk.collections.setProperties.submitWaitResult(args);
    
    console.log(result.parsed);

Arguments

address: Address - Signer, the address of the Collection Owner or Collection Admin

collectionId: number - Collection id

properties: Array<{ key: string; value: string; }> - Array of properties

Behaviour and errors

Throw errors:

  • Collection not found
  • Signer is not Collection Owner or Collection Admin

Returns

This method returns SetCollectionPermissionsResult

    type SetCollectionPermissionsResult = {
      collectionId: number;
    }

Examples

    const args: SetCollectionPropertiesArguments = {
      address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
      collectionId: 1,
      properties: [
        {
          key: 'foo',
          value: 'bar',
        },
      ],
    };
    
    const result = await sdk.collections.setProperties.submitWaitResult(args);
    
    console.log(result.parsed);

    curl -X 'POST' \
      'https://rest.unique.network/opal/collection/properties?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX",
      "collectionId": 1,
      "properties": [
          {
              "key": "foo",
              "value": "bar"
          }
      ]
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.setProperties.submitWaitResult({
      "address": "5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX",
      "collectionId": 1,
      "properties": [
        {
          "key": "foo",
          "value": "bar"
        }
      ]
    });
    
    const { parsed: { properties } } = result;
    
    console.log(`Properties ${properties.map(t => t.propertyKey).join()} are set for the collection`);

Set token property permissions

Overview

The method sets some tokenPropertyPermissions values. The current value of tokenPropertyPermissions can be found using Property permissionsopen in new window.

The token cannot be attributed to an arbitrary key, only to a key from the tokenPropertyPermissions list.

Only the Collection Owner and Collection Admin can add and modify keys.

The permissions to create and modify properties of a collection are carried out using three keys - mutable, collectionAdmin and tokenOwner.

  • mutable attribute sets the immutability attribute.
  • collectionAdmin grants the designated collection administrator and the collection owner 'write/modify' access
  • tokenOwner grants the token owner 'write/modify' access

Brief example

    const args: SetTokenPropertyPermissionsArguments = {
      address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
      collectionId: 1,
      propertyPermissions: [
        {
          key: 'foo',
          permission: {
            mutable: true,
            collectionAdmin: true,
            tokenOwner: true,
          },
        },
      ],
    };
    
    const result =
      await sdk.collections.setTokenPropertyPermissions.submitWaitResult(args);
    
    console.log(result.parsed);

Arguments

address: string - Signer, the address of the Collection Owner or Collection Admin

collectionId: number - Collection id

propertyPermissions: Array<{ key: string; permission: PropertyPermission*; }> - Array of property permissions

* Type PropertyPermission

mutable: boolean - attribute sets the immutability attribute

collectionAdmin: boolean - grants the designated collection administrator and the collection owner 'write/modify' access

tokenOwner: boolean - grants the token owner 'write/modify' access

Behaviour and errors

Throw errors:

  • Collection not found
  • Signer is not Collection Owner or Collection Admin

Returns

This method returns SetTokenPropertyPermissionsResult

    type SetTokenPropertyPermissionsResult = {
      propertyPermissions: Array<{
        collectionId: number;
        propertyKey: string;
      }>;
    };

Examples

    const args: SetTokenPropertyPermissionsArguments = {
      address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
      collectionId: 1,
      propertyPermissions: [
        {
          key: 'foo',
          permission: {
            mutable: true,
            collectionAdmin: true,
            tokenOwner: true,
          },
        },
      ],
    };
    
    const result =
      await sdk.collections.setTokenPropertyPermissions.submitWaitResult(args);
    
    console.log(result.parsed);

    curl -X 'POST' \
      'https://rest.unique.network/opal/collection/property-permissions?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX",
      "collectionId": 1,
      "propertyPermissions": [
        {
          "key": "foo",
          "permission": {
            "mutable": true,
            "collectionAdmin": true,
            "tokenOwner": true
          }
        }
      ]
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.setPropertyPermissions.submitWaitResult({
      "address": "5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX",
      "collectionId": 1,
      "propertyPermissions": [
        {
          "key": "foo",
          "permission": {
            "mutable": true,
            "collectionAdmin": true,
            "tokenOwner": true
          }
        }
      ]
    });
    
    const { parsed: { propertyPermissions } } = result;
    
    console.log(`the values of the keys ${propertyPermissions.map(t => t.propertyKey).join()} are set`);

Set transfers enabled flag

Overview

The method enables or disables transfers in a collection.

Only the Collection Owner can call this method.

The method sets transfersEnabled flag for particular collection. The current value of the transfersEnabled flag can be found using the method Get effective limitsopen in new window

Brief example

    import { SetTransfersEnabledArguments } from '@unique-nft/substrate-client/tokens/types';
    
    const args: SetTransfersEnabledArguments = {
      address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
      collectionId: 1,
      isEnabled: true,
    };
    
    const result = await sdk.collections.setTransfersEnabled.submitWaitResult(args);
    
    console.log(result.parsed.success);

Arguments

address: string- Signer, the address of the Collection Owner

collectionId: number - Collection id

isEnabled: boolean - New flag value. If True, allows transfers, otherwise token transfers are frozen

Behaviour and errors

Throw errors:

  • Collection not found
  • Signer is not Collection Owner

Returns

This method returns SetTransfersEnabledResult

    interface SetTransfersEnabledResult {
      success: boolean;
    }

Examples

    import { SetTransfersEnabledArguments } from '@unique-nft/substrate-client/tokens/types';
    
    const args: SetTransfersEnabledArguments = {
      address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
      collectionId: 1,
      isEnabled: true,
    };
    
    const result = await sdk.collections.setTransfersEnabled.submitWaitResult(args);
    
    console.log(result.parsed.success);

    curl -X 'POST' \
      'https://rest.unique.network/opal/collection/transfers-enabled?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
      "collectionId": 1,
      "isEnabled": true
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.setTransfersEnabled.submitWaitResult({
      "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
      "collectionId": 1,
      "isEnabled": true
    });

    console.log(result.parsed.success);

Change the owner of the collection

Overview

This method assigns a new collection owner. Only the Collection Owner can call this method.

Brief example

    import { TransferCollectionArguments } from '@unique-nft/substrate-client/tokens/types';
    
    const args: TransferCollectionArguments = {
      collectionId: '<ID of the collection>',
      from: '<collection owner>',
      to: '<new collection owner>'
    };
    
    const result = await sdk.collections.transfer.submitWaitResult(args);
    const { collectionId, newOnwer } = result.parsed;

Arguments

collectionId: number - ID of the collection to change owner for

from: string - The address of the Collection Owner

to: string - New collection owner (Substrate address)

Behaviour and errors

Throw errors:

  • Collection not found
  • from address is not Collection Admin address

Returns

This method returns TransferCollectionResult

    export interface TransferCollectionResult {
      collectionId: number;
      owner: string;
    }

Examples

    import { TransferCollectionArguments } from '@unique-nft/substrate-client/tokens/types';
    
    const args: TransferCollectionArguments = {
      collectionId: '<ID of the collection>',
      from: '<collection owner>',
      to: '<new collection owner>'
    };
    
    const result = await sdk.collections.transfer.submitWaitResult(args);
    const { collectionId, newOnwer } = result.parsed;

    curl -X 'PATCH' \
      'https://rest.unique.network/opal/collection/transfer?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "collectionId": 1,
      "from": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
      "to": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.transfer.submitWaitResult({
      "collectionId": 1,
      "from": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
      "to": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
    });
    
    const { parsed: { collectionId, owner } } = result;
    
    console.log(`new owner of collection ${collectionId} has address ${owner}`);

Collections admin

Add collection admin

Overview

Adds an admin of the Collection.

Admin description is available in Get admin listopen in new window.

Only Collection Owner or Collection Admin has permission to call this method.

Brief example

    import { AddCollectionAdminArguments } from '@unique-nft/substrate-client/tokens';
    
    const args: AddCollectionAdminArguments = {
      address: '<address>',
      collectionId: 1,
      newAdmin: '<address>',
    };
    
    const result = await sdk.collections.addAdmin.submitWaitResult(args);
    
    console.log(result.parsed);

Arguments

address: string - Signer, the address of the Collection Owner or Collection Admin

collectionId: number - ID of the Collection to add admin for

newAdmin: string - Address of new admin to add

Behaviour and errors

Throw errors:

  • Collection not found
  • Signer is not Collection Owner or Collection Admin

Returns

This method returns AddCollectionAdminResult

    interface AddCollectionAdminResult {
      collectionId: number;
      newAdmin: string;
    }

Examples

    import { AddCollectionAdminArguments } from '@unique-nft/substrate-client/tokens';
    
    const args: AddCollectionAdminArguments = {
      address: '<address>',
      collectionId: 1,
      newAdmin: '<address>',
    };
    
    const result = await sdk.collections.addAdmin.submitWaitResult(args);
    
    console.log(result.parsed);

    curl -X 'POST' \
      'https://rest.unique.network/opal/collection/admins?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
      "collectionId": 1,
      "newAdmin": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.addAdmin.submitWaitResult({
      "address": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
      "collectionId": 1,
      "newAdmin": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
    });
    
    const { parsed: { collectionId, newAdmin } } = result;
    
    console.log(`collection ${collectionId} has admin ${newAdmin}`);

Get admin list

Overview

Gets an array of Collection Admins.

NFT Collection can be controlled by multiple admin addresses (some of which can also be servers, for example).

Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.

The list of admins may be or become empty.

To add a Collection Admin, use the Add collection adminopen in new window method.

Brief example

    import {
      AdminlistArguments,
      AdminlistResult,
    } from '@unique-nft/substrate-client/tokens/types';
    
    const args: AdminlistArguments = {
      collectionId: 1,
    };
    
    const result: AdminlistResult = await sdk.collections.admins(args);

Arguments

collectionId: number - Collection id

at?: string; - Allows to specify at which moment of the chain (block hash) you need to perform the check. If you leave it empty, the result will be for the last block of the chain.

Behaviour and errors

Throw errors:

  • Collection not found

Returns

This method returns AdminlistResult

    type AdminlistResult = {
      admins: string[];
    };

Examples

    import {
      AdminlistArguments,
      AdminlistResult,
    } from '@unique-nft/substrate-client/tokens/types';
    
    const args: AdminlistArguments = {
      collectionId: 1,
    };
    
    const result: AdminlistResult = await sdk.collections.admins(args);
    curl -X 'GET' \
      'https://rest.unique.network/opal/collection/admins?collectionId=1' \
      -H 'accept: application/json'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.admins({
        collectionId: 1,
    });
    
    const { admins } = result;
    
    console.log(`${admins.join()} - collection admins`);

Remove collection admin

Overview

The method removes the admin address of the Collection. An admin address can remove itself.

The list of admins may be or become empty, in which case only Collection Owner will be able to add an Admin.

Admin description is available in Get admin listopen in new window.

Only the Collection Owner or Collection Admin has permission to call this method.

Brief example

    import { RemoveCollectionAdminArguments } from '@unique-nft/substrate-client/tokens';
    
    const args: RemoveCollectionAdminArguments = {
      address: '<address>',
      collectionId: 1,
      accountId: '<address>',
    };
    
    const result = await sdk.collections.removeAdmin.submitWaitResult(args);
    
    console.log(result.parsed);

Arguments

address: string - Signer, the address of the Collection Owner or Collection Admin

collectionId: number - ID of the Collection to remove admin for

admin: string - Address of admin to remove

Behaviour and errors

Throw errors:

  • Collection not found
  • Signer is not Collection Owner or Collection Admin

Returns

This method returns RemoveCollectionAdminResult

    interface RemoveCollectionAdminResult {
      collectionId: number;
      admin: string;
    }

Examples

    import { RemoveCollectionAdminArguments } from '@unique-nft/substrate-client/tokens';
    
    const args: RemoveCollectionAdminArguments = {
      address: '<address>',
      collectionId: 1,
      accountId: '<address>',
    };
    
    const result = await sdk.collections.removeAdmin.submitWaitResult(args);
    
    console.log(result.parsed);

    curl -X 'DELETE' \
      'https://rest.unique.network/opal/collection/admins?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
          "address": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
          "collectionId": 1,
          "admin": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
        }'
        
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

    const result = await sdk.collections.removeAdmin.submitWaitResult({
      "address": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
      "collectionId": 1,
      "admin": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
    });
    
    const { parsed: { collectionId, admin } } = result;
    
    console.log(`admin ${admin} removed from collection ${collectionId}`);

Collections allow list

Add To Allow List

Overview

Adds an address to allow list of a collection.

Brief example

import { AddToAllowListArguments } from '@unique-nft/substrate-client/tokens/types';

const addToAllowListArgs: AddToAllowListArguments = {
    address: '<your account address>',
    collectionId: '<ID of the collection>',
    newAdminId: '<valid address>'
};

const { parsed } = await sdk.collections.addToAllowList.submitWaitResult(addToAllowListArgs);
const { collectionId, address } = parsed;

Arguments

  • address - Sender address
  • collectionId - An ID of the collection which will be affected
  • newAdminId - The address to be added to the allow list

Behaviour and errors

Returns

This method returns AddToAllowListResult

interface AccountTokensResult {
  address: Address;
  collectionId: number;
}

Examples

import { AddToAllowListArguments } from '@unique-nft/substrate-client/tokens/types';

const addToAllowListArgs: AddToAllowListArguments = {
    address: '<your account address>',
    collectionId: '<ID of the collection>',
    newAdminId: '<valid address>'
};

const { parsed } = await sdk.collections.addToAllowList.submitWaitResult(addToAllowListArgs);

const { collectionId, address } = parsed;

console.log(
  `Address ${address} is allowed in collection ${collectionId}`,
);
    curl -X 'POST' \
      'https://rest.unique.network/opal/collection/add-to-allow-list' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "<address>",
      "collectionId": 1,
      "newAdminId": "<address>"
    }'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const { parsed } = await sdk.collections.addToAllowList.submitWaitResult({
  address: '<your account address>',
  collectionId: '<ID of the collection>',
  newAdminId: '<valid address>'
});

const { address, collectionId } = parsed;

console.log(
  `Address ${address} is allowed in collection ${collectionId}`,
);

Allow list

Overview

Gets the addresses from allow list of the specified collection.

Brief example

import { AllowListArguments } from '@unique-nft/substrate-client/tokens/types';

const allowListArgs: AllowListArguments = {
  collectionId: 1,
};

const addresses = await sdk.collections.allowList(allowListArgs);

Arguments

  • collectionId - an ID of the collection which will be checked

Returns

This method returns AllowListResult

interface AllowListResult {
  addresses: Address[];
}

Examples

  import { AllowListArguments } from '@unique-nft/substrate-client/tokens/types';
  
  const allowListArgs: AllowListArguments = {
    collectionId: 1,
  };

  const { addresses } = await sdk.collections.allowList(allowListArgs);
  
  console.log(`addresses: ${addresses}`);
    curl -X 'GET' \
    'https://rest.unique.network/opal/collection/allow-list?collectionId=1'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const { addresses } = await sdk.collections.allowList({
        collectionId: 1,
    });

    console.log(`addresses: ${addresses}`);

Get allowance

The method gets the number of token pieces approved to transfer

Arguments

  • from - address from
  • to - address to
  • collectionId - ID of collection
  • tokenId - ID of token

Returns

Method returns object:

  • isAllowed - boolean

Examples

const { isAllowed } = await sdk.tokens.allowance({
  from: '<address>',
  to: '<address>',
  collectionId: 1,
  tokenId: 1,
});

Check is allowed

Overview

Checks if user is allowed to use the collection. Returns true or false.

Brief example

const { isAllowed } = await sdk.collection.allowed({
  collectionId: 1,
  account: '<address>',
});

console.log(`isAllowed: ${isAllowed}`);

Arguments

  • collectionId - ID of collection
  • account - Account address
  • at optional - hash of execution block

Returns

This method returns AllowedResult

interface AllowedResult {
  isAllowed: boolean;
}

Examples

  const { isAllowed } = await sdk.collection.allowed({
    collectionId: 1,
    account: '<address>',
  });
  
  console.log(`isAllowed: ${isAllowed}`);
    curl -X 'GET' \
    'https://rest.unique.network/opal/collection/allowed?collectionId=1&address=<address>'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const { isAllowed } = await sdk.collections.allowed({
        collectionId: 1,
        account: '<address>',
    });

    console.log(`isAllowed: ${isAllowed}`);

Remove from allow list

Overview

Removes an account from the allow list.

Brief example

import { RemoveFromAllowListArguments } from '@unique-nft/substrate-client/tokens/types';

const removeFromAllowListArgs: RemoveFromAllowListArguments = {
    address: '<your account address>',
    collectionId: '<ID of the collection>',
    addressToDelete: '<valid address>'
};

const { parsed } = await sdk.collections.removeFromAllowList.submitWaitResult(removeFromAllowListArgs);
const { collectionId, address } = parsed;

Arguments

  • address - Sender address
  • collectionId - an ID of the collection which will be affected
  • addressToDelete - the address to be removed from the allow list

Returns

This method returns RemoveFromAllowListResult

interface RemoveFromAllowListResult {
  address: Address;
  collectionId: number;
}

Examples

    import { RemoveFromAllowListArguments } from '@unique-nft/substrate-client/tokens/types';
    
    const removeFromAllowListArgs: RemoveFromAllowListArguments = {
        address: '<your account address>',
        collectionId: '<ID of the collection>',
        addressToDelete: '<valid address>'
    };
    
    const { parsed } = await sdk.collections.removeFromAllowList.submitWaitResult(removeFromAllowListArgs);
    
    const { collectionId, address } = parsed;
    
    console.log(
      `Address ${address} removed from allow list in collection ${collectionId}`,
    );
    curl -X 'POST' \
      'https://rest.unique.network/opal/collection/remove-from-allow-list' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "<address>",
      "collectionId": 1,
      "addressToDelete": "<address>"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const { parsed } = await sdk.collections.removeFromAllowList.submitWaitResult({
      address: '<your account address>',
      collectionId: '<ID of the collection>',
      addressToDelete: '<valid address>'
    });
    
    const { collectionId, address } = parsed;
    
    console.log(
      `Address ${address} removed from allow list in collection ${collectionId}`,
    );

Nesting

Get bundle

Overview

Returns full tree of a nested tokens. You can request it with any token from the bundle, the result will be the same for all.

Brief example

import { NestedToken } from '@unique-nft/substrate-client/types';

const result: NestedToken = await sdk.tokens.getBundle({
  collectionId: 2,
  tokenId: 5,
});

console.log(result);

/*
{
    tokenId: 1,
    collectionId: 1,
    nestingChildTokens: [
    {tokenId: 2, collectionId 1, childs: []},
    ...
    {tokenId: 5, collectionId 1, childs: []},       <------- this is the requested token
    ]
}
*/

Arguments

collectionId: number - collection id

tokenId: number - token id

Behaviour and errors

Throw errors:

  • If the topmost token of a bundle has no nested tokens
  • Recursion depth exceeded
  • Token not found during search for nested children

Returns

This method returns NestedToken

type NestedToken = Omit<TokenByIdResult, 'nestingChildTokens'> & {
  nestingChildTokens: NestedToken[];
};

Examples

import { GetBundleArguments } from '@unique-nft/substrate-client/tokens';

const args: GetBundleArguments = {
  collectionId: 2,
  tokenId: 5,
};

const bundle = await sdk.tokens.getBundle(args);

console.log(bundle);
curl -X 'GET' \
  'https://rest.unique.network/opal/token/get-bundle?collectionId=2&tokenId=5' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const bundle = await sdk.tokens.getBundle({
  collectionId: 2,
  tokenId: 5,
});

console.log(bundle);

Is Bundle

Overview

The method returns whether the token is in part of the bundle or not.

Brief example

const isBundle = await sdk.tokens.isBundle({
  collectionId: 2,
  tokenId: 1,
});

console.log(isBundle);

// false

Arguments

collectionId: number - collection id

tokenId: number - token id

Returns

This method returns IsBundleResult

type IsBundleResult = boolean;

Examples

import { IsBundleArguments } from '@unique-nft/substrate-client/tokens';

const args: IsBundleArguments = {
  collectionId: 2,
  tokenId: 1,
};

const bundle = await sdk.tokens.isBundle(args);

console.log(bundle);
curl -X 'GET' \
  'https://rest.unique.network/opal/token/is-bundle?collectionId=2&tokenId=1' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const result = await sdk.tokens.isBundle({
  collectionId: 2,
  tokenId: 1,
});

console.log(result.isBundle);

Nest token

Overview

Nesting is a process of forming a structural relationship between two NFTs that form a parent-child relationship in a tree structure. Such a relationship is formed by forwarding token A2 to the address of token A1 by which A2 becomes a child of token A1 (conversely, token A1 becomes the parent of A2).

Brief example

import { NestTokenArguments } from '@unique-nft/substrate-client/tokens/types';

const args: NestTokenArguments = {
  address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
  parent: {
    collectionId: 1,
    tokenId: 1,
  },
  nested: {
    collectionId: 1,
    tokenId: 2,
  },
};

const result = await sdk.tokens.nestToken.submitWaitResult(args);

const { tokenId, collectionId } = result.parsed;

console.log(
  `Token ${tokenId} from collection ${collectionId} successfully nested`,
);

Arguments

address: string - Token owner address

parent: { collectionId: number, tokenId: number } - Parent token object

nested: { collectionId: number, tokenId: number } - Nested token object

Behaviour and errors

Nesting can be applied only if the token collection has permission for nesting. If the collection has no permission for nesting - "UserIsNotAllowedToNest" Error will be thrown.

await sdk.collections.creation.submitWaitResult({
  // ...
  permissions: {
    nesting: {
      tokenOwner: true,
      collectionAdmin: true,
    },
  },

Returns

The method returns NestTokenResult

type NestTokenResult = {
  /**
   * id of the collection
   */
  collectionId: number;
  /**
   * id of the token
   */
  tokenId: number;
};

Examples

import { NestTokenArguments } from '@unique-nft/substrate-client/tokens/types';

const args: NestTokenArguments = {
  address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
  parent: {
    collectionId: 1,
    tokenId: 1,
  },
  nested: {
    collectionId: 1,
    tokenId: 2,
  },
};

const result = await sdk.tokens.nestToken.submitWaitResult(args);

const { tokenId, collectionId } = result.parsed;

console.log(
  `Token ${tokenId} from collection ${collectionId} successfully nested`,
);

    curl -X 'POST' \
      'https://rest.unique.network/opal/token/nest' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "yGCyN3eydMkze4EPtz59Tn7obwbUbYNZCz48dp8FRdemTaLwm",
      "parent": {
        "collectionId": 1,
        "tokenId": 1
      },
      "nested": {
        "collectionId": 1,
        "tokenId": 2
      }
    }'

    # then we sign, then we call

    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const result = await sdk.tokens.nest.submitWaitResult({
  address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
  parent: {
    collectionId: 1,
    tokenId: 1,
  },
  nested: {
    collectionId: 1,
    tokenId: 2,
  },
});

const {
  parsed: { sponsor, collectionId },
} = result;

console.log(
  `Token ${tokenId} from collection ${collectionId} successfully nested`,
);

Token children

Overview

Gets an array of nested tokens. If the token has no children returns an empty array.

Brief example

import {
  TokenChildrenArguments,
  TokenChildrenResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenChildrenArguments = {
  collectionId: 1,
  tokenId: 1,
};

const result: TokenChildrenResult = await sdk.tokens.children(args);

console.log(result);

/*
{
  children: [
    {
      collectionId: 1,
      token: 2
    },
    {
      collection: 1,
      token: 3
    }
  ]
}
*/

Arguments

collectionId: number - collection id

tokenId: number - token id

Returns

This method returns TokenChildrenResult

type TokenChildrenArguments = {
  collectionId: number;
  tokenId: number;
};

type TokenChildrenResult = {
  children: TokenChildrenArguments[];
};

Examples

import {
  TokenChildrenArguments,
  TokenChildrenResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenChildrenArguments = {
  collectionId: 1,
  tokenId: 1,
};

const result: TokenChildrenResult = await sdk.tokens.children(args);

console.log(result);
curl -X 'GET' \
  'https://rest.unique.network/opal/token/children?collectionId=1&tokenId=1' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const result = await sdk.tokens.children({
  collectionId: 1,
  tokenId: 1,
});

console.log(result.children);

Token parent

Overview

Returns info about the token parent. Call the tokenOwner method. If the owner is not a nesting token returns null.

Brief example

import {
  TokenParentArguments,
  TokenParentResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenParentArguments = {
  collectionId: 1,
  tokenId: 2,
};

const result: TokenParentResult = await sdk.tokens.parent(args);

console.log(result);

/*
{
  collectionId: 1;
  tokenId: 1;
  address: "5HpZHYXjV23eEdVzhvYD2D3H6g1kM3aRGYwrmuGe9zaod6od";
}
*/

Arguments

collectionId: number - collection id

tokenId: number - token id

Returns

This method returns TokenParentResult

type TokenParentResult = {
  collectionId: number;
  tokenId: number;
  address: Address;
};

Examples

import {
  TokenParentArguments,
  TokenParentResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenParentArguments = {
  collectionId: 1,
  tokenId: 2,
};

const result: TokenParentResult = await sdk.tokens.parent(args);

console.log(result);
curl -X 'GET' \
  'https://rest.unique.network/opal/token/parent?collectionId=1&tokenId=2' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const result = await sdk.tokens.parent({
  collectionId: 1,
  tokenId: 2,
});

console.log(result);

Topmost token owner

Overview

Returns substrate address of the topmost token owner.

Brief example

import {
  TokenOwnerArguments,
  TopmostTokenOwnerResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenOwnerArguments = {
  collectionId: 1,
  tokenId: 1,
  // blockHashAt: '0xff19c2457fa4d7216cfad444615586c4365250e7310e2de7032ded4fcbd36873'
};

const result: TopmostTokenOwnerResult = await sdk.tokens.topmostOwner(args);

console.log(result);

/*
{
  topmostOwner: "5HpZHYXjV23eEdVzhvYD2D3H6g1kM3aRGYwrmuGe9zaod6od"
}
*/

Arguments

collectionId: number - collection id

tokenId: number - token id

blockHashAt: string - optional - hash of execution block

Returns

This method returns TopmostTokenOwnerResult

type TopmostTokenOwnerResult = { topmostOwner: Address };

Examples

import {
  TokenOwnerArguments,
  TopmostTokenOwnerResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenOwnerArguments = {
  collectionId: 1,
  tokenId: 1,
  // blockHashAt: '0xff19c2457fa4d7216cfad444615586c4365250e7310e2de7032ded4fcbd36873'
};

const result: TopmostTokenOwnerResult = await sdk.tokens.topmostOwner(args);

console.log(result);
curl -X 'GET' \
  'https://rest.unique.network/opal/token/topmost-owner?collectionId=1&tokenId=2' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const result = await sdk.tokens.topmostOwner({
  collectionId: 1,
  tokenId: 2,
});

console.log(result.topmostOwner);

Unnest token

Overview

Nesting is a process of forming a structural relationship between two NFTs that form a parent-child relationship in a tree structure. Such a relationship is formed by forwarding token A2 to the address of token A1 by which A2 becomes a child of token A1 (conversely, token A1 becomes the parent of A2).

Brief example

import { UnnestTokenArguments } from '@unique-nft/substrate-client/tokens/types';

const args: UnnestTokenArguments = {
  address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
  parent: {
    collectionId: 1,
    tokenId: 1,
  },
  nested: {
    collectionId: 1,
    tokenId: 2,
  },
};

const result = await sdk.tokens.unnestToken.submitWaitResult(args);

const { tokenId, collectionId } = result.parsed;

console.log(
  `Token ${tokenId} from collection ${collectionId} successfully unnested`,
);

Arguments

address: string - Token owner address

parent: { collectionId: number, tokenId: number } - Parent token object

nested: { collectionId: number, tokenId: number } - Nested token object

Behaviour and errors

This method can only be executed if the token is nested.

Returns

The method returns UnnestTokenResult

type UnnestTokenResult = {
  /**
   * id of the collection
   */
  collectionId: number;
  /**
   * id of the token
   */
  tokenId: number;
};

Examples

import { UnnestTokenArguments } from '@unique-nft/substrate-client/tokens/types';

const args: UnnestTokenArguments = {
  address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
  parent: {
    collectionId: 1,
    tokenId: 1,
  },
  nested: {
    collectionId: 1,
    tokenId: 2,
  },
};

const result = await sdk.tokens.unnestToken.submitWaitResult(args);

const { tokenId, collectionId } = result.parsed;

console.log(
  `Token ${tokenId} from collection ${collectionId} successfully unnested`,
);

    curl -X 'POST' \
      'https://rest.unique.network/opal/token/unnest' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "yGCyN3eydMkze4EPtz59Tn7obwbUbYNZCz48dp8FRdemTaLwm",
      "parent": {
        "collectionId": 1,
        "tokenId": 1
      },
      "nested": {
        "collectionId": 1,
        "tokenId": 2
      }
    }'

    # then we sign, then we call

    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const result = await sdk.tokens.unnest.submitWaitResult({
  address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
  parent: {
    collectionId: 1,
    tokenId: 1,
  },
  nested: {
    collectionId: 1,
    tokenId: 2,
  },
});

const {
  parsed: { sponsor, collectionId },
} = result;

console.log(
  `Token ${tokenId} from collection ${collectionId} successfully unnested`,
);

Sponsorship

Confirm sponsorship

Overview

Sponsors should use this method to confirm sponsorship after the collection owner called the set collection sponsoropen in new window method.

Brief example

    import { ConfirmSponsorshipArguments } from '@unique-nft/substrate-client/tokens';

    const confirmSponsorshipArgs: ConfirmSponsorshipArguments = {
        address: '5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp',
        collectionId: 1,
    };
    
    await sdk.collections.confirmSponsorship.submitWaitResult(confirmSponsorshipArgs);

    const { sponsorship } = await sdk.collections.get({ collectionId: 1 });

    // `5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp - true`
    console.log(`${sponsorship?.address} - ${sponsorship?.isConfirmed}`);

Arguments

address: string — sponsor address

collectionId: number — collection id

Behaviour and errors

This method takes collection id and confirms the signer to be a collection sponsor.

The collection owner should call the set collection sponsoropen in new window with the sponsor address, otherwise, an error will be thrown.

Only an unconfirmed sponsor of the collection should call and sign this method.

Throws common errors on insufficient balance and so on.

Returns

This method returns ConfirmSponsorshipResult

    interface ConfirmSponsorshipResult {
        /**
         * id of the collection
         */
        collectionId: number;
    
        /**
         * address of the sponsor (Substrate)
         */
        sponsor: Address;
    }

Examples

    import { ConfirmSponsorshipArguments } from '@unique-nft/substrate-client/tokens';

    const confirmSponsorshipArgs: ConfirmSponsorshipArguments = {
        address: '5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp',
        collectionId: 1,
    };
    
    await sdk.collections.confirmSponsorship.submitWaitResult(confirmSponsorshipArgs);
    
    const { sponsorship } = await sdk.collections.get({ collectionId: 1 });
    
    // `5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp - true`
    console.log(`${sponsorship?.address} - ${sponsorship?.isConfirmed}`);

    curl -X 'POST' \
    'https://rest.unique.network/opal/collection/sponsorship/confirm' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "address": "5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp",
    "collectionId": 1
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.confirmSponsorship.submitWaitResult({
        address: '5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp',
        collectionId: 1,
    });
    
    const { parsed: { sponsor, collectionId } } = result;
    
    console.log(`${sponsor} approved sponsorship of ${collectionId} collection`);

Next sponsored

Overview

This method returns the number of blocks when the sponsored transaction is available. Returns null if sponsorship hasn't been set.

Brief example

import {
  NextSponsoredArguments,
  NextSponsoredResult,
} from '@unique-nft/substrate-client/types';

const args: NextSponsoredArguments = {
  collectionId: 1,
  tokenId: 1,
  address: '5G4M7RCt8PvtFPFm4XSwu85eK9Z8n9c6rygHZawHVALUvgcd',
  // at: "0xa37d1c0155bda5877f4bc64c62cd37022c1b6db201c8225da7d169336d38b257"
};

const result: NextSponsoredResult = await sdk.collections.nextSponsored(args);

console.log(result);
/*
{
  "blockNumber": 0
}
*/

Arguments

collectionId: number - ID of collection

tokenId: number - ID of token

address: string - Address of transaction account

at: string - optional - Hash of execution block

Returns

This method returns NextSponsoredResult

type NextSponsoredResult = {
  blockNumber: number | null;
};

Examples

import {
  NextSponsoredArguments,
  NextSponsoredResult,
} from '@unique-nft/substrate-client/types';

const args: NextSponsoredArguments = {
  collectionId: 1,
  tokenId: 1,
  address: '5G4M7RCt8PvtFPFm4XSwu85eK9Z8n9c6rygHZawHVALUvgcd',
  // at: "0xa37d1c0155bda5877f4bc64c62cd37022c1b6db201c8225da7d169336d38b257"
};

const result: NextSponsoredResult = await sdk.collections.nextSponsored(args);

console.log(result);
curl -X 'GET' \
  'https://rest.unique.network/opal/collection/next-sponsored?collectionId=934&address=5GbRWxdwL8eHAgVaeXW3GUBffyLaKaLRhXXPwcnZbbzKDUU8&tokenId=1' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const result = await sdk.tokens.nextSponsored({
  collectionId: 1,
  tokenId: 1,
  address: '5G4M7RCt8PvtFPFm4XSwu85eK9Z8n9c6rygHZawHVALUvgcd',
});

console.log(result);

Remove collection sponsor

Overview

The collection owner can use this method to remove sponsors added by the set collection sponsoropen in new window method.

Brief example

    import { RemoveSponsorshipArguments } from '@unique-nft/substrate-client/tokens';

    const removeSponsorshipArgs: RemoveSponsorshipArguments = {
        address: '5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ',
        collectionId: 1,
    };
    
    await sdk.collections.removeSponsorship.submitWaitResult(removeSponsorshipArgs);

    const { sponsorship } = await sdk.collections.get({ collectionId: 1 });

    // `null`
    console.log(sponsorship);

Arguments

address: string — collection owner address

collectionId: number — collection id

Behaviour and errors

This method takes the collection id and removes the collection sponsor.

Only collection owners are allowed to call this method.

Throws common errors on insufficient balance and so on.

Returns

This method returns RemoveSponsorshipResult

    interface RemoveSponsorshipResult {
        /**
         * id of the collection
         */
        collectionId: number;
    }

Examples

    import { RemoveSponsorshipArguments } from '@unique-nft/substrate-client/tokens';

    const removeSponsorshipArgs: RemoveSponsorshipArguments = {
        address: '5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ',
        collectionId: 1,
    };
    
    await sdk.collections.removeSponsorship.submitWaitResult(removeSponsorshipArgs);
    
    const { sponsorship } = await sdk.collections.get({ collectionId: 1 });
    
    // `null`
    console.log(sponsorship);

    curl -X 'DELETE' \
    'https://rest.unique.network/opal/collection/sponsorship' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "address": "5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ",
    "collectionId": 1
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.removeSponsorship.submitWaitResult({
        address: '5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ',
        collectionId: 1,
    });
    
    const { parsed: { collectionId } } = result;
    
    console.log(`${collectionId} now works without sponsoring`);

Set collection sponsor

Overview

The collection owner can use this method to set the sponsor of the collection.

After that sponsor should confirm sponsorshipopen in new window and the sponsoring mechanism will be enabled.

The collection owner can also remove collection sponsoropen in new window.

Brief example

    import { SetCollectionSponsorArguments } from '@unique-nft/substrate-client/tokens/types';
    
    const setSponsorArgs: SetCollectionSponsorArguments = {
        address: '5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ',
        collectionId: 1,
        newSponsor: '5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp',
    };
    
    await sdk.collections.setCollectionSponsor.submitWaitResult(setSponsorArgs);

    const { sponsorship } = await sdk.collections.get({ collectionId: 1 });

    // `5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp - false`
    console.log(`${sponsorship?.address} - ${sponsorship?.isConfirmed}`);

Arguments

address: string — collection owner address

collectionId: number — collection id

newSponsor: string — address of new sponsor

Behaviour and errors

The method takes an address and sets it as a collection sponsor.

The signer must be an admin of the collection.

Be aware that if the address is already a sponsor of the given collection no exception will be thrown, but a fee will be charged.

Throws common errors on insufficient balance.

Returns

This method returns SetSponsorshipResult

    interface SetSponsorshipResult {
        /**
         * id of the collection
         */
        collectionId: number;
    
        /**
         * address of the sponsor (Substrate)
         */
        sponsor: Address;
    }

Examples

    import { SetCollectionSponsorArguments } from '@unique-nft/substrate-client/tokens';
    
    const setSponsorArgs: SetCollectionSponsorArguments = {
        address: '5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ',
        collectionId: 1,
        newSponsor: '5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp',
    };
    
    await sdk.collections.setCollectionSponsor.submitWaitResult(setSponsorArgs);
    
    const { sponsorship } = await sdk.collections.get({ collectionId: 1 });
    
    // `5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp - false`
    console.log(`${sponsorship?.address} - ${sponsorship?.isConfirmed}`);

    curl -X 'POST' \
    'https://rest.unique.network/opal/collection/sponsorship' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "address": "5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ",
    "collectionId": 1,
    "newSponsor": "5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp"
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.setSponsorship.submitWaitResult({
        address: '5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ',
        collectionId: 1,
        newSponsor: '5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp',
    });
    
    const { parsed: { sponsor, collectionId } } = result;
    
    console.log(`${sponsor} should now approve sponsorship of ${collectionId} collection`);

Statistics

Get account tokens of the collection

Overview

Returns an array of tokens, owned by address.

Brief example

import { AccountTokensResult } from '@unique-nft/substrate-client/tokens';

const tokensResult: AccountTokensResult = await sdk.tokens.getAccountTokens({
  collectionId: 1,
  address: '<address>',
});

const token = tokensResult.tokens[0];
const { collectionId, tokenId } = token;

Arguments

collectionId: number - ID of collection

address: string - address of tokens owner

Behaviour and errors

Returns

This method returns AccountTokensResult

import { TokenIdArguments } from '@unique-nft/substrate-client/tokens';

interface AccountTokensResult {
  tokens: TokenIdArguments[];
}

Examples

  import { AccountTokensArguments, AccountTokensResult } from '@unique-nft/substrate-client/tokens';
  
  const accountTokensArguments: AccountTokensArguments = {
      address: '5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp',
      collectionId: 1,
  };
  
  const tokensResult: AccountTokensResult = await sdk.tokens.getAccountTokens(accountTokensArguments);
  
  const token = tokensResult.tokens[0];
  const { collectionId, tokenId } = token;
  
  console.log(`${collectionId} - ${tokenId}`);
    curl -X 'GET' \
    'https://rest.unique.network/opal/token/account-tokens?address=5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp&collectionId=1'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const tokensResult = await sdk.tokens.accountTokens({
        address: '5DZGhQtBRyZpRgKX3VffhyBCSQD1KwU2yY1eAs99Soh7Dpwp',
        collectionId: 1,
    });

    const token = tokensResult.tokens[0];
    const { collectionId, tokenId } = token;
    
    console.log(`${collectionId} - ${tokenId}`);

Get collection tokens

Overview

This method gets tokens contained within a collection.

Brief example

import { CollectionTokensResult } from '@unique-nft/substrate-client/tokens/types';

const result: CollectionTokensResult = await sdk.collections.tokens({
  collectionId: 1,
});

Arguments

collectionId: number - Collection ID

Behaviour and errors

Returns

This method returns CollectionTokensResult - an array of token Ids contained within the passed collection.

interface CollectionTokensResult {
  ids: number[];
}

Examples

  import { CollectionTokensResult } from '@unique-nft/substrate-client/tokens';

  const tokensResult: CollectionTokensResult = await sdk.collections.tokens({
    collectionId: 1,
  });
  
  const { ids } = tokensResult;
  
  console.log(`ids - ${ids}`);
    curl -X 'GET' \
    'https://rest.unique.network/opal/collection/tokens?collectionId=1'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const tokensResult = await sdk.collections.tokens({
        collectionId: 1,
    });

    const { ids } = tokensResult;
    
    console.log(`ids - ${ids}`);

Get collection stats

Overview

Returns blockchain collection statistics:

  • The number of total collections created
  • The number of destroyed collections
  • The number of collections that are still alive

Brief example

import { GetStatsResult } from '@unique-nft/substrate-client/types';

const stats: GetStatsResult = await sdk.collections.getStats();

console.log(`stats: ${stats.created}, ${stats.destroyed}, ${stats.alive}`);

Arguments

No arguments required.

Returns

This method returns GetStatsResult

interface GetStatsResult {
  created: number;
  destroyed: number;
  alive: number;
}

Examples

  import { CollectionTokensResult } from '@unique-nft/substrate-client/tokens';

  const stats: GetStatsResult = await sdk.collections.getStats();
  
  const { created, destroyed, alive } = stats;
  
  console.log(`stats - ${created}, ${destroyed}, ${alive}`);
    curl -X 'GET' \
    'https://rest.unique.network/opal/collection/stats'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const stats = await sdk.collections.stats();

    const { created, destroyed, alive } = stats;

    console.log(`stats - ${created}, ${destroyed}, ${alive}`);

Last token id

Overview

The method gets the last generated token id.

Brief example

import { LastTokenIdResult } from '@unique-nft/substrate-client/types';

const lastTokenIdResult: LastTokenIdResult = await sdk.collections.lastTokenId({
  collectionId: 1,
});

const { tokenId } = lastTokenIdResult;

console.log(`tokenId - ${tokenId}`);

Arguments

collectionId: number - ID of collection

Returns

This method returns LastTokenIdResult

interface LastTokenIdResult {
  tokenId: number;
};

Examples

  import { LastTokenIdResult } from '@unique-nft/substrate-client/types';

  const lastTokenIdResult: LastTokenIdResult = await sdk.collections.lastTokenId({
    collectionId: 1,
  });
  
  const { tokenId } = lastTokenIdResult;
  
  console.log(`tokenId - ${tokenId}`);
    curl -X 'GET' \
    'https://rest.unique.network/opal/collection/last-token-id?collectionId=1'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const lastTokenId = await sdk.collections.lastTokenId();

    const { tokenId } = lastTokenId;

    console.log(`lastTokenId - ${tokenId}`);

Total supply

Overview

Returns the number of tokens in the collection.

Brief example

import {
  TotalSupplyResult,
} from '@unique-nft/substrate-client/tokens/types';

const result: TotalSupplyResult = await sdk.collections.totalSupply({
  collectionId: 1
});
const { totalSupply } = result;

console.log(`totalSupply - ${totalSupply}`);

Arguments

collectionId: number - ID of collection

blockHashAt?: number - hash of execution block, is optional

Returns

This method returns LastTokenIdResult

interface TotalSupplyResult {
  totalSupply: number;
}

Examples

  import {
    TotalSupplyResult,
  } from '@unique-nft/substrate-client/tokens/types';
  
  const result: TotalSupplyResult = await sdk.collections.totalSupply({
    collectionId: 1
  });
  const { totalSupply } = result;
  
  console.log(`totalSupply - ${totalSupply}`);
    curl -X 'GET' \
    'https://rest.unique.network/opal/collection/total-supply?collectionId=1'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.collections.totalSupply();

    const { totalSupply } = result;

    console.log(`totalSupply - ${totalSupply}`);

Token

Get allowance

Overview

Get the amount of token pieces approved to transfer

Brief example

import { AllowanceArguments } from '@unique-nft/substrate-client/tokens/types';

const AllowanceArgs: AllowanceArguments = {
    from: '<address>',
    to: '<address>',
    collectionId: 1,
    tokenId: 1,
};

const { isAllowed } = await sdk.tokens.allowance(AllowanceArgs);

Arguments

from: string - address from

to: string - address to

collectionId: number - ID of collection

tokenId: number - ID of token

at?: string — hash of execution block

Behaviour and errors

Throw errors:

  • Collection or token not found

Returns

This method returns AllowanceResult

type AllowanceResult = {
    isAllowed: boolean;
}

Examples

import { AllowanceArguments } from '@unique-nft/substrate-client/tokens/types';

const AllowanceArgs: AddToAllowListArguments = {
    from: '<address>',
    to: '<address>',
    collectionId: 1,
    tokenId: 1,
};

const { isAllowed } = await sdk.tokens.allowance(AllowanceArgs);
curl -X 'GET' \
  'http://localhost:3000/token/allowance?collectionId=1&tokenId=1&from=<address>&to=<address>' \
  -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const { isAllowed } = await sdk.tokens.allowance({
    address: '<your account address>',
    collectionId: '<ID of the collection>',
    newAdminId: '<valid address>'
});

Burn token

Overview

This method destroys a concrete instance of NFT or amount of Fungible token.

If the from parameter is specified, then the token is destroyed on behalf of the owner of the item.

Only the Collection Owner, Collection Admin, or Current NFT owner has permission to call this method.

Brief example

import '@unique-nft/substrate-client/tokens';
import { BurnTokenArguments } from '@unique-nft/substrate-client/tokens/types';
const burnItemArgs: BurnTokenArguments = {
  tokenId: 1,
  collectionId: 1,
};
const setResult = await sdk.tokens.burn.submitWaitResult(burnItemArgs);
const { collectionId, tokenId, address, value } = setResult.parsed;

Arguments

address: string - Signer address

collectionId: number - ID of the collection

tokenId: number - ID of NFT to burn

Optional Arguments

from?: string - The owner of the item on whose behalf the token is destroyed

value?: number - Amount to burn

  • Non-Fungible Mode: Ignored
  • Fungible Mode: Must specify the transferred amount
  • Re-Fungible Mode: Must specify transferred portion (between 0 and 1)

Behaviour and errors

Throw errors:

  • Collection or token not found
  • The Signer or from addresses do not have permission to call this method
  • If the owner of the collection (but not the owner of the token) wants to burn the token and the ownerCanDestroy flag is set to false. Check the set limits using the method effectiveCollectionLimitsopen in new window
  • Insufficient balance

Returns

This method returns BurnTokenResult

  interface BurnTokenResult {
    collectionId: number;
    tokenId: number;
    address: Address;
    value: number;
  }

Examples

import '@unique-nft/substrate-client/tokens';
import { BurnTokenArguments } from '@unique-nft/substrate-client/tokens/types';
const burnItemArgs: BurnTokenArguments = {
  tokenId: 1,
  collectionId: 1,
};
const setResult = await sdk.tokens.burn.submitWaitResult(burnItemArgs);
const { collectionId, tokenId, address, value } = setResult.parsed;

  curl -X 'DELETE' \
    'http://rest.unique.network/opal/token?use=Build&withFee=false&verify=false' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "collectionId": 183,
    "tokenId": 5,
    "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
  }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.tokens.burn.submitWaitResult({
      "collectionId": 1,
      "tokenId": 1,
      "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
    });
    
    const { parsed: { collectionId, tokenId } } = result;
    
    console.log(`burned token ${tokenId} collection ${collectionId}`);

Create multiple tokens

Overview

This method creates multiple items in a collection.

Only the Collection Owner, Collection Admin and addresses from the Allow List (if Allow List is enabled and MintPermission is enabled) can mint tokens.

Brief example

import { CreateMultipleTokensArguments } from '@unique-nft/substrate-client/tokens';

import {
  UniqueCollectionSchemaToCreate,
  COLLECTION_SCHEMA_NAME,
  AttributeType,
} from '@unique-nft/substrate-client/tokens';

const createTokenArgs: CreateTokenNewArguments = {
  address: '<your account address>',
  collectionId: 123,
  data: [{
    encodedAttributes: {
      '0': 0,
      '1': [0],
      '2': 'foo_bar',
    },
    image: {
      ipfsCid: '<valid_ipfs_cid>',
    },
  }],
};

const result = await sdk.tokens.createMultiple.submitWaitResult(createArgs);
const [{ collectionId, tokenId }] = result.parsed;

const token = await sdk.tokens.get({ collectionId, tokenId });

Arguments

address: Address - The address of the collection owner

collectionId: number - Collection id

data: Array<UniqueTokenToCreate & { owner?: string} > - The content of the tokens:

Behaviour and errors

Throw errors:

  • Collection not found
  • The signer must be Collection Owner or Collection Admin or in Allow List of the collection
  • The collection is set TokenLimit and creating a new token will exceed the token limit
  • Insufficient balance

Returns

This method returns TokenIdArguments[]

interface TokenIdArguments {
  collectionId: number;
  tokenId: number;
}

Examples

import { CreateMultipleTokensArguments } from '@unique-nft/substrate-client/tokens';

import {
  UniqueCollectionSchemaToCreate,
  COLLECTION_SCHEMA_NAME,
  AttributeType,
} from '@unique-nft/substrate-client/tokens';

const createTokenArgs: CreateTokenNewArguments = {
  address: '<your account address>',
  collectionId: 123,
  data: [{
    encodedAttributes: {
      '0': 0,
      '1': [0],
      '2': 'foo_bar',
    },
    image: {
      ipfsCid: '<valid_ipfs_cid>',
    },
  }],
};

const result = await sdk.tokens.createMultiple.submitWaitResult(createArgs);
const [{ collectionId, tokenId }] = result.parsed;

const token = await sdk.tokens.get({ collectionId, tokenId });

  curl -X 'POST' \
    'http://rest.unique.network/opal/token/create-multiple?use=Build&withFee=false&verify=false' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
    "collectionId": 183,
    "data": [
      {
        "image": {
          "url": "https://ipfs.unique.network/ipfs/QmcAcH4F9HYQtpqKHxBFwGvkfKb8qckXj2YWUrcc8yd24G/image1.png"
        }
      },
      {
        "image": {
          "url": "https://ipfs.unique.network/ipfs/QmcAcH4F9HYQtpqKHxBFwGvkfKb8qckXj2YWUrcc8yd24G/image2.png"
        }    
      }
    ]
  }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
  const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
  
  const result = await sdk.tokens.createMultiple.submitWaitResult({
    "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
    "collectionId": 183,
    "data": [
      {
        "image": {
          "url": "https://ipfs.unique.network/ipfs/QmcAcH4F9HYQtpqKHxBFwGvkfKb8qckXj2YWUrcc8yd24G/image1.png"
        }
      },
      {
        "image": {
          "url": "https://ipfs.unique.network/ipfs/QmcAcH4F9HYQtpqKHxBFwGvkfKb8qckXj2YWUrcc8yd24G/image2.png"
        }
      }
    ]
  });
  
  const { parsed } = result;
  
  console.log(`minted ${parsed.length} tokens`);

Create token (mint)

Overview

This method creates a concrete instance of NFT collection.

Collection can be created with Create collectionopen in new window method.

Only the Collection Owner, Collection Admin and addresses from the Allow List (if Allow List is enabled and MintPermission is enabled) can mint token.

The owner of the token is specified in the owner field. If the owner field is not set, then the Signer becomes the owner of the token.

Brief example

import { CreateTokenNewArguments } from '@unique-nft/substrate-client/tokens/types';

import {
  UniqueCollectionSchemaToCreate,
  COLLECTION_SCHEMA_NAME,
  AttributeType,
} from '@unique-nft/substrate-client/tokens';

const createTokenArgs: CreateTokenNewArguments = {
  address: '<your account address>',
  collectionId: 123,
  data: {
    encodedAttributes: {
      '0': 0,
      '1': [0],
      '2': 'foo_bar',
    },
    image: {
      ipfsCid: '<valid_ipfs_cid>',
    },
  },
};

const result = await sdk.tokens.create.submitWaitResult(createArgs);
const { collectionId, tokenId } = result.parsed;

const token = await sdk.tokens.get({ collectionId, tokenId });   

Arguments

address: string - The address of collection owner

collectionId: number - Collection id

owner?: string - The address of token owner (optional)

data: UniqueTokenToCreate - The content of the token is stored in the fields of the object:

  • name?: LocalizedStringWithDefault*

  • description?: LocalizedStringWithDefault*

  • image: GenericInfixUrlOrCidWithHash** - Token image (url, urlInfix or ipfsCid)

  • imagePreview?: GenericInfixUrlOrCidWithHash**

  • video?: GenericInfixUrlOrCidWithHash**

  • audio?: GenericInfixUrlOrCidWithHash**

  • spatialObject?: GenericInfixUrlOrCidWithHash**

  • encodedAttributes?: EncodedTokenAttributes - Token attributes

* Type LocalizedStringWithDefault

{
  _: string;
  [K: string]: string;
}

* Type GenericInfixUrlOrCidWithHash

  { urlInfix?: string; hash?: string | null }
  | { url?: string; hash?: string | null }
  | { ipfsCid?: string; hash?: string | null };

Behaviour and errors

Throw errors:

  • Collection not found
  • The signer must be Collection Owner or Collection Admin or in Allow List of the collection
  • The collection is set TokenLimit and creating a new token will exceed the token limit (TokenLimit includes all the tokens that have been minted, even if some of them were burned after)
  • Insufficient balance

Returns

This method returns TokenIdArguments

  interface TokenIdArguments extends CollectionIdArguments {
    tokenId: number;
  }   

Examples

import { CreateTokenNewArguments } from '@unique-nft/substrate-client/tokens/types';

import {
    UniqueCollectionSchemaToCreate,
    COLLECTION_SCHEMA_NAME,
    AttributeType,
} from '@unique-nft/substrate-client/tokens';

const createTokenArgs: CreateTokenNewArguments = {
    address: '<your account address>',
    collectionId: 123,
    data: {
        encodedAttributes: {
            '0': 0,
            '1': [0],
            '2': 'foo_bar',
        },
        image: {
            ipfsCid: '<valid_ipfs_cid>',
        },
    },
};

const result = await sdk.tokens.create.submitWaitResult(createArgs);
const { collectionId, tokenId } = result.parsed;

const token = await sdk.tokens.get({ collectionId, tokenId });

  curl -X 'POST' \
    'http://rest.unique.network/opal/token?use=Build&withFee=false&verify=false' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
    "collectionId": 183,
    "data": {
      "image": {
        "url": "https://ipfs.unique.network/ipfs/QmcAcH4F9HYQtpqKHxBFwGvkfKb8qckXj2YWUrcc8yd24G/image1.png"
      },
      "name": {
        "_": "Hello!"
      },
      "description": {
        "_": "Hello!"
      }
    }
  }'

# then we sign, then we call

    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.tokens.create.submitWaitResult({
      "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
      "collectionId": 183,
      "data": {
        "image": {
          "url": "https://ipfs.unique.network/ipfs/QmcAcH4F9HYQtpqKHxBFwGvkfKb8qckXj2YWUrcc8yd24G/image1.png"
        },
        "name": {
          "_": "Hello!"
        },
        "description": {
          "_": "Hello!"
        }
      }
    });
    
    const { parsed: { collectionId, tokenId } } = result;
    
    console.log(`created token ${tokenId} in collection ${collectionId}`);

Delete token properties

Overview

Deletes properties (see Token propertiesopen in new window) from a token.

Brief example

  const args: DeleteTokenPropertiesArguments = {
    address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
    collectionId: 1,
    tokenId: 1,
    propertyKeys: ['foo', 'bar'],
  };
  
  const result = await sdk.tokens.deleteProperties.submitWaitResult(args);
  
  console.log(result.parsed);

Arguments

address: string - Signer, the address of the Collection Owner, Collection Admin or Token Owner

collectionId: number - Collection id

tokenId: number - Token id

propertyKeys: string[] - Array of properties keys

Behaviour and errors

Throw errors:

Returns

This method returns DeleteTokenPropertiesResult

  type DeleteTokenPropertiesResult = {
    properties: Array<{
      collectionId: number;
      tokenId: number;
      propertyKey: string;
    }>;
  }

Examples

  const args: DeleteTokenPropertiesArguments = {
    address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
    collectionId: 1,
    tokenId: 1,
    propertyKeys: ['foo', 'bar'],
  };
  
  const result = await sdk.tokens.deleteProperties.submitWaitResult(args);
  
  console.log(result.parsed);

  curl -X 'DELETE' \
    'http://rest.unique.network/opal/token/properties?use=Build&withFee=false&verify=false' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "address": "5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX",
    "collectionId": 1,
    "tokenId": 1,
    "propertyKeys": ['\''foo'\'', '\''bar'\'']
  }'
  
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const { parsed: { properties } } = await sdk.tokens.deleteProperties.submitWaitResult({
      "address": "5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX",
      "collectionId": 1,
      "tokenId": 1,
      "propertyKeys": [
        "foo",
        "bar"
      ]
    });
    
    console.log(`removed properties  ${properties.map(t => t.propertyKey).join()}`);

Set token properties

Overview

Sets (creates or overwrites) propertiesopen in new window for token.

Brief example

  const args: SetTokenPropertiesArguments = {
    address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
    collectionId: 1,
    tokenId: 1,
    properties: [
      {
        key: 'foo',
        value: 'bar',
      },
    ],
  };
  
  const result = await sdk.tokens.setProperties.submitWaitResult(args);
  
  console.log(result.parsed);

Arguments

address: string - Signer, the address of the Collection Owner, Collection Admin or Token Owner

collectionId: number - Collection id

tokenId: number - Token id

properties: Array<{ key: string; value: string; }> - Array of properties

Behaviour and errors

Throw errors:

Returns

This method returns SetTokenPropertiesResult

  type SetTokenPropertiesResult = {
    properties: Array<{
      collectionId: number;
      tokenId: number;
      propertyKey: string;
    }>;
  };

Examples

  const args: SetTokenPropertiesArguments = {
    address: '5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX',
    collectionId: 1,
    tokenId: 1,
    properties: [
      {
        key: 'foo',
        value: 'bar',
      },
    ],
  };
  
  const result = await sdk.tokens.setProperties.submitWaitResult(args);
  
  console.log(result.parsed);

    curl -X 'POST' \
      'https://rest.unique.network/opal/token/properties?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX",
      "collectionId": 1,
      "tokenId": 1,
      "properties": [
        {
          "key": "foo",
          "value": "bar"
        }
      ]
    }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

    const { parsed: { properties } } = await sdk.tokens.setProperties.submitWaitResult({
      "address": "5HNid8gyLiwocM9PyGVQetbWoBY76SrixnmjTRtewgaicKRX",
      "collectionId": 1,
      "tokenId": 1,
      "properties": [
        {
          "key": "foo",
          "value": "bar"
        }
      ]
    });

    console.log(`the values of the keys ${properties.map(t => t.propertyKey).join()} are set`);

Get token

Overview

Returns information about the NFT of a specific collection.

Brief example

const token = await sdk.tokens.get({
  collectionId: 2,
  tokenId: 1,
});
    
const {
    collectionId,
    tokenId,
    owner,
    image,
    attributes,
} = token;

Arguments

collectionId: number — collection id

tokenId: number — token id

Behaviour and errors

Throw errors:

  • Collection not found (not created or destroyed)
  • Token not found (not created or burned)
  • Check path chain (CHAIN_WS_URL)

Returns

This method returns TokenByIdResult

type TokenByIdResult = Omit<UniqueTokenDecoded, 'owner'> & {
  owner: Address;
};

Examples

const token = await sdk.tokens.get({
  collectionId: 2,
  tokenId: 1,
});
    
const {
    collectionId,
    tokenId,
    owner,
    image,
    attributes,
} = token;
curl -X 'GET' \
  'https://rest.unique.network/opal/token?collectionId=2&tokenId=1' \
  -H 'accept: application/json'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

    const result = await sdk.tokens.get({
      collectionId: 2,
      tokenId: 1,
    });
    
    const { tokenId, owner } = result;
    
    console.log(`token ${tokenId} is owned by address ${owner}`);

Get token owner

Overview

This method allows you to get the current NFT owner.

The initial owner of the token is set to the address that signed the token creation extrinsic.

You can change the owner of the token using the transfer tokenopen in new window method.

Brief example

import {
  TokenOwnerArguments,
  TokenOwnerResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenOwnerArguments = {
  collectionId: 1,
  tokenId: 1,
  // blockHashAt: '0xff19c2457fa4d7216cfad444615586c4365250e7310e2de7032ded4fcbd36873'
};

const result: TokenOwnerResult = await sdk.tokens.tokenOwner(
  args,
);

Arguments

collectionId: number — collection ID

tokenId: number — token ID

blockHashAt?: string — hash of execution block

Behaviour and errors

Throw errors:

  • Collection not found (not created or destroyed)
  • Token not found (not created or burned)
  • Check path chain (CHAIN_WS_URL)

Returns

The method returns TokenOwnerResult

type TokenOwnerResult = { owner: Address }

Examples

import {
  TokenOwnerArguments,
  TokenOwnerResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenOwnerArguments = {
  collectionId: 1,
  tokenId: 1,
  // blockHashAt: '0xff19c2457fa4d7216cfad444615586c4365250e7310e2de7032ded4fcbd36873'
};

const result: TokenOwnerResult = await sdk.tokens.tokenOwner(
  args,
);

    curl -X 'GET' \
  'https://rest.unique.network/opal/token/owner?collectionId=1&tokenId=1' \
  -H 'accept: application/json'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const { owner } = await sdk.tokens.owner({
      collectionId: 1,
      tokenId: 1,
    });
    
    console.log(`token owner ${owner}`);

Token properties

Overview

Gets an array of token properties. Property keys must be in the tokenPropertyPermissions list (see Set token property permissionsopen in new window).

Brief example

import {
  TokenPropertiesArguments,
  TokenPropertiesResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenPropertiesArguments = {
  collectionId: 1,
  tokenId: 1,
  // propertyKeys: ['foo', 'bar'],
};

const result: TokenPropertiesResult = await sdk.tokens.properties(args);

Arguments

collectionId: number - Collection ID

tokenId: number - Token ID

Additional arguments

propertyKeys?: string[] - Array of property keys

Behaviour and errors

Throw errors:

  • Collection or token not found

Returns

This method returns TokenPropertiesResult

type TokenPropertiesResult = {
  properties: Array<{
    key: string;
    value: string;
  }>;
};

Examples

import {
  TokenPropertiesArguments,
  TokenPropertiesResult,
} from '@unique-nft/substrate-client/tokens/types';

const args: TokenPropertiesArguments = {
  collectionId: 1,
  tokenId: 1,
  // propertyKeys: ['foo', 'bar'],
};

const result: TokenPropertiesResult = await sdk.tokens.properties(args);
  curl -X 'GET' \
    'https://rest.unique.network/opal/token/properties?collectionId=1&tokenId=1' \
    -H 'accept: application/json'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

    const { properties } = await sdk.tokens.properties({
      collectionId: 1,
      tokenId: 1,
    });

Transfer token

Overview

This method changes the ownership of the token.

Only the Collection Owner, Collection Admin, or Current NFT owner has permission to call this method.

The Current NFT owner can be found using Get token owneropen in new window method.

Brief example

import { TransferArguments } from '@unique-nft/substrate-client/tokens';

const args: TransferArguments = {
  address: '<address>',
  to: '<address>',
  collectionId: 1,
  tokenId: 1,
};

const result = await sdk.tokens.transfer.submitWaitResult(args);

console.log(result.parsed);

Arguments

address: string - Signer address

to: string - Address of token recipient

collectionId: number - Collection id

tokenId: number - Token id

Optional Arguments

from: string - Address that owns token (default is signer address)

value: number - Amount to transfer (default is 1):

  • Non-Fungible Mode: Ignored
  • Fungible Mode: Must specify transferred amount
  • Re-Fungible Mode: Must specify transferred portion (between 0 and 1)

Behaviour and errors

Throw errors:

  • Collection or token not found
  • Signer is not a Collection Owner, Collection Admin, or Current NFT owner
  • The restrictions set by the transfersEnabled or ownerCanTransfer flags apply. Check the set limits using the method effectiveCollectionLimitsopen in new window
  • Insufficient balance

Returns

This method returns TransferResult

interface TransferResult {
  collectionId: number;
  tokenId: number;
  from: Address;
  to: Address;
  value: number;
}

Examples

import { TransferArguments } from '@unique-nft/substrate-client/tokens';

const args: TransferArguments = {
  address: '<address>',
  to: '<address>',
  collectionId: 1,
  tokenId: 1,
};

const result = await sdk.tokens.transfer.submitWaitResult(args);

console.log(result.parsed);

  curl -X 'PATCH' \
    'http://rest.unique.network/opal/token/transfer?use=Build&withFee=false&verify=false' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "collectionId": 183,
    "tokenId": 1,
    "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
    "to": "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"
  }'
    
    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.tokens.transfer.submitWaitResult({
      "collectionId": 183,
      "tokenId": 1,
      "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
      "to": "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"
    });
    
    const { parsed: { collectionId, tokenId, to } } = result;
    
    console.log(`${to} is the new owner of token ${tokenId} from collection ${collectionId}`);

Other

Approve

Overview

Set, change, or remove approved address to transfer the ownership of the token.

Brief example

import { ApproveArguments } from '@unique-nft/substrate-client/tokens/types';

const approveArgs: ApproveArguments = {
    address: '<Signer address>',
    spender: '<Account address for whom token will be approved>',
    collectionId: '<ID of the collection>',
    tokenId: '<ID of the token>',
    isApprove: true
};

const result = await sdk.tokens.approve.submitWaitResult(approveArgs);
const { collectionId, tokenId } = result.parsed;

Arguments

address: string - Signer address

spender: string - Address that is approved to transfer this token

collectionId: number - Collection id

tokenId: number - Token id

isApprove: boolean - Must be true (for approval) or false (for disapproval)

Behaviour and errors

Throw errors:

  • Collection ot token not found
  • Signer is not Collection Owner, Collection Admin or Token Owner

Returns

This method returns ApproveResult

interface ApproveResult {
    collectionId: number;
    tokenId: number;
}

Examples

import { ApproveArguments } from '@unique-nft/substrate-client/tokens/types';

const approveArgs: ApproveArguments = {
    address: '<Signer address>',
    spender: '<Account address for whom token will be approved>',
    collectionId: '<ID of the collection>',
    tokenId: '<ID of the token>',
    isApprove: true
};

const result = await sdk.tokens.approve.submitWaitResult(approveArgs);
const { collectionId, tokenId } = result.parsed;
    curl -X 'POST' \
      'http://localhost:3000/v1/tokens/approve?use=Build&withFee=false&verify=false' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "address": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
      "spender": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
      "collectionId": 1,
      "tokenId": 1,
      "isApprove": true
    }'

    # then we sign, then we call
    
    curl -X 'POST' \
    'https://rest.unique.network/opal/extrinsic/submit' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
    "signerPayloadJSON": { *from previous response* },
    "signature": "0x_your_signature_in_hex"
    }'
    const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });
    
    const result = await sdk.tokens.approve.submitWaitResult({
        address: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty',
        spender: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty',
        collectionId: 1,
        tokenId: 1,
        isApprove: true
    });
    
    const { collectionId, tokenId } = result.parsed;

Token exists

Overview

Checks if token exists in collection. Returns true or false.

Brief example

const { isExists } = await sdk.tokens.exists({ collectionId: 1, tokenId: 1 });

Arguments

collectionId: number - ID of collection

tokenId: number - ID of token

at: string - optional - Hash of execution block

Behaviour and errors

Throw errors:

  • Collection or token not found

Returns

This method returns TokenExistsResult

type TokenExistsResult = {
    isExists: boolean;
}

Examples

const { isExists } = await sdk.tokens.exists({ collectionId: 1, tokenId: 1 });
    curl -X 'GET' \
      'https://rest.unique.network/opal/v1/tokens/exists?collectionId=1&tokenId=1' \
      -H 'accept: application/json'
const sdk = new Sdk({ baseUrl: 'https://rest.unique.network/opal' });

const { isExists } = await sdk.tokens.exists({
    collectionId: 1,
    tokenId: 1
});