Scaffolded TypeScript Token Project for ERC-1155

Blockchain App Builder takes the input from your token specification file and generates a fully-functional scaffolded chaincode project.

The project automatically generates token lifecycle classes and functions, including CRUD and non-CRUD methods. Validation of arguments, marshalling/unmarshalling, and transparent persistence capability are all supported automatically.

For information on the scaffolded project and methods that are not directly related to tokens, see Scaffolded TypeScript Chaincode Project.

Model

Every tokenized model class extends the OchainModel class. Transparent Persistence Capability, or simplified ORM, is captured in the OchainModel class. The following model shows a whole non-fungible token.

import * as yup from "yup";
import { Id, Mandatory, Validate, Default, Embedded, Derived, ReadOnly } from "../../lib/decorators";
import { OchainModel } from "../../lib/ochain-model";
import { STRATEGY } from "../../lib/utils";
import { EmbeddedModel } from "../../lib/ochain-embedded-model";

export class ArtCollectionMetadata extends EmbeddedModel<ArtCollectionMetadata> {
  @Validate(yup.string())
  public painting_name: string;

  @Validate(yup.string())
  public description: string;

  @Validate(yup.string())
  public image: string;

  @Validate(yup.string())
  public painter_name: string;

}
    
@Id("tokenId")
export class ArtCollection extends OchainModel<ArtCollection> {
  public readonly assetType = "otoken";

  @Mandatory()
  @Validate(
    yup
      .string()
      .required()
      .matches(/^[A-Za-z0-9][A-Za-z0-9_-]*$/)
      .max(16)
  )
  public tokenId: string;

  @ReadOnly("artcollection")
  public tokenName: string;

  @Validate(yup.string().trim().max(256))
  public tokenDesc: string;


  @ReadOnly("erc1155+")
  public tokenStandard: string;

  @ReadOnly("nonfungible")
  public tokenType: string;

  @ReadOnly("whole")
  public tokenUnit: string;

  @ReadOnly(["indivisible","singleton","mintable","transferable","burnable","roles"])
  public behaviors: string[];

  @ReadOnly({ minter_role_name: "minter" })
  public roles: object;

  @ReadOnly({ max_mint_quantity: 20000 })
  public mintable: object;

  @Validate(yup.string())
  public owner: string;

  @Validate(yup.string())
  public createdBy: string;

  @Validate(yup.string())
  public transferredBy: string;

  @Validate(yup.string())
  public creationDate: string;

  @Validate(yup.string())
  public transferredDate: string;

  @Validate(yup.bool())
  public isBurned: boolean;

  @Validate(yup.string())
  public burnedBy: string;

  @Validate(yup.string())
  public burnedDate: string;

  @Mandatory()
  @Validate(yup.string().required().max(2000)) 
  public tokenUri: string;

  @Embedded(ArtCollectionMetadata)
  public tokenMetadata: ArtCollectionMetadata;

  @Validate(yup.number())
  public price: number;
  
  @Validate(yup.boolean())
  public on_sale_flag: boolean;
  
}

@Id("tokenId")
export class Loyalty extends OchainModel<Loyalty> {
  public readonly assetType = "otoken";

  @Mandatory()
  @Validate(
    yup
      .string()
      .required()
      .matches(/^[A-Za-z0-9][A-Za-z0-9_-]*$/)
      .max(16)
  )
  public tokenId: string;

  @ReadOnly("loyalty")
  public tokenName: string;

  @Validate(yup.string().trim().max(256))
  public tokenDesc: string;

  @ReadOnly("erc1155+")
  public tokenStandard: string;

  @ReadOnly("fungible")
  public tokenType: string;

  @ReadOnly("fractional")
  public tokenUnit: string;

  @ReadOnly(["divisible","mintable","transferable","burnable","roles"])
  public behaviors: string[];

  @ReadOnly({ minter_role_name: "minter" })
  public roles: object;

  @ReadOnly({ max_mint_quantity: 10000 })
  public mintable: object;

  @ReadOnly({ decimal: 2 })
  public divisible: object;

  @Validate(yup.string())
  public currency_name: string;
  
  @Validate(yup.number())
  public token_to_currency_ratio: number;
  
}
The following model shows a fractional non-fungible token.
export class RealEstatePropertyMetadata extends EmbeddedModel<RealEstatePropertyMetadata> {
  @Validate(yup.string())
  public propertyType: string;
  
  @Validate(yup.string())
  public propertyName: string;
  
  @Validate(yup.string())
  public propertyAddress: string;
  
  @Validate(yup.string())
  public propertyImage: string;
  
}
    
@Id("tokenId")
export class RealEstateProperty extends OchainModel<RealEstateProperty> {
  public readonly assetType = "otoken";

  @Mandatory()
  @Validate(
    yup
      .string()
      .required()
      .matches(/^[A-Za-z0-9][A-Za-z0-9_-]*$/)
      .max(16)
  )
  public tokenId: string;

  @ReadOnly("realestateproperty")
  public tokenName: string;

  @Validate(yup.string().trim().max(256))
  public tokenDesc: string;

  @ReadOnly("erc1155+")
  public tokenStandard: string;

  @ReadOnly("nonfungible")
  public tokenType: string;

  @ReadOnly("fractional")
  public tokenUnit: string;

  @ReadOnly(["divisible","mintable","transferable","roles"])
  public behaviors: string[];

  @ReadOnly({ minter_role_name: "minter" })
  public roles: object;

  @ReadOnly({ max_mint_quantity: 0 })
  public mintable: object;

  @Validate(yup.number().positive())
  public quantity: number;

  @Validate(yup.string())
  public createdBy: string;

  @Validate(yup.string())
  public creationDate: string;

  @ReadOnly({ decimal: 0 })
  public divisible: object;

  @Validate(yup.bool())
  public isBurned: boolean;

  @Mandatory()
  @Validate(yup.string().required().max(2000))
  public tokenUri: string;

  @Embedded(RealEstatePropertyMetadata)
  public tokenMetadata: RealEstatePropertyMetadata;

  @Validate(yup.number())
  public propertySellingPrice: number;
  
  @Validate(yup.number())
  public propertyRentingPrice: number;
  
}

Controller

The main controller class extends the OchainController class. There is only one main controller.

export class DigiCurrCCController extends OchainController{

You can create any number of classes, functions, or files, but only those methods that are defined within the main controller class are invokable. The other methods are hidden.

You can use the token SDK methods to write custom methods for your business application.

Automatically Generated Token Methods

Blockchain App Builder automatically generates methods to support tokens and token life cycles. You can use these methods to initialize tokens, manage roles and accounts, and complete other token lifecycle tasks without any additional coding. Controller methods must have a @Validator(...params) decorator to be invokable.

Methods for Access Control Management

isTokenAdmin
This method returns the Boolean value true if the caller of the function is a Token Admin, otherwise it returns false. This method can be called only by a Token Admin of the chaincode.
@GetMethod()
@Validator(yup.string(), yup.string())
public async getAccountDetailsByUser(orgId: string, userId: string) {
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.getAccountDetailsByUser", "TOKEN", {
    accountId: userAccountId,
  });
  return await this.Ctx.ERC1155Account.getAccountDetailsByUser(orgId, userId);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • The method returns true if the caller is a Token Admin, otherwise it returns false.
Return Value Example:
{"result": true}
addTokenAdmin
This method adds a user as a Token Admin of the chaincode. This method can be called only by a Token Admin of the chaincode.
@Validator(yup.string(), yup.string())
public async addTokenAdmin(orgId: string, userId: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ADMIN.addAdmin", "TOKEN");
  return await this.Ctx.ERC1155Admin.addAdmin(orgId, userId);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a message that includes details of the user who was added as a Token Admin of the chaincode.
Return Value Example:
{"msg":"Successfully added Admin (OrgId: appDev, UserId: user1)"}
removeTokenAdmin
This method removes a user as a Token Admin of the chaincode. This method can be called only by a Token Admin of the chaincode. You cannot remove yourself as a Token Admin.
@Validator(yup.string(), yup.string())
public async removeTokenAdmin(orgId: string, userId: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ADMIN.removeAdmin", "TOKEN");
  return await this.Ctx.ERC1155Admin.removeAdmin(orgId, userId);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a message that includes details of the user who was removed as a Token Admin of the chaincode.
Return Value Example:
{"msg": "Successfully removed Admin (OrgId: appDev, UserId: user1)"}
getAllTokenAdmins
This method returns a list of all users who are a Token Admin of the chaincode. This method can be called only by a Token Admin of the chaincode.
@GetMethod()
@Validator()
public async getAllTokenAdmins() {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ADMIN.getAllAdmins", "TOKEN");
  return await this.Ctx.ERC1155Admin.getAllAdmins();
}
Parameters:
  • none
Returns:
  • On success, an admins array in JSON format that contains orgId and userId objects.
Return Value Example:
{
  "admins": [
    {
      "orgId": "appdev",
      "userId": "user2"
    },
    {
      "orgId": "appdev",
      "userId": "user1"
    }
  ]
}

Methods for Token Configuration Management

init
This method is called when the chaincode is instantiated. Every Token Admin is identified by the userId and orgId information in the adminList parameter. The userId is the user name or email ID of the instance owner or the user who is logged in to the instance. The orgId is the membership service provider (MSP) ID of the user in the current network organization. The adminList parameter is mandatory the first time you deploy the chaincode. If you are upgrading the chaincode, pass an empty list ([]). If you are the user who initially deployed the chaincode, you can also specify new admins in the adminList parameter when you are upgrading the chaincode. Any other information in the adminList parameter is ignored during upgrades.
@Validator(yup.array().of(yup.object()).nullable())
public async init(adminList: ERC1155TokenAdminAsset[]) {
  await this.Ctx.ERC1155Admin.initAdmin(adminList);
  await this.Ctx.ERC1155Token.saveClassInfo(<1st NFT Token Name>);
  await this.Ctx.ERC1155Token.saveClassInfo(<2nd NFT Token Name>);
  .
  .
  await this.Ctx.ERC1155Token.saveClassInfo(<nth NFT Token Name>);
  // await this.Ctx.ERC1155Token.saveDeleteTransactionInfo();
  return;
}
Parameters:
  • adminList array – An array of {orgId, userId} information that specifies the list of token admins. The adminList array is a mandatory parameter.
create<Token Name>Token
This method creates tokens. Every token that is defined has its own create method. For fungible tokens, this method can be called only by a Token Admin of the chaincode. For non-fungible tokens, if the minter role is defined in the specification file, any user with the minter role can call this method to create an NFT. If the minter role is not defined, any user can use this method to create (mint) NFTs. The user who calls this method becomes the owner of the NFT.
Fungible Tokens:
@Validator(<Token Class>)
public async create<Token Name>Token(tokenAsset: <Token Class>) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.save", "TOKEN");
  return await this.Ctx.ERC1155Token.save(tokenAsset);
}
Non-Fungible Tokens:
@Validator(<Token Class>, yup.number())
public async create<Token Name>Token(tokenAsset: <Token Class>, quantity: number) {
  return await this.Ctx.ERC1155Token.save(tokenAsset, quantity);
}
Parameters:
  • tokenAsset: <Token Class> – The token asset. The properties of the asset are defined in the model file.
  • quantity: number – For non-fungible tokens only, the number of tokens to mint. The only supported value for this parameter is 1.
Returns:
  • On success, the token asset in JSON format, which includes the following information, depending on the token type.
  • tokenMetadata – JSON information that describes the token.
  • createdBy – The account ID of the caller, who is the user minting the token. This property cannot be edited.
  • creationDate – The time stamp of the minting transaction. This property cannot be edited.
  • isBurned – This property indicates whether the token is burned. This property cannot be edited.
  • tokenName – The name of the token. This property cannot be edited.
  • tokenDesc – The description of the token.
  • symbol – The symbol of the token. This property cannot be edited.
  • tokenStandard – The standard of the token. This property cannot be edited.
  • tokenType – The type of the token (fungible or non-fungible). This property cannot be edited.
  • tokenUnit – The unit of the token (whole or fractional). This property cannot be edited.
  • behaviors – A list of token behaviors. This property cannot be edited.
  • mintable – The properties related to minting. The max_mint_quantity value defines the maximum number of tokens that can be created for the token class.
  • owner – The account ID of the current owner, who is the caller of the method.
  • tokenUri – The URI of the token.
  • quantity – The quantity of the token.
Return Value Example (Whole NFT):
{
    "tokenMetadata": {
        "paintingName": "monalisa",
        "description": "monalisa painting",
        "image": "image link",
        "painterName": "Leonardo da Vinci"
    },
    "assetType": "otoken",
    "quantity": 1,
    "tokenId": "artnft",
    "tokenName": "artcollection",
    "tokenDesc": "artcollection nft",
    "tokenStandard": "erc1155+",
    "tokenType": "nonfungible",
    "tokenUnit": "whole",
    "behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 500
    },
    "owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "creationDate": "2022-12-29T04:08:35.000Z",
    "isBurned": false,
    "tokenUri": "tu",
    "price": 10000,
    "onSaleFlag": false
}
Return Value Example (Fungible Token):
{
    "assetType": "otoken",
    "tokenId": "Loyalty",
    "tokenName": "loyalty",
    "tokenDesc": "Token Description",
    "tokenStandard": "erc1155+",
    "tokenType": "fungible",
    "tokenUnit": "fractional",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 10000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "Dollar"
}
Return Value Example (Fractional NFT):
{
    "tokenMetadata": {
        "painting_name": "paint",
        "description": "Painting Description"
    },
    "assetType": "otoken",
    "tokenId": "realEstate",
    "tokenName": "realestate",
    "tokenDesc": "Token Description",
    "tokenStandard": "erc1155+",
    "tokenType": "nonfungible",
    "tokenUnit": "fractional",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 20000
    },
    "quantity": 100,
    "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "creationDate": "2023-06-14T04:20:14.000Z",
    "divisible": {
        "decimal": 2
    },
    "isBurned": false,
    "tokenUri": "www.realestate.example.com",
    "price": 1000,
    "on_sale_flag": true
}
update<Token Name>Token
This method updates tokens. Every token that is defined has its own update method. You cannot update token metadata or the token URI of non-fungible tokens. For fungible tokens, this method can be called only by a Token Admin of the chaincode. For non-fungible tokens, this method can be called only by the token owner.
Fungible Tokens:
@Validator(<Token Class>)
public async update<Token Name>Token(tokenAsset: <Token Class>) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.update", "TOKEN");
  return await this.Ctx.ERC1155Token.update(tokenAsset);
}
Non-Fungible Tokens:
@Validator(<Token Class>)
public async update<Token Name>Token(tokenAsset: <Token Class>) {
  return await this.Ctx.ERC1155Token.update(tokenAsset);
}
Parameters:
  • tokenAsset: <Token Class> – The token asset. The properties of the asset are defined in the model file.
Returns:
  • On success, the updated token asset in JSON format.
Return Value Example (Whole NFT):
{
    "tokenMetadata": {
        "paintingName": "monalisa",
        "description": "monalisa painting",
        "image": "image link",
        "painterName": "Leonardo da Vinci"
    },
    "assetType": "otoken",
    "quantity": 1,
    "tokenId": "artnft",
    "tokenName": "artcollection",
    "tokenDesc": "artcollection nft",
    "tokenStandard": "erc1155+",
    "tokenType": "nonfungible",
    "tokenUnit": "whole",
    "behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 500
    },
    "owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "creationDate": "2022-12-29T04:08:35.000Z",
    "isBurned": false,
    "tokenUri": "tu",
    "price": 10000,
    "onSaleFlag": false
}
getTokenHistory
This method returns the history for a specified token ID. Anyone can call this method.
@GetMethod()
@Validator(yup.string())
public async getTokenHistory(tokenId: string) {
  return await this.Ctx.ERC1155Token.getTokenHistory(tokenId);
}
Parameters:
  • tokenId: string – The ID of the token.
Returns:
  • On success, a JSON array that contains the token history.
Return Value Example (Fungible Token):
[
    {
        "trxId": "ef4af760c3d7ee5e273196231d59fb91cafe6ca0f78c64747e87bc9bcbb3334b",
        "timeStamp": "2023-09-04T02:36:20.000Z",
        "value": {
            "assetType": "otoken",
            "tokenId": "LoyaltyToken",
            "tokenName": "loyalty",
            "tokenDesc": "Updated Fungible Whole",
            "tokenStandard": "erc1155+",
            "tokenType": "fungible",
            "tokenUnit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 10000
            },
            "divisible": {
                "decimal": 2
            },
            "currency_name": "Rupees"
        }
    },
    {
        "trxId": "4fb391a8903633a12a545cd2ecfb57f5575241325abf59995e2a4ed96572bb09",
        "timeStamp": "2023-09-04T02:35:07.000Z",
        "value": {
            "assetType": "otoken",
            "tokenId": "LoyaltyToken",
            "tokenName": "loyalty",
            "tokenDesc": "Fungible Whole",
            "tokenStandard": "erc1155+",
            "tokenType": "fungible",
            "tokenUnit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 10000
            },
            "divisible": {
                "decimal": 2
            },
            "currency_name": "Dollar"
        }
    }
]
Return Value Example (Fractional NFT):
[
    {
        "txId": "99bca74f401465206da7499cbf704dd443b3c3d94e348b1d6682ab5ee1864a08",
        "timestamp": "2023-06-20T01:09:18.000Z",
        "value": {
            "assetType": "otoken",
            "tokenId": "FNFT",
            "tokenName": "realestate",
            "tokenStandard": "erc1155+",
            "tokenType": "nonfungible",
            "tokenUnit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 20000
            },
            "quantity": 100,
            "createdBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "creationDate": "2023-06-20T00:53:13.000Z",
            "divisible": {
                "decimal": 2
            },
            "isBurned": false,
            "tokenUri": "www.FNFT.example.com",
            "price": 2000,
            "on_sale_flag": true,
            "owners": [
                {
                    "accountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "tokenShare": 90
                },
                {
                    "accountId": "oaccount~3cddfdaa855900579d963aa6f755a4aed1f3a474a2462c1b45bd7f36df673224",
                    "tokenShare": 10
                }
            ]
        }
    },
    {
        "txId": "d517c61f40e7d6af2f04fe6d337b3e5108eb57030c9dc823793498fd4fed671b",
        "timestamp": "2023-06-20T00:53:13.000Z",
        "value": {
            "assetType": "otoken",
            "tokenId": "FNFT",
            "tokenName": "realestate",
            "tokenStandard": "erc1155+",
            "tokenType": "nonfungible",
            "tokenUnit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 20000
            },
            "quantity": 100,
            "createdBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "creationDate": "2023-06-20T00:53:13.000Z",
            "divisible": {
                "decimal": 2
            },
            "isBurned": false,
            "tokenUri": "www.FNFT.example.com",
            "price": 2000,
            "on_sale_flag": true,
            "owners": [
                {
                    "accountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "tokenShare": 100
                }
            ]
        }
    }
]
Return Value Example (Whole NFT):
[
    {
        "trxId": "92ac6b56112acdba724dd49924d2420a7899c013c61aa40d272e8ab391a65e0f",
        "timeStamp": "2023-09-04T02:28:48.000Z",
        "value": {
            "tokenMetadata": {
                "painting_name": "monalisa",
                "description": "monalisa painting",
                "image": "image link",
                "painter_name": "Leonardo da Vinci"
            },
            "assetType": "otoken",
            "tokenId": "artnft",
            "tokenName": "artcollection",
            "tokenDesc": "Updated Token Description",
            "tokenStandard": "erc1155+",
            "tokenType": "nonfungible",
            "tokenUnit": "whole",
            "behaviors": [
                "indivisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 20000
            },
            "quantity": 1,
            "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "creationDate": "2023-09-04T02:27:19.000Z",
            "owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "isBurned": false,
            "tokenUri": "www.FNFT.example.com",
            "price": 10000,
            "on_sale_flag": true
        }
    },
    {
        "trxId": "27697dd4a8dba53bad073aa95587cd1ef173b02fd95d771a60273d301fd3bcbe",
        "timeStamp": "2023-09-04T02:27:19.000Z",
        "value": {
            "tokenMetadata": {
                "painting_name": "monalisa",
                "description": "monalisa painting",
                "image": "image link",
                "painter_name": "Leonardo da Vinci"
            },
            "assetType": "otoken",
            "tokenId": "artnft",
            "tokenName": "artcollection",
            "tokenDesc": "artcollection nft",
            "tokenStandard": "erc1155+",
            "tokenType": "nonfungible",
            "tokenUnit": "whole",
            "behaviors": [
                "indivisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 20000
            },
            "quantity": 1,
            "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "creationDate": "2023-09-04T02:27:19.000Z",
            "owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "isBurned": false,
            "tokenUri": "www.FNFT.example.com",
            "price": 10000,
            "on_sale_flag": true
        }
    }
]
[
    {
        "trxId": "ebda1f31543f8906b7ec50a631afff6b8318a3d63c84f3e73be6785cc2ff31ff",
        "timeStamp": "2023-06-20T01:14:08.000Z",
        "value": {
            "assetType": "otoken",
            "tokenId": "NFT",
            "tokenName": "artcollection",
            "tokenStandard": "erc1155+",
            "tokenType": "nonfungible",
            "tokenUnit": "whole",
            "behaviors": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 20000
            },
            "quantity": 1,
            "createdBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "creationDate": "2023-06-20T01:14:08.000Z",
            "owner": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "isBurned": false,
            "tokenUri": "www.NFT.example.com",
            "price": 2000,
            "on_sale_flag": true
        }
    }
]
getAllTokens
This method returns all of the token assets that are saved in the state database. This method can be called only by a Token Admin of the chaincode. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
@GetMethod()
@Validator(yup.string())
public async getTokenHistory(tokenId: string) {
  return await this.Ctx.ERC1155Token.getTokenHistory(tokenId);
}
Parameters:
  • none
Returns:
  • A list of all token assets in JSON format.
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenOne",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenTwo",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  },
  {
    "key": "art",
    "valueJson": {
      "assetType": "otoken",
      "quantity": 1,
      "tokenId": "art",
      "tokenName": "artcollection",
      "tokenStandard": "erc1155+",
      "tokenType": "nonfungible",
      "tokenUnit": "whole",
      "behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter"
      },
      "mintable": {
        "max_mint_quantity": 20000
      },
      "owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "createdBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "creationDate": "2022-12-08T08:52:57.000Z",
      "isBurned": true,
      "tokenUri": "art.example.com",
      "transferredBy": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
      "transferredDate": "2022-12-08T08:59:17.000Z",
      "burnedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "burnedDate": "2022-12-08T09:01:28.000Z"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "assetType": "otoken",
        "tokenId": "FNFT",
        "tokenName": "realestate",
        "tokenStandard": "erc1155+",
        "tokenType": "nonfungible",
        "tokenUnit": "fractional",
        "behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "roles": {
            "minter_role_name": "minter",
            "burner_role_name": "burner"
        },
        "mintable": {
            "max_mint_quantity": 20000
        },
        "quantity": 100,
        "createdBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "creationDate": "2023-06-20T00:53:13.000Z",
        "divisible": {
            "decimal": 2
        },
        "isBurned": false,
        "tokenUri": "www.FNFT.example.com",
        "price": 2000,
        "on_sale_flag": true
    }
  }
]
getTokenById
This method returns a token object if the token is present in the state database. For fractional NFTs, the list of owners is also returned. This method can be called only by a Token Admin of the chaincode or the token owner.
@GetMethod()
@Validator(yup.string())
public async getTokenById(tokenId: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.getTokenById", "TOKEN", { tokenId });
  return await this.Ctx.ERC1155Token.getTokenById(tokenId);
}
Parameters:
  • tokenId: string – The ID of the token to get.
Return Value Example (Whole NFT):
{
  "assetType": "otoken",
  "quantity": 1,
  "tokenId": "art",
  "tokenName": "artcollection",
  "tokenStandard": "erc1155+",
  "tokenType": "nonfungible",
  "tokenUnit": "whole",
  "behaviors": [
    "indivisible",
    "singleton",
    "mintable",
    "transferable",
    "burnable",
    "roles"
  ],
  "roles": {
    "minter_role_name": "minter"
  },
  "mintable": {
    "max_mint_quantity": 20000
  },
  "owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "createdBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "creationDate": "2022-12-08T08:52:57.000Z",
  "isBurned": true,
  "tokenUri": "art.example.com",
  "transferredBy": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "transferredDate": "2022-12-08T08:59:17.000Z",
  "burnedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "burnedDate": "2022-12-08T09:01:28.000Z"
}
Return Value Example (Fungible Token):
{
    "assetType": "otoken",
    "tokenId": "Loyalty",
    "tokenName": "loyalty",
    "tokenDesc": "Token Description",
    "tokenStandard": "erc1155+",
    "tokenType": "fungible",
    "tokenUnit": "fractional",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 10000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "Dollar"
}
Return Value Example (Fractional NFT):
{
    "tokenMetadata": {
        "painting_name": "paint",
        "description": "Painting Description"
    },
    "assetType": "otoken",
    "tokenId": "realEstate",
    "tokenName": "realestate",
    "tokenDesc": "Token Description",
    "tokenStandard": "erc1155+",
    "tokenType": "nonfungible",
    "tokenUnit": "fractional",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 20000
    },
    "quantity": 100,
    "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "creationDate": "2023-06-14T04:20:14.000Z",
    "divisible": {
        "decimal": 2
    },
    "isBurned": false,
    "tokenUri": "www.realestate.example.com",
    "price": 1000,
    "on_sale_flag": true,
    "owners": [
        {
            "accountId": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "tokenShare": 100
        }
    ]
}
getAllTokensByUser
This method returns all of the token assets that are owned by a specified user. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network. This method can be called only by a Token Admin of the chaincode or by the account owner.
@GetMethod()
@Validator(yup.string(), yup.string())
public async getAllTokensByUser(orgId: string, userId: string) {
  const accountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.getAllTokensByUser", "TOKEN", { accountId });
  return await this.Ctx.ERC1155Token.getAllTokensByUser(accountId);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenOne",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  },
  {
    "key": "nftToken",
    "valueJson": {
      "assetType": "otoken",
      "quantity": 1,
      "tokenId": "nftToken",
      "tokenName": "artcollection",
      "tokenStandard": "erc1155+",
      "tokenType": "nonfungible",
      "tokenUnit": "whole",
      "behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter"
      },
      "mintable": {
        "max_mint_quantity": 20000
      },
      "owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "createdBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "creationDate": "2022-12-08T09:10:21.000Z",
      "isBurned": false,
      "tokenUri": "example.com"
    }
  }
]
ownerOf
This method returns the account ID, organization ID, and user ID of the owner of the specified token ID. Anyone can call this method.
@GetMethod()
@Validator(yup.string())
public async ownerOf(tokenId: string) {
  return await this.Ctx.ERC1155Token.ownerOf(tokenId);
}
Parameters:
  • tokenId: string – The ID of the token.
Return Value Example (Whole NFT):
{
    "accountId": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
    "orgId": "appdev",
    "userId": "idcqa"
}
Return Value Example (Fractional NFT):
[
    {
        "accountId": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
        "orgId": "Org1MSP",
        "userId": "admin"
    },
    {
        "accountId": "oaccount~74108eca702bab6d8548e740254f2cc7955d886885251d52d065042172a59db0",
        "orgId": "Org1MSP",
        "userId": "user"
    }
]
URI
This method returns the URI of a specified token. Anyone can call this method.
@GetMethod()
@Validator(yup.string())
public async URI(tokenId: string) {
  return await this.Ctx.ERC1155Token.tokenURI(tokenId);
}
Parameters:
  • tokenId: string – The ID of the token.
Return Value Example:
{
    "tokenUri": "example.com"
}
name
This method returns the name of the token class. Anyone can call this method.
@GetMethod()
@Validator(yup.string())
public async name(tokenId: string) {
  return await this.Ctx.ERC1155Token.name(tokenId);
}
Parameters:
  • tokenId: string – The ID of the token.
Return Value Example:
{"tokenName": "artcollection"}
totalSupply
This method returns the total number of minted tokens. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name. This method can be called only by a Token Admin of the chaincode.
@GetMethod()
@Validator(yup.object())
public async totalSupply(tokenDetail: TokenDetail) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.totalSupply", "TOKEN");
  const token = await this.Ctx.ERC1155Token.getTokenByIdOrName(tokenDetail);
  return await this.Ctx.ERC1155Token.totalSupply(token);
}
Parameters:
  • tokenDetails: TokenDetail – The details that specify the token. For fungible tokens, use the following format:
    {"tokenId":"token1"}
    For non-fungible tokens, use the following format:
    {"tokenName":"artCollection"}
Return Value Example:
{"totalSupply": 110}
totalNetSupply
This method returns the total number of minted tokens minus the number of burned tokens. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name. This method can be called only by a Token Admin of the chaincode.
@GetMethod()
@Validator(yup.object())
public async totalNetSupply(tokenDetail: TokenDetail) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.totalNetSupply", "TOKEN");
  const token = await this.Ctx.ERC1155Token.getTokenByIdOrName(tokenDetail);
  return await this.Ctx.ERC1155Token.totalNetSupply(token);
}
Parameters:
  • tokenDetails: TokenDetail – The details that specify the token. For fungible tokens, use the following format:
    {"tokenId":"token1"}
    For non-fungible tokens, use the following format:
    {"tokenName":"artCollection"}
Return Value Example:
{"totalNetSupply": 105}
getTokensByName
This method returns all of the token assets for a specified token name. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network. This method can be called only by a Token Admin of the chaincode.
@GetMethod()
@Validator(yup.string())
public async getTokensByName(tokenName: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.getTokensByName", "TOKEN");
  return await this.Ctx.ERC1155Token.getTokensByName(tokenName);
}
Parameters:
  • tokenName: string – The name of the token.
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenOne",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenTwo",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  }
]
getTokenDecimal
This method returns the number of decimal places for a specified token. This method can be called only by a Token Admin of the chaincode.
@GetMethod()
@Validator(yup.string())
public async getTokenDecimal(tokenId: string) {
  const token = await this.Ctx.ERC1155Token.get(tokenId);
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.getDecimals", "TOKEN");
  return {
    msg: `Token Id: ${tokenId} has ${this.Ctx.ERC1155Token.getDecimals(token)} decimal places.`,
  };
}
Parameters:
  • tokenId: string – The ID of the token.
Return Value Example:
{
    "msg": "Token Id: tokenOne has 2 decimal places."
}

Methods for Account Management

createAccount
This method creates an account for a specified user and associated token accounts for fungible or non-fungible tokens. An account must be created for any user who will have tokens at any point. The user account tracks the NFT account and the fungible token accounts that a user holds. Users must have accounts in the network to complete token-related operations. This method can be called only by a Token Admin of the chaincode.

A user account has a unique ID, which is formed by an SHA-256 hash of the orgId parameter and the userId parameter.

A user can have multiple fungible token accounts with unique account IDs. Fungible token account IDs are formed by an SHA-256 hash of the orgId parameter, the userId parameter, the constant string ft separated by the tilde symbol (~), and a counter number that signifies the index of the fungible account that is being created separated by the tilde symbol (~).

A user can have only one non-fungible token account. Non-fungible token account IDs are unique and are formed by an SHA-256 hash of the orgId parameter, the userId parameter, and the constant string nft separated by the tilde symbol (~). All non-fungible tokens that a user owns, whether whole or fractional, are linked to this account.

User account IDs start with with ouaccount~. Token account IDs start with oaccount~.

@Validator(yup.string(), yup.string(), yup.boolean(), yup.boolean())
public async createAccount(orgId: string, userId: string, ftAccount: boolean, nftAccount: boolean) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.createAccount", "TOKEN");
  return await this.Ctx.ERC1155Account.createAccount(orgId, userId, ftAccount, nftAccount);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • ftAccount: boolean – If true, a fungible token account is created and associated with the user account.
  • nftAccount: boolean – If true, a non-fungible token account is created and associated with the user account.
Returns:
  • On success, a JSON object of the account that was created.
Return Value Example:
{
  "assetType": "ouaccount",
  "accountId": "ouaccount~cf20877546f52687f387e7c91d88b9722c97e1a456cc0484f40c747f7804feae",
  "userId": "user1",
  "orgId": "appdev",
  "totalAccounts": 2,
  "totalFtAccounts": 1,
  "associatedFtAccounts": [
    {
      "accountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
      "tokenId": ""
    }
  ],
  "associatedNftAccount": "oaccount~73c3e835dac6d0a56ca9d8def08269f83cefd59b9d297fe2cdc5a9083828fa58"
}
createUserAccount
This method creates an account for a specified user. An account must be created for any user who will have tokens at any point. The user account tracks the NFT account and the fungible token accounts that a user has. Users must have accounts in the network to complete token-related operations.

An account ID is an SHA-256 hash of the orgId parameter and the userId parameter. This method can be called only by a Token Admin of the chaincode.

@Validator(yup.string(), yup.string())
  public async createUserAccount(orgId: string, userId: string) {
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.createUserAccount", "TOKEN");
    return await this.Ctx.ERC1155Account.createUserAccount(orgId, userId);
  }
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a JSON object of the user account that was created.
Return Value Example:
{
  "assetType": "ouaccount",
  "accountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "userId": "user2",
  "orgId": "appdev",
  "totalAccounts": 0,
  "totalFtAccounts": 0,
  "associatedFtAccounts": [],
  "associatedNftAccount": ""
}
createTokenAccount
This method creates a fungible or non-fungible token account to associate with a user account.

A user can have multiple fungible token accounts with unique account IDs. Fungible token account IDs are formed by an SHA-256 hash of the orgId parameter, the userId parameter, the constant string ft separated by the tilde symbol (~), and a counter number that signifies the index of the fungible account that is being created separated by the tilde symbol (~).

A user can have only one non-fungible token account. Non-fungible token account IDs are unique and are formed by an SHA-256 hash of the orgId parameter, the userId parameter, and the constant string nft separated by the tilde symbol (~). All non-fungible tokens that a user owns, whether whole or fractional, are linked to this account.

This method can be called only by a Token Admin of the chaincode.

@Validator(yup.string(), yup.string(), yup.string())
  public async createTokenAccount(orgId: string, userId: string, tokenType: TokenType) {
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.createTokenAccount", "TOKEN");
    return await this.Ctx.ERC1155Account.createTokenAccount(orgId, userId, tokenType);
  }
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • tokenType: TokenType – The type of token account to create. The only supported token types are nonfungible and fungible.
Returns:
  • On success, a JSON object of the token account that was created.
Return Value Example:
{
  "assetType": "ouaccount",
  "accountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "userId": "user2",
  "orgId": "appdev",
  "totalAccounts": 1,
  "totalFtAccounts": 1,
  "associatedFtAccounts": [
    {
      "accountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
      "tokenId": ""
    }
  ],
  "associatedNftAccount": ""
}
associateFungibleTokenAccount
This method associates a user's fungible token account to a particular fungible token.

This method can be called only by a Token Admin of the chaincode.

@Validator(yup.string(), yup.string(), yup.string())
public async associateFungibleTokenToAccount(orgId: string, userId: string, tokenId: string) {
  const accountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.associateFungibleTokenToAccount", "TOKEN", { accountId });
  return await this.Ctx.ERC1155Account.associateTokenToToken(accountId, tokenId);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • tokenId: string – The ID of the token.
Returns:
  • On success, a JSON object of the user account, which shows that the fungible token was associated to the token account. For example, in the following example, the first object in the associatedFtAccounts array shows that the fungible token account ID and the token ID are associated.
Return Value Example:
{
  "assetType": "ouaccount",
  "accountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "userId": "user2",
  "orgId": "appdev",
  "totalAccounts": 1,
  "totalFtAccounts": 1,
  "associatedFtAccounts": [
    {
      "accountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
      "tokenId": "tokenOne"
    }
  ],
  "associatedNftAccount": ""
}
getAccountHistory
This method returns history for a specified token account. This is an asynchronous method. This method can be called only by a Token Admin of the chaincode or by the account owner.
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string())
public async getAccountHistory(orgId: string, userId: string, tokenId?: string) {
  const userAccountId = await this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  const userAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.history", "TOKEN", { accountId: userAccountId });
  return await this.Ctx.ERC1155Account.getAccountHistory(userAccount.accountId);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • tokenId?: string – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
Returns:
  • On success, an array of JSON objects that describes the account history.
Return Value Example:
[
  {
    "trxId": "89f462697f3c988024b2c248cbda21f9eb7e96567e56dd8db64ada96a4845a7f",
    "timeStamp": "2022-12-08T07:15:10.000Z",
    "value": {
      "assetType": "oaccount",
      "bapAccountVersion": 1,
      "accountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
      "userId": "user2",
      "orgId": "appdev",
      "tokenType": "fungible",
      "tokenId": "tokenOne",
      "tokenName": "moneytok",
      "balance": 110
    }
  },
  {
    "trxId": "30dd4fe0746350c85a5000996974487010a0a8fee73d6b2e480c3ca330a6d31f",
    "timeStamp": "2022-12-08T06:43:10.000Z",
    "value": {
      "assetType": "oaccount",
      "bapAccountVersion": 0,
      "accountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
      "userId": "user2",
      "orgId": "appdev",
      "tokenType": "fungible",
      "tokenId": "tokenOne",
      "tokenName": "moneytok",
      "balance": 0
    }
  },
  {
    "trxId": "6226c0455cc3a4f99c3fd7ed8b1d36b8e93f863e42ab61a9b0d399f2d69d2f3d",
    "timeStamp": "2022-12-08T06:41:51.000Z",
    "value": {
      "assetType": "oaccount",
      "bapAccountVersion": 0,
      "accountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
      "userId": "user2",
      "orgId": "appdev",
      "tokenType": "fungible",
      "tokenId": "",
      "balance": 0
    }
  }
]
getAccount
This method returns token account details for a specified user. This method can be called only by a Token Admin of the chaincode or the Account Owner of the account.
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string())
public async getAccount(orgId: string, userId: string, tokenId?: string) {
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.getAccount", "TOKEN", { accountId: userAccountId });
  return await this.Ctx.ERC1155Account.getAccountWithStatus(userAccountId, tokenId);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • tokenId?: string – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
Returns:
  • On success, a JSON object that includes token account details. The bapAccountVersion parameter is defined in the account object for internal use.
Return Value Example (Non-Fungible Token Account):
{
  "assetType": "oaccount",
  "bapAccountVersion": 1,
  "status": "active",
  "accountId": "oaccount~cc301bee057f14236a97d434909ec1084970921b008f6baab09c2a0f5f419a9a",
  "userId": "idcqa",
  "orgId": "appdev",
  "tokenType": "nonfungible",
  "noOfNfts": 1
}
Return Value Example (Fungible Token Account):
{
  "bapAccountVersion": 0,
  "assetType": "oaccount",
  "status": "active",
  "accountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "userId": "idcqa",
  "orgId": "appdev",
  "tokenType": "fungible",
  "tokenId": "t1",
  "tokenName": "loyalty",
  "balance": 100
}
getAllAccounts
This method returns details of all user accounts. This method can be called only by a Token Admin of the chaincode.
@GetMethod()
@Validator()
public async getAllAccounts() {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.getAllAccounts", "TOKEN");
  return await this.Ctx.ERC1155Account.getAllAccounts();
}
Parameters:
  • none
Returns:
  • On success, a JSON array of all accounts.
Return Value Example:
[
        {
            "assetType": "ouaccount",
            "accountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
            "userId": "idcqa",
            "orgId": "appdev",
            "totalAccounts": 2,
            "totalFtAccounts": 1,
            "associatedFtAccounts": [
                {
                    "accountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
                    "tokenId": "loy1"
                }
            ],
            "associatedNftAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371"
        },
        {
            "assetType": "ouaccount",
            "accountId": "ouaccount~9501bb774c156eb8354dfe489250ea91f757523d70f08ee494bda98bb352003b",
            "userId": "user1_minter",
            "orgId": "appdev",
            "totalAccounts": 2,
            "totalFtAccounts": 1,
            "associatedFtAccounts": [
                {
                    "accountId": "oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c",
                    "tokenId": "loy1"
                }
            ],
            "associatedNftAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446"
        },
    ]
getAccountDetailsByUser
This method returns an account summary for a specified user and details of fungible and non-fungible tokens that are associated with the user. This method can be called only by a Token Admin of the chaincode or the Account Owner of the account.
@GetMethod()
@Validator(yup.string(), yup.string())
public async getAccountDetailsByUser(orgId: string, userId: string) {
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.getAccountDetailsByUser", "TOKEN", {
    accountId: userAccountId,
  });
  return await this.Ctx.ERC1155Account.getAccountDetailsByUser(orgId, userId);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a JSON account object that includes and account summary for the specified user and details of fungible and non-fungible tokens that are associated with the user. For fractional non-fungible tokens, the tokenShare property in the associatedNFTs section shows the share that the user owns.
Return Value Example:
{
    "userAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
    "associatedFTAccounts": [
        {
            "accountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "tokenId": "FT",
            "balance": 50
        }
    ],
    "associatedNFTAccount": {
        "accountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "associatedNFTs": [
            {
                "nftTokenId": "FNFT",
                "tokenShare": 100
            },
            {
                "nftTokenId": "FNFT2",
                "tokenShare": 110
            },
            {
                "nftTokenId": "NFT"
            }
        ]
    }
}
getUserByAccountId
This method returns the user details of a specified account ID. This method can be called by any user.
@GetMethod()
@Validator(yup.string())
public async getUserByAccountId(accountId: string) {
  return await this.Ctx.ERC1155Account.getUserByAccountId(accountId);
}
Parameters:
  • accountId: string – The ID of the account.
Returns:
  • On success, a JSON object of the user details (orgId and userId).
Return Value Example:
{
  "orgId": "appdev"
  "userId": "user2",
}

Methods for Role Management

addRole
This method adds a role to a specified user and token. This method can be called only by a Token Admin of the chaincode. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name. The specified user must have a token account that is associated with the fungible token, or a non-fungible token account for NFT roles. The specified role must exist in the specification file for the token.
@Validator(yup.string(), yup.string(), yup.string(), yup.object())
public async addRole(orgId: string, userId: string, role: string, tokenDetail: TokenDetail) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.addRoleMember", "TOKEN");
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  const token = await this.Ctx.ERC1155Token.getTokenByIdOrName(tokenDetail);
  return await this.Ctx.ERC1155Token.addRoleMember(role, userAccountId, token);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • role: string – The name of the role to add to the specified user.
  • tokenDetails: TokenDetail – The details that specify the token. For fungible tokens, use the following format:
    {"tokenId":"token1"}
    For non-fungible tokens, use the following format:
    {"tokenName":"artCollection"}
Returns:
  • On success, a message with account details.
Return Value Example:
{
  "msg": "Successfully added role 'minter' to Account Id: oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (Org-Id: appdev, User-Id: idcqa)"
}
isInRole
This method returns a Boolean value to indicate if a user has a specified role. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name. This method can be called only by a Token Admin of the chaincode or the Account Owner of the account. The specified user must have a token account that is associated with the fungible token, or a non-fungible token account for NFT roles. The specified role must exist in the specification file for the token.
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string(), yup.object())
public async isInRole(orgId: string, userId: string, role: string, tokenDetail: TokenDetail) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.removeRoleMember", "TOKEN");
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  const token = await this.Ctx.ERC1155Token.getTokenByIdOrName(tokenDetail);
  return await this.Ctx.ERC1155Token.isInRole(role, userAccountId, token);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • role: string – The name of the role to search for.
  • tokenDetails: TokenDetail – The details that specify the token. For fungible tokens, use the following format:
    {"tokenId":"token1"}
    For non-fungible tokens, use the following format:
    {"tokenName":"artCollection"}
Return Value Example:
{
    "result": true,
    "msg": "Account Id oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (Org-Id: appdev, User-Id: idcqa) has minter role"
}
removeRole
This method removes a role from a specified user and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name. This method can be called only by a Token Admin of the chaincode. The specified user must have a token account that is associated with the fungible token, or a non-fungible token account for NFT roles. The specified role must exist in the specification file for the token.
@Validator(yup.string(), yup.string(), yup.string(), yup.object())
public async removeRole(orgId: string, userId: string, role: string, tokenDetail: TokenDetail) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155TOKEN.removeRoleMember", "TOKEN");
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  const token = await this.Ctx.ERC1155Token.getTokenByIdOrName(tokenDetail);
  return await this.Ctx.ERC1155Token.removeRoleMember(role, userAccountId, token);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • role: string – The name of the role to remove from the specified user.
  • tokenDetails: TokenDetail – The details that specify the token. For fungible tokens, use the following format:
    {"tokenId":"token1"}
    For non-fungible tokens, use the following format:
    {"tokenName":"artCollection"}
Return Value Example:
{
  "msg": "Successfully removed role 'minter' from Account Id: oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b (Org-Id: appdev, User-Id: user1)"
}
getAccountsByRole
This method returns a list of all account IDs for a specified role and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name. This method can be called only by a Token Admin of the chaincode.
@GetMethod()
@Validator(yup.string(), yup.object())
public async getAccountsByRole(role: string, tokenDetail: TokenDetail) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ROLE.getAccountsByRole", "TOKEN");
  const token = await this.Ctx.ERC1155Token.getTokenByIdOrName(tokenDetail);
  return await this.Ctx.ERC1155Token.getAccountsByRole(role, token);
}
Parameters:
  • role: string – The name of the role to search for.
  • tokenDetails: TokenDetail – The details that specify the token. For fungible tokens, use the following format:
    {"tokenId":"token1"}
    For non-fungible tokens, use the following format:
    {"tokenName":"artCollection"}
Return Value Example:
{
  "accounts": [
    "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
    "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b"
  ]
}
getUsersByRole
This method returns a list of all users for a specified role and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name. This method can be called only by a Token Admin of the chaincode.
@GetMethod()
@Validator(yup.string(), yup.object())
public async getUsersByRole(role: string, tokenDetail: TokenDetail) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ROLE.getUsersByRole", "TOKEN");
  const token = await this.Ctx.ERC1155Token.getTokenByIdOrName(tokenDetail);
  return await this.Ctx.ERC1155Token.getUsersByRole(role, token);
}
Parameters:
  • role: string – The name of the role to search for.
  • tokenDetails: TokenDetail – The details that specify the token. For fungible tokens, use the following format:
    {"tokenId":"token1"}
    For non-fungible tokens, use the following format:
    {"tokenName":"artCollection"}
Return Value Example:
{
    "users": [
        {
            "accountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
            "orgId": "appdev",
            "userId": "user2"
        },
        {
            "accountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
            "orgId": "appdev",
            "userId": "user1"
        }
    ]
}

Methods for Transaction History Management

getAccountTransactionHistory
This method returns account transaction history. This method can be called only by a Token Admin of the chaincode or by the account owner. For non-fungible tokens, this method can only be called when connected to the remote Oracle Blockchain Platform network.
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string())
public async getAccountTransactionHistory(orgId: string, userId: string, tokenId?: string) {
  const userAccountId = await this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.getAccountTransactionHistory", "TOKEN", {
    accountId: userAccountId,
  });
  const account = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
  return await this.Ctx.ERC1155Account.getAccountTransactionHistory(account.accountId);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • tokenId?: string – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
Return Value Example:
[
    {
        "transactionId": "otransaction~3a6b23c3003626f3947e990eddbd7ac23398d2200e2eb3eac745e6ddfae140bc~7c88c736df38d5622512f1e8dcdd50710eb47c953f1ecb24ac44790a9e2f475b",
        "timestamp": "2023-06-06T14:48:08.000Z",
        "tokenId": "FNFT",
        "transactedAmount": 10,
        "triggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "transactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "transactionType": "DEBIT",
        "balance": 90
    },
    {
        "transactionId": "otransaction~3a6b23c3003626f3947e990eddbd7ac23398d2200e2eb3eac745e6ddfae140bc~178e3730bc5bee50d02f1464a4eebf733a051905f651e5789039adb4a3edc114",
        "timestamp": "2023-06-06T14:48:08.000Z",
        "tokenId": "NFT",
        "triggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "transactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "transactionType": "DEBIT"
    },
    {
        "transactionId": "otransaction~c369929e28e78de06c72d020f1418c9a154a7dd280b2e22ebb4ea4485e249124~a7cefb22ff39ee7e36967be71de27da6798548c872061a62dabc56d88d50b930",
        "timestamp": "2023-06-06T14:47:08.000Z",
        "tokenId": "NFT",
        "triggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "transactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "transactionType": "MINT"
    },
    {
        "transactionId": "otransaction~114a1bc78d04be48ee6dc140c32c042ee9481cb118959626f090eec744522422~e4eb15d9354f694230df8835ade012100d82aa43672896a2c7125a86e3048f9f",
        "timestamp": "2023-06-05T17:17:57.000Z",
        "tokenId": "FNFT",
        "transactedAmount": 100,
        "triggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "transactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "transactionType": "MINT",
        "balance": 100
    }
]
getTransactionById
This method returns the transaction details for a specified transaction ID. Anyone can call this method.
@GetMethod()
@Validator(yup.string())
public async getTransactionById(transactionId: string) {
  return await this.Ctx.ERC1155Transaction.getTransactionById(transactionId);
}
Parameters:
  • transactionId: string – The ID of the transaction.
Return Value Example:
{
  "transactionId": "otransaction~9ea7b05ab099f7ff4db8342b8c3609031f1d54f11205906e7f1fe88661fe3cbe~33b59ce0c89e96c1e16449f24301581e8e71954f38ad977c7eb6f065e87f2a53",
  "history": [
    {
      "trxId": "9ea7b05ab099f7ff4db8342b8c3609031f1d54f11205906e7f1fe88661fe3cbe",
      "timeStamp": "2022-12-08T09:01:28.000Z",
      "value": {
        "assetType": "otransaction",
        "transactionId": "otransaction~9ea7b05ab099f7ff4db8342b8c3609031f1d54f11205906e7f1fe88661fe3cbe~33b59ce0c89e96c1e16449f24301581e8e71954f38ad977c7eb6f065e87f2a53",
        "tokenId": "tokenOne",
        "fromAccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
        "toAccountId": "",
        "transactionType": "BURN",
        "amount": 5,
        "timestamp": "2022-12-08T09:01:28.000Z",
        "triggeredByUserAccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc"
      }
    }
  ]
}
deleteHistoricalTransactions
This method deletes transactions before a specified time stamp from the state database. This method can be called only by a Token Admin of the chaincode.
@Validator(yup.date())
public async deleteHistoricalTransactions(time_to_expiration: Date) {
  await this.Ctx.ERC1155Auth.checkAuthorization("TRANSACTION.deleteTransactions", "TOKEN");
  return await this.Ctx.ERC1155Transaction.deleteTransactions(time_to_expiration);
}
Parameters:
  • timestamp: string – All transactions before this time stamp will be deleted.
Return Value Example:
{
  "msg": "Successfuly deleted transaction older than date: Thu Apr 07 2022 21:18:59 GMT+0000 (Coordinated Universal Time).",
  "transactions": [
    "otransaction~30513757d8b647fffaafac440d743635f5c1b2e41b25ebd6b70b5bbf78a2643f",
    "otransaction~ac0e908c735297941ba58bb208ee61ff4816a1e54c090d68024f82adf743892b"
  ]
}

Methods for Token Behavior Management - Mintable Behavior

mintBatch
This method creates (mints) multiple tokens in a batch operation. This method creates only fungible tokens or fractional non-fungible tokens.

For fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method. If not, any user can use this method to mint tokens. You cannot mint more than the max_mint_quantity property of the token, if that property was specified when the token was created or updated.

For non-fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method. If not, any user can use this method to mint tokens. Additionally, the caller must also be the creator of the token. There is no upper limit to the quantity of fractional non-fungible tokens that can be minted.

You cannot use this method to mint a whole non-fungible token.

@Validator(yup.string(), yup.string(), yup.array().of(yup.string()), yup.array().of(yup.number()))
public async mintBatch(orgId: string, userId: string, tokenIds: string[], quantity: number[]) {
  const accountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  return await this.Ctx.ERC1155Token.mintBatch(accountId, tokenIds, quantity);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • tokenIds: string[] – The list of token IDs to mint tokens for.
  • quantity: number[] – The list of quantities of tokens to mint, corresponding to the token ID array.
Returns:
  • On success, a JSON object that includes details on the minted tokens.
Return Value Example:
{
    "msg": "Successfully minted batch of tokens for User-Account-Id ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38 (Org-Id: appdev, User-Id: idcqa).",
    "details": [
        {
            "msg": "Successfully minted 100 tokens of fractional tokenId: plot55 to Org-Id: appdev, User-Id: idcqa"
        },
        {
            "msg": "Successfully minted 100 tokens of tokenId: loyalty to Token-Account-Id oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e"
        }
    ]
}

Methods for Token Behavior Management - Transferable Behavior

batchTransferFrom
This method completes a batch operation that transfers tokens specified in a list of token IDs from one user to another user.

For NFTs, because the method transfers ownership of the NFT, the sender of the NFT must own the token.

For fractional NFTs, if a user (including the creator of the token) transfers all of the shares that they own, then they lose ownership of the token. If any share of a token is transferred to a user, that user automatically becomes one of the owners of the fractional NFT.

This method does not validate that the caller of the method is the specified sender. This method can be called by any user.

@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.array().of(yup.string()), yup.array().of(yup.number()))
public async batchTransferFrom(
  fromOrgId: string,
  fromUserId: string,
  toOrgId: string,
  toUserId: string,
  tokenIds: string[],
  quantity: number[]
) {
  const fromAccountId = this.Ctx.ERC1155Account.generateAccountId(fromOrgId, fromUserId, ACCOUNT_TYPE.USER_ACCOUNT);
  const toAccountId = this.Ctx.ERC1155Account.generateAccountId(toOrgId, toUserId, ACCOUNT_TYPE.USER_ACCOUNT);
  return await this.Ctx.ERC1155Token.batchTransferFrom(fromAccountId, toAccountId, tokenIds, quantity);
}
Parameters:
  • fromOrgId: string – The membership service provider (MSP) ID of the sender and token owner in the current organization.
  • fromUserId: string – The user name or email ID of the sender and token owner.
  • toOrgId: string – The membership service provider (MSP) ID of the receiver in the current organization.
  • toUserId: string – The user name or email ID of the receiver.
  • tokenIds: string[] – A list of token IDs for the tokens to transfer.
  • quantity: number[] – The list of quantities of tokens to transfer, corresponding to the token ID array.
Returns:
  • On success, a message with details for each token transfer.
Return Value Example:
[
    {
        "msg": "Successfully transferred NFT token: 'FNFT' of '10' quantity from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred 10 FT token: 'FT' from Account-Id: oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred NFT token: 'NFT' from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    }
]
safeBatchTransferFrom
This method completes a batch operation that transfers tokens specified in a list of token IDs from one user to another user.

For NFTs, because the method transfers ownership of the NFT, the sender of the NFT must own the token.

For fractional NFTs, if a user (including the creator of the token) transfers all of the shares that they own, then they lose ownership of the token. If any share of a token is transferred to a user, that user automatically becomes one of the owners of the fractional NFT.

The caller of the method must be the specified sender. This method can be called by any user.

@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.array().of(yup.string()), yup.array().of(yup.number()))
public async safeBatchTransferFrom(
  fromOrgId: string,
  fromUserId: string,
  toOrgId: string,
  toUserId: string,
  tokenIds: string[],
  quantity: number[]
) {
  const fromAccountId = this.Ctx.ERC1155Account.generateAccountId(fromOrgId, fromUserId, ACCOUNT_TYPE.USER_ACCOUNT);
  const toAccountId = this.Ctx.ERC1155Account.generateAccountId(toOrgId, toUserId, ACCOUNT_TYPE.USER_ACCOUNT);
  return await this.Ctx.ERC1155Token.safeBatchTransferFrom(fromAccountId, toAccountId, tokenIds, quantity);
}
Parameters:
  • fromOrgId: string – The membership service provider (MSP) ID of the sender and token owner in the current organization.
  • fromUserId: string – The user name or email ID of the sender and token owner.
  • toOrgId: string – The membership service provider (MSP) ID of the receiver in the current organization.
  • toUserId: string – The user name or email ID of the receiver.
  • tokenIds: string[] – A list of token IDs for the tokens to transfer.
  • quantity: number[] – The list of quantities of tokens to transfer, corresponding to the token ID array.
Returns:
  • On success, a message with details for each token transfer.
Return Value Example:
[
    {
        "msg": "Successfully transferred NFT token: 'FNFT' of '10' quantity from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred 10 FT token: 'FT' from Account-Id: oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred NFT token: 'NFT' from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    }
]
balanceOfBatch
This method completes a batch operation that gets the balance of token accounts. The account details are specified in three separate lists of organization IDs, user IDs, and token IDs. This method can be called only by a Token Admin of the chaincode or by account owners. Account owners can see balance details only for accounts that they own.
@GetMethod()
@Validator(yup.array().of(yup.string()), yup.array().of(yup.string()), yup.array().of(yup.string()))
public async balanceOfBatch(orgIds: string[], userIds: string[], tokenIds: string[]) {
  let callerAccountCheck = false;
  try {
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.balanceOfBatch", "TOKEN");
  } catch (err) {
    callerAccountCheck = true;
  }
  const accountIds = await this.Ctx.ERC1155Account.generateAccountIds(orgIds, userIds, callerAccountCheck);
  return await this.Ctx.ERC1155Account.balanceOfBatch(accountIds, tokenIds);
}
Parameters:
  • orgIds: string[] – A list of the membership service provider (MSP) IDs in the current organization.
  • userIds: string[] – A list of the user name or email IDs.
  • tokenIds: string[] – A list of the token IDs.
Return Value Example:

In the following example, the token ID FNFT represents a fractional non-fungible token and the token ID FT represents a fungible token.

[
    {
        "orgId": "appdev",
        "userId": "idcqa",
        "userAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "tokenAccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "tokenId": "FNFT",
        "balance": 100
    },
    {
        "orgId": "appdev",
        "userId": "idcqa",
        "userAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "tokenAccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
        "tokenId": "FT",
        "balance": 50
    },
    {
        "orgId": "appdev",
        "userId": "user1_minter",
        "userAccountId": "ouaccount~9501bb774c156eb8354dfe489250ea91f757523d70f08ee494bda98bb352003b",
        "tokenAccountId": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "tokenId": "FNFT",
        "balance": 10
    }
]
exchangeToken
This method exchanges tokens between specified accounts. This method only supports exchanging between an NFT and a fungible token or a fungible token and an NFT. The NFT can be whole or fractional. This method can be called only by the account owner.
@Validator(yup.string(), yup.string(), yup.string(), yup.number(), yup.string(), yup.string(), yup.string(), yup.number())
  public async exchangeToken(
    fromTokenId: string,
    fromOrgId: string,
    fromUserId: string,
    fromTokenQuantity: number,
    toTokenId: string,
    toOrgId: string,
    toUserId: string,
    toTokenQuantity: number
  ) {
    const fromUserAccountId = this.Ctx.ERC1155Account.generateAccountId(fromOrgId, fromUserId, ACCOUNT_TYPE.USER_ACCOUNT);
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT.exchangeToken", "TOKEN", { accountId: fromUserAccountId });
    const toUserAccountId = this.Ctx.ERC1155Account.generateAccountId(toOrgId, toUserId, ACCOUNT_TYPE.USER_ACCOUNT);
    return await this.Ctx.ERC1155Token.exchangeToken(
      fromTokenId,
      fromUserAccountId,
      fromTokenQuantity,
      toTokenId,
      toUserAccountId,
      toTokenQuantity
    );
  }
Parameters:
  • fromTokenId: string – The ID of the token that the sender owns.
  • fromOrgId: string – The membership service provider (MSP) ID of the sender in the current organization.
  • fromUserId: string – The user name or email ID of the sender.
  • fromTokenQuantity: number – The quantity of tokens from the sender to exchange with the receiver.
  • toTokenId: string – The ID of the token that the receiver owns.
  • toOrgId: string – The membership service provider (MSP) ID of the receiver in the current organization.
  • toUserId: string – The user name or email ID of the receiver.
  • toTokenQuantity: number – The quantity of tokens from the receiver to exchange with the sender.
Returns:
  • On success, a message with token exchange details.
Return Value Example:
{
    "msg": "Succesfully exchanged 10 tokens of type nonfungible with tokenId: [r1] from Account oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (OrgId: appdev, UserId: idcqa) to 10 tokens of type fungible with tokenId: [loy1] from Account oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (OrgId: appdev, UserId: user1_minter)"
}

Methods for Token Behavior Management - Burnable Behavior

burnBatch
This method deactivates, or burns, the specified fungible and non-fungible tokens. Any user with the burner role can call this method.
@Validator(yup.string(), yup.string(), yup.array().of(yup.string()), yup.array().of(yup.number()))
public async burnBatch(orgId: string, userId: string, tokenIds: string[], quantity: number[]) {
    const accountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
    return await this.Ctx.ERC1155Token.burn(accountId, tokenIds, quantity);
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID in the current organization.
  • userId: string – The user name or email ID.
  • tokenIds: string[] – The list of the token IDs to burn
  • quantity: number[] – The list of quantities of tokens to burn, corresponding to the token ID array..
Returns:
  • On success, a message with details about the burn operations.
Return Value Example:
[
  {
    "msg": "Successfully burned NFT token: 'art' from Account-Id: oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6 (Org-Id: appdev, User-Id: idcqa)"
  },
  {
    "msg": "Successfully burned 5 tokens of tokenId: tokenOne from Account-ID oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (Org-Id: appdev, User-Id: idcqa)"
  },
  {
    "msg": "Successfully burned 2 token share of tokenId: FNFT from Account-ID oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a (Org-Id: AutoF1377358917, User-Id: idcqa)"
  }
]
burnNFT
This method deactivates, or burns, the specified non-fungible token, and returns a token object and token history. Any user with the burner role can call this method.
@Validator(yup.string(), yup.string(), yup.string())
public async burnNFT(orgId: string, userId: string, tokenId: string): Promise<any> {
    const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId);
    const token = await this.Ctx.ERC1155Token.get(tokenId);
    if (token.tokenType !== TOKEN_TYPE.NON_FUNGIBLE) {
      
      throw new Error(`The Token with id ${tokenId} is not a nonfungible token`);
    }
    if (token.isBurned === true) {
      throw new Error(`token with tokenId ${tokenId} is already burned`);
    }
    let tokenBurnQuantity = 1;
    const tokenUnit = token.tokenUnit;
    if (tokenUnit === TOKEN_UNIT.FRACTIONAL) {
       const owners = await this.Ctx.ERC1155Token.getFractionalNFTOwners(tokenId);
       if (owners.length !== 1) {
         throw new Error(`Token with tokenId ${tokenId} has multiple owners`);
       }
      tokenBurnQuantity = token.quantity;
    }
    const tokenHistory = await this.Ctx.ERC1155Token.getTokenHistory(tokenId);
    await this.Ctx.ERC1155Token.burn(userAccountId, [tokenId], [tokenBurnQuantity]);
    token.tokenId = parseInt(token.tokenId);
    if(Number.isNaN(token.tokenId)) {
      throw new Error(`tokenId is expected to be integer but found ${tokenId}`)
    }
    token.isBurned = true;
    return {...token, tokenHistory: JSON.stringify(tokenHistory)};
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID in the current organization.
  • userId: string – The user name or email ID.
  • tokenId: string – The ID of the non-fungible token to burn
Returns:
  • On success, a token object in JSON format that includes token history information.
Return Value Example:
{
    "assetType": "otoken",
    "tokenId": 1,
    "tokenName": "artcollection",
    "tokenStandard": "erc1155+",
    "tokenType": "nonfungible",
    "tokenUnit": "whole",
    "behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
    },
    "mintable": {
        "max_mint_quantity": 20000
    },
    "quantity": 1,
    "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "creationDate": "2023-08-22T07:32:40.000Z",
    "owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "isBurned": true,
    "tokenUri": "example.com",
    "price": 120,
    "onSaleFlag": false,
    "tokenHistory": "[{\"trxId\":\"21a932750f2d4ccffd62eda5678a577cadde0513ed7c7a307f24cd7713a1818b\",\"timeStamp\":\"2023-08-22T07:32:40.000Z\",\"value\":{\"assetType\":\"otoken\",\"tokenId\":\"1\",\"tokenName\":\"artcollection\",\"tokenStandard\":\"erc1155+\",\"tokenType\":\"nonfungible\",\"tokenUnit\":\"whole\",\"behaviors\":[\"indivisible\",\"singleton\",\"mintable\",\"transferable\",\"burnable\",\"roles\"],\"roles\":{\"minter_role_name\":\"minter\"},\"mintable\":{\"max_mint_quantity\":20000},\"quantity\":1,\"createdBy\":\"oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d\",\"creationDate\":\"2023-08-22T07:32:40.000Z\",\"owner\":\"oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d\",\"isBurned\":false,\"tokenUri\":\"example.com\",\"price\":120,\"onSaleFlag\":false}}]"
}

SDK Methods

Methods for Access Control Management

checkAuthorization
Use this method to add an access control check to an operation. This is an asynchronous function. Certain token methods can be run only by the Token Admin or AccountOwner of the token or by the MultipleAccountOwner for users with multiple accounts. The access control mapping is described in the ../lib/constant.ts file. You can modify access control by editing the ../lib/constant.ts file. To use your own access control or to disable access control, remove the access control code from the automatically generated controller methods and custom methods.
ADMIN: {
   isUserTokenAdmin: ["Admin"],
   addAdmin: ["Admin"],
   removeAdmin: ["Admin"],
   getAllAdmins: ["Admin"],
 },
 TOKEN: {
   save: ["Admin"],
   getAllTokens: ["Admin"],
   get: ["Admin"],
   update: ["Admin"],
   getDecimals: ["Admin"],
   getTokensByName: ["Admin"],
   addRoleMember: ["Admin"],
   removeRoleMember: ["Admin"],
   isInRole: ["Admin", "AccountOwner"],
   getTotalMintedTokens: ["Admin"],
   getNetTokens: ["Admin"],
   getTokenHistory: ["Admin"],
 },
 ROLE: {
   getAccountsByRole: ["Admin"],
   getUsersByRole: ["Admin"],
 },
 TRANSACTION: {
   deleteTransactions: ["Admin"],
 },
 ACCOUNT: {
   createAccount: ["Admin"],
   associateToken: ["Admin"],
   getAllAccounts: ["Admin"],
   getAccountsByUser: ["Admin", "MultipleAccountOwner"],
   getAccount: ["Admin", "AccountOwner"],
   history: ["Admin", "AccountOwner"],
   getAccountTransactionHistory: ["Admin", "AccountOwner"],
   getAccountTransactionHistoryWithFilters: ["Admin", "AccountOwner"],
   getSubTransactionsById: ["Admin", TRANSACTION_INVOKER],
   getSubTransactionsByIdWithFilters: ["Admin", TRANSACTION_INVOKER],
   getAccountBalance: ["Admin", "AccountOwner"],
   getAccountOnHoldBalance: ["Admin", "AccountOwner"],
   getOnHoldIds: ["Admin", "AccountOwner"],
   getConversionHistory: ["Admin", "AccountOwner"],
 },
 ACCOUNT_STATUS: {
   get: ["Admin", "AccountOwner"],
   history: ["Admin", "AccountOwner"],
   activateAccount: ["Admin"],
   suspendAccount: ["Admin"],
   deleteAccount: ["Admin"],
 },
 TOKEN_CONVERSION: {
   initializeExchangePoolUser: ["Admin"],
   addConversionRate: ["Admin"],
   updateConversionRate: ["Admin"],
   getConversionRate: ["Admin", "AnyAccountOwner"],
   getConversionRateHistory: ["Admin", "AnyAccountOwner"],
   tokenConversion: ["Admin", "AnyAccountOwner"],
   getExchangePoolUser: ["Admin"],
 },
 ERC721ADMIN: {
   isUserTokenAdmin: ["Admin"],
   addAdmin: ["Admin"],
   removeAdmin: ["Admin"],
   getAllAdmins: ["Admin"],
 },
 ERC721TOKEN: {
   getAllTokens: ["Admin"],
   getAllTokensByUser: ["Admin", "AccountOwner"],
   get: ["Admin", TOKEN_OWNER],
   getTokensByName: ["Admin"],
   addRoleMember: ["Admin"],
   removeRoleMember: ["Admin"],
   isInRole: ["Admin", "AccountOwner"],
   totalSupply: ["Admin"],
   totalNetSupply: ["Admin"],
   history: ["Admin"],
 },
 ERC721ROLE: {
   getAccountsByRole: ["Admin"],
   getUsersByRole: ["Admin"],
 },
 ERC721TRANSACTION: {
   deleteTransactions: ["Admin"],
 },
 ERC721ACCOUNT: {
   createAccount: ["Admin"],
   getAllAccounts: ["Admin"],
   getAccountByUser: ["Admin", "MultipleAccountOwner"],
   history: ["Admin", "AccountOwner"],
   getAccountTransactionHistory: ["Admin", "AccountOwner"],
   getAccountTransactionHistoryWithFilters: ["Admin", "AccountOwner"],
   balanceOf: ["Admin", "MultipleAccountOwner"],
 },
 ERC1155ADMIN: {
   isUserTokenAdmin: ["Admin"],
   addAdmin: ["Admin"],
   removeAdmin: ["Admin"],
   getAllAdmins: ["Admin"],
 },
 ERC1155TOKEN: {
   getAllTokens: ["Admin"],
   get: ["Admin", TOKEN_OWNER],
   getAllTokensByUser: ["Admin", "AccountOwner"],
   totalSupply: ["Admin"],
   totalNetSupply: ["Admin"],
   getTokensByName: ["Admin"],
   getDecimals: ["Admin"],
   addRoleMember: ["Admin"],
   removeRoleMember: ["Admin"],
   isInRole: ["Admin", "AccountOwner"],
   save: ["Admin"],
   update: ["Admin"],
 },
 ERC1155ACCOUNT: {
   createAccount: ["Admin"],
   createUserAccount: ["Admin"],
   createTokenAccount: ["Admin"],
   associateFungibleTokenToAccount: ["Admin", "AccountOwner"],
   getAccountsByUser: ["Admin", "AccountOwner"],
   getAccount: ["Admin", "AccountOwner"],
   history: ["Admin", "AccountOwner"],
   getAllAccounts: ["Admin"],
   balanceOfBatch: ["Admin"],
   getAccountTransactionHistory: ["Admin", "AccountOwner"],
   getAccountTransactionHistoryWithFilters: ["Admin", "AccountOwner"],
   exchangeToken: ["AccountOwner"],
   getAccountDetailsByUser: ["Admin", "AccountOwner"],
 },
 ERC1155ROLE: {
   getAccountsByRole: ["Admin"],
   getUsersByRole: ["Admin"],
 },
Ctx.ERC1155Auth.checkAuthorization(classFuncName: string, ...args)
Parameters:
  • classFuncName: string – The map value between the class and methods as described in the ../lib/constant.ts file.
  • ...args – A variable argument where args[0] takes the constant 'TOKEN' and args[1] takes the account_id to add an access control check for an AccountOwner. To add an access control check for a MultipleAccountOwner, args[1] takes the org_id and args[2] takes the user_id.
Returns:
  • On success, a promise. On error, a rejection with an error message.
isUserTokenAdmin
This method returns the Boolean value true if the specified user is a Token Admin, and false otherwise. The method can be called only by a Token Admin of the token chaincode.
Ctx.ERC1155Auth.isUserTokenAdmin(orgId: string, userId: string)
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Return Value Example:
{
  "result": true
}
addAdmin
This method adds a user as a Token Admin of the token chaincode. The method can be called only by a Token Admin of the token chaincode.
Ctx.ERC1155Admin.addAdmin(orgId: string, userId: string)
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a message that lists details for the user added as a Token Admin of the token chaincode.
Return Value Example:
{
  "msg": "Successfully added Admin (OrgId: appDev, UserId: user1)"
}
removeAdmin
This method removes a user as a Token Admin of the token chaincode. The method can be called only by a Token Admin of the token chaincode. You cannot remove yourself as a Token Admin.
Ctx.ERC1155Admin.removeAdmin(orgId: string, userId: string)
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a message that lists details for the user removed as a Token Admin of the token chaincode.
Return Value Example:
{
  "msg": "Successfully removed Admin (OrgId: appDev, UserId: user1)"
}
getAllAdmins
This method returns a list of all Token Admin users.
Ctx.ERC1155Admin.getAllAdmins()
Parameters:
  • none
Returns:
  • On success, a list of all Token Admin users, identifed by organization ID and user ID.
Return Value Example:
{
  "admins": [
    {
      "orgId": "appdev",
      "userId": "idcqa"
    },
    {
      "orgId": "appdev",
      "userId": "user1"
    }
  ]
}

Methods for Token Configuration Management

save
This method creates tokens. Every token that is defined has its own create method. For non-fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method to create an NFT. If not, any user can use this method to create (mint) NFTs. The user who calls this method becomes the owner of the NFT (whole or fractional).
Ctx.ERC1155Token.save(tokenAsset: <Token Class>, quantity?: number);
Parameters:
  • tokenAsset: <Token Class> – The token asset. The properties of the asset are defined in the model file.
  • quantity: number – For non-fungible tokens only, the number of tokens to mint. The only supported value for this parameter is 1.
Returns:
  • On success, the token asset in JSON format, which can include the following information.
  • tokenMetadata – JSON information that describes the token.
  • createdBy – The account ID of the caller, who is the user minting the token. This property cannot be edited.
  • creationDate – The time stamp of the minting transaction. This property cannot be edited.
  • isBurned – This property indicates whether the token is burned. This property cannot be edited.
  • tokenName – The name of the token. This property cannot be edited.
  • tokenDesc – The description of the token.
  • symbol – The symbol of the token. This property cannot be edited.
  • tokenStandard – The standard of the token. This property cannot be edited.
  • tokenType – The type of the token (fungible or non-fungible). This property cannot be edited.
  • tokenUnit – The unit of the token (whole or fractional). This property cannot be edited.
  • behaviors – A list of token behaviors. This property cannot be edited.
  • mintable – The properties related to minting. The max_mint_quantity value defines the maximum number of tokens that can be created for the token class.
  • owner – The account ID of the current owner, who is the caller of the method.
  • tokenUri – The URI of the token.
  • quantity – The quantity of the token.
Return Value Example (Whole NFT):
{
    "tokenMetadata": {
        "paintingName": "monalisa",
        "description": "monalisa painting",
        "image": "image link",
        "painterName": "Leonardo da Vinci"
    },
    "assetType": "otoken",
    "quantity": 1,
    "tokenId": "artnft",
    "tokenName": "artcollection",
    "tokenDesc": "artcollection nft",
    "tokenStandard": "erc1155+",
    "tokenType": "nonfungible",
    "tokenUnit": "whole",
    "behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 500
    },
    "owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "creationDate": "2022-12-29T04:08:35.000Z",
    "isBurned": false,
    "tokenUri": "tu",
    "price": 10000,
    "onSaleFlag": false
}
Return Value Example (Fungible Token):
{
    "assetType": "otoken",
    "tokenId": "Loyalty",
    "tokenName": "loyalty",
    "tokenDesc": "Token Description",
    "tokenStandard": "erc1155+",
    "tokenType": "fungible",
    "tokenUnit": "fractional",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 10000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "Dollar"
}
Return Value Example (Fractional NFT):
{
    "tokenMetadata": {
        "painting_name": "paint",
        "description": "Painting Description"
    },
    "assetType": "otoken",
    "tokenId": "realEstate",
    "tokenName": "realestate",
    "tokenDesc": "Token Description",
    "tokenStandard": "erc1155+",
    "tokenType": "nonfungible",
    "tokenUnit": "fractional",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 20000
    },
    "quantity": 100,
    "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "creationDate": "2023-06-14T04:20:14.000Z",
    "divisible": {
        "decimal": 2
    },
    "isBurned": false,
    "tokenUri": "www.realestate.example.com",
    "price": 1000,
    "on_sale_flag": true
}
update
This method updates tokens. You cannot update token metadata or the token URI of non-fungible tokens.
Ctx.ERC1155Token.update(tokenAsset: any);
Parameters:
  • tokenAsset: <Token Class> – The token asset. The properties of the asset are defined in the model file.
Returns:
  • On success, the updated token asset in JSON format.
Return Value Example (Whole NFT):
{
    "tokenMetadata": {
        "paintingName": "monalisa",
        "description": "monalisa painting",
        "image": "image link",
        "painterName": "Leonardo da Vinci"
    },
    "assetType": "otoken",
    "quantity": 1,
    "tokenId": "artnft",
    "tokenName": "artcollection",
    "tokenDesc": "artcollection nft",
    "tokenStandard": "erc1155+",
    "tokenType": "nonfungible",
    "tokenUnit": "whole",
    "behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 500
    },
    "owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "creationDate": "2022-12-29T04:08:35.000Z",
    "isBurned": false,
    "tokenUri": "tu",
    "price": 10000,
    "onSaleFlag": false
}
history (Token)
This method returns the history for a specified token ID.
Ctx.ERC1155Token.history(tokenId: string)
Parameters:
  • tokenId: string – The ID of the token.
Returns:
  • On success, a JSON array that contains the token history.
Return Value Example (Fungible Token):
[
    {
        "trxId": "ef4af760c3d7ee5e273196231d59fb91cafe6ca0f78c64747e87bc9bcbb3334b",
        "timeStamp": "2023-09-04T02:36:20.000Z",
        "value": {
            "assetType": "otoken",
            "tokenId": "LoyaltyToken",
            "tokenName": "loyalty",
            "tokenDesc": "Updated Fungible Whole",
            "tokenStandard": "erc1155+",
            "tokenType": "fungible",
            "tokenUnit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 10000
            },
            "divisible": {
                "decimal": 2
            },
            "currency_name": "Rupees"
        }
    },
    {
        "trxId": "4fb391a8903633a12a545cd2ecfb57f5575241325abf59995e2a4ed96572bb09",
        "timeStamp": "2023-09-04T02:35:07.000Z",
        "value": {
            "assetType": "otoken",
            "tokenId": "LoyaltyToken",
            "tokenName": "loyalty",
            "tokenDesc": "Fungible Whole",
            "tokenStandard": "erc1155+",
            "tokenType": "fungible",
            "tokenUnit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 10000
            },
            "divisible": {
                "decimal": 2
            },
            "currency_name": "Dollar"
        }
    }
]
Return Value Example (Fractional NFT):
[
    {
        "txId": "99bca74f401465206da7499cbf704dd443b3c3d94e348b1d6682ab5ee1864a08",
        "timestamp": "2023-06-20T01:09:18.000Z",
        "value": {
            "assetType": "otoken",
            "tokenId": "FNFT",
            "tokenName": "realestate",
            "tokenStandard": "erc1155+",
            "tokenType": "nonfungible",
            "tokenUnit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 20000
            },
            "quantity": 100,
            "createdBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "creationDate": "2023-06-20T00:53:13.000Z",
            "divisible": {
                "decimal": 2
            },
            "isBurned": false,
            "tokenUri": "www.FNFT.example.com",
            "price": 2000,
            "on_sale_flag": true,
            "owners": [
                {
                    "accountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "tokenShare": 90
                },
                {
                    "accountId": "oaccount~3cddfdaa855900579d963aa6f755a4aed1f3a474a2462c1b45bd7f36df673224",
                    "tokenShare": 10
                }
            ]
        }
    },
    {
        "txId": "d517c61f40e7d6af2f04fe6d337b3e5108eb57030c9dc823793498fd4fed671b",
        "timestamp": "2023-06-20T00:53:13.000Z",
        "value": {
            "assetType": "otoken",
            "tokenId": "FNFT",
            "tokenName": "realestate",
            "tokenStandard": "erc1155+",
            "tokenType": "nonfungible",
            "tokenUnit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 20000
            },
            "quantity": 100,
            "createdBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "creationDate": "2023-06-20T00:53:13.000Z",
            "divisible": {
                "decimal": 2
            },
            "isBurned": false,
            "tokenUri": "www.FNFT.example.com",
            "price": 2000,
            "on_sale_flag": true,
            "owners": [
                {
                    "accountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "tokenShare": 100
                }
            ]
        }
    }
]
Return Value Example (Whole NFT):
[
    {
        "trxId": "92ac6b56112acdba724dd49924d2420a7899c013c61aa40d272e8ab391a65e0f",
        "timeStamp": "2023-09-04T02:28:48.000Z",
        "value": {
            "tokenMetadata": {
                "painting_name": "monalisa",
                "description": "monalisa painting",
                "image": "image link",
                "painter_name": "Leonardo da Vinci"
            },
            "assetType": "otoken",
            "tokenId": "artnft",
            "tokenName": "artcollection",
            "tokenDesc": "Updated Token Description",
            "tokenStandard": "erc1155+",
            "tokenType": "nonfungible",
            "tokenUnit": "whole",
            "behaviors": [
                "indivisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 20000
            },
            "quantity": 1,
            "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "creationDate": "2023-09-04T02:27:19.000Z",
            "owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "isBurned": false,
            "tokenUri": "www.FNFT.example.com",
            "price": 10000,
            "on_sale_flag": true
        }
    },
    {
        "trxId": "27697dd4a8dba53bad073aa95587cd1ef173b02fd95d771a60273d301fd3bcbe",
        "timeStamp": "2023-09-04T02:27:19.000Z",
        "value": {
            "tokenMetadata": {
                "painting_name": "monalisa",
                "description": "monalisa painting",
                "image": "image link",
                "painter_name": "Leonardo da Vinci"
            },
            "assetType": "otoken",
            "tokenId": "artnft",
            "tokenName": "artcollection",
            "tokenDesc": "artcollection nft",
            "tokenStandard": "erc1155+",
            "tokenType": "nonfungible",
            "tokenUnit": "whole",
            "behaviors": [
                "indivisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter",
                "burner_role_name": "burner"
            },
            "mintable": {
                "max_mint_quantity": 20000
            },
            "quantity": 1,
            "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "creationDate": "2023-09-04T02:27:19.000Z",
            "owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "isBurned": false,
            "tokenUri": "www.FNFT.example.com",
            "price": 10000,
            "on_sale_flag": true
        }
    }
]
getAllTokens
This method returns all of the token assets that are saved in the state database. This method can be called only by a Token Admin of the chaincode. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
Ctx.ERC1155Token.getAllTokens()
Parameters:
  • none
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenOne",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenTwo",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  },
  {
    "key": "art",
    "valueJson": {
      "assetType": "otoken",
      "quantity": 1,
      "tokenId": "art",
      "tokenName": "artcollection",
      "tokenStandard": "erc1155+",
      "tokenType": "nonfungible",
      "tokenUnit": "whole",
      "behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter"
      },
      "mintable": {
        "max_mint_quantity": 20000
      },
      "owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "createdBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "creationDate": "2022-12-08T08:52:57.000Z",
      "isBurned": true,
      "tokenUri": "art.example.com",
      "transferredBy": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
      "transferredDate": "2022-12-08T08:59:17.000Z",
      "burnedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "burnedDate": "2022-12-08T09:01:28.000Z"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "assetType": "otoken",
        "tokenId": "FNFT",
        "tokenName": "realestate",
        "tokenStandard": "erc1155+",
        "tokenType": "nonfungible",
        "tokenUnit": "fractional",
        "behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "roles": {
            "minter_role_name": "minter",
            "burner_role_name": "burner"
        },
        "mintable": {
            "max_mint_quantity": 20000
        },
        "quantity": 100,
        "createdBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "creationDate": "2023-06-20T00:53:13.000Z",
        "divisible": {
            "decimal": 2
        },
        "isBurned": false,
        "tokenUri": "www.FNFT.example.com",
        "price": 2000,
        "on_sale_flag": true
    }
  },
]
get (Token)
This method returns a token object if the token is present in the state database. This method can be called only by a Token Admin of the chaincode or the token owner.
this.Ctx.ERC1155Token.get(tokenId: string)
Parameters:
  • tokenId: string – The ID of the token to get.
Return Value Example (Whole NFT):
{
  "assetType": "otoken",
  "quantity": 1,
  "tokenId": "art",
  "tokenName": "artcollection",
  "tokenStandard": "erc1155+",
  "tokenType": "nonfungible",
  "tokenUnit": "whole",
  "behaviors": [
    "indivisible",
    "singleton",
    "mintable",
    "transferable",
    "burnable",
    "roles"
  ],
  "roles": {
    "minter_role_name": "minter"
  },
  "mintable": {
    "max_mint_quantity": 20000
  },
  "owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "createdBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "creationDate": "2022-12-08T08:52:57.000Z",
  "isBurned": true,
  "tokenUri": "example.com",
  "transferredBy": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "transferredDate": "2022-12-08T08:59:17.000Z",
  "burnedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "burnedDate": "2022-12-08T09:01:28.000Z"
}
Return Value Example (Fungible Token):
{
    "assetType": "otoken",
    "tokenId": "Loyalty",
    "tokenName": "loyalty",
    "tokenDesc": "Token Description",
    "tokenStandard": "erc1155+",
    "tokenType": "fungible",
    "tokenUnit": "fractional",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 10000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "Dollar"
}
Return Value Example (Fractional NFT):
{
    "tokenMetadata": {
        "painting_name": "paint",
        "description": "Painting Description"
    },
    "assetType": "otoken",
    "tokenId": "realEstate",
    "tokenName": "realestate",
    "tokenDesc": "Token Description",
    "tokenStandard": "erc1155+",
    "tokenType": "nonfungible",
    "tokenUnit": "fractional",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
    },
    "mintable": {
        "max_mint_quantity": 20000
    },
    "quantity": 100,
    "createdBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "creationDate": "2023-06-14T04:20:14.000Z",
    "divisible": {
        "decimal": 2
    },
    "isBurned": false,
    "tokenUri": "www.realestate.example.com",
    "price": 1000,
    "on_sale_flag": true,
    "owners": [
        {
            "accountId": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "tokenShare": 100
        }
    ]
}
getAllTokensByUser
This method returns all of the token assets that are owned by a specified user. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
Ctx.ERC1155Token.getAllTokensByUser(accountId: string)
Parameters:
  • accountId: string – The account ID of the user.
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenOne",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  },
  {
    "key": "nftToken",
    "valueJson": {
      "assetType": "otoken",
      "quantity": 1,
      "tokenId": "nftToken",
      "tokenName": "artcollection",
      "tokenStandard": "erc1155+",
      "tokenType": "nonfungible",
      "tokenUnit": "whole",
      "behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter"
      },
      "mintable": {
        "max_mint_quantity": 20000
      },
      "owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "createdBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "creationDate": "2022-12-08T09:10:21.000Z",
      "isBurned": false,
      "tokenUri": "example.com"
    }
  }
]
ownerOf
This method returns the account ID, organization ID, and user ID of the owner of the specified token ID.
Ctx.ERC1155Token.ownerOf(tokenId: string)
Parameters:
  • tokenId: string – The ID of the token.
Return Value Example:
{
    "accountId": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
    "orgId": "appdev",
    "userId": "idcqa"
}
tokenURI
This method returns the URI of a specified token. Anyone can call this method.
Ctx.ERC1155Token.tokenURI(tokenId: string)
Parameters:
  • tokenId: string – The ID of the token.
Return Value Example:
{
    "tokenUri": "example.com"
}
name
This method returns the name of the token class. Anyone can call this method.
Ctx.ERC1155Token.name(tokenId: string)
Parameters:
  • tokenId: string – The ID of the token.
Return Value Example:
{"tokenName": "artcollection"}
totalSupply
This method returns the total number of minted tokens. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
Ctx.ERC1155Token.totalSupply(token: any)
Parameters:
  • token: any – The token asset.
Return Value Example:
{"totalSupply": 110}
totalNetSupply
This method returns the total number of minted tokens minus the number of burned tokens. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
Ctx.ERC1155Token.totalNetSupply(token: any)
Parameters:
  • token: any – The token asset.
Return Value Example:
{"totalNetSupply": 105}
getTokensByName
This method returns all of the token assets for a specified token name. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
Ctx.ERC1155Token.getTokensByName(tokenName: string)
Parameters:
  • tokenName: string – The name of the token.
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenOne",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "assetType": "otoken",
      "tokenId": "tokenTwo",
      "tokenName": "moneytok",
      "tokenStandard": "erc1155+",
      "tokenType": "fungible",
      "tokenUnit": "fractional",
      "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner"
      },
      "mintable": {
        "max_mint_quantity": 1000
      },
      "divisible": {
        "decimal": 2
      }
    }
  }
]
getDecimals
This method returns the number of decimal places for a specified token. If the divisible behavior is not specified for the token, then the default value of zero decimal places is returned.
Ctx.ERC1155Token.getDecimals(token)
Parameters:
  • token: any – The token asset.
Return Value Example:
2

Methods for Account Management

createAccount
This method creates an account for a specified user and associated token accounts for fungible or non-fungible tokens. An account must be created for any user who will have tokens at any point. The user account tracks the NFT account and the fungible token accounts that a user has. Users must have accounts in the network to complete token-related operations. This method can be called only by a Token Admin of the chaincode.

A user account has a unique ID, which is formed by an SHA-256 hash of the orgId parameter and the userId parameter.

A user can have multiple fungible token accounts with unique account IDs. Fungible token account IDs are formed by an SHA-256 hash of the orgId parameter, the userId parameter, the constant string ft separated by the tilde symbol (~), and a counter number that signifies the index of the fungible account that is being created separated by the tilde symbol (~).

A user can have only one non-fungible token account. Non-fungible token account IDs are unique and are formed by an SHA-256 hash of the orgId parameter, the userId parameter, and the constant string nft separated by the tilde symbol (~). All non-fungible tokens that a user owns, whether whole or fractional, are linked to this single non-fungible token account.

Ctx.ERC1155Account.createAccount(orgId: string, userId: string, ftAccount: boolean, nftAccount: boolean)
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • ftAccount: boolean – If true, a fungible token account is created and associated with the user account.
  • nftAccount: boolean – If true, a non-fungible token account is created and associated with the user account.
Returns:
  • On success, a JSON object of the account that was created.
Return Value Example:
{
  "assetType": "ouaccount",
  "accountId": "ouaccount~cf20877546f52687f387e7c91d88b9722c97e1a456cc0484f40c747f7804feae",
  "userId": "user1",
  "orgId": "appdev",
  "totalAccounts": 2,
  "totalFtAccounts": 1,
  "associatedFtAccounts": [
    {
      "accountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
      "tokenId": ""
    }
  ],
  "associatedNftAccount": "oaccount~73c3e835dac6d0a56ca9d8def08269f83cefd59b9d297fe2cdc5a9083828fa58"
}
createUserAccount
This method creates an account for a specified user. An account must be created for any user who will have tokens at any point. The user account tracks the NFT account and the fungible token accounts that a user has. Users must have accounts in the network to complete token-related operations.

An account ID is an SHA-256 hash of the orgId parameter and the userIdparameter. This method can be called only by a Token Admin of the chaincode.

Ctx.ERC1155Account.createUserAccount(orgId: string, userId: string)
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a JSON object of the user account that was created.
Return Value Example:
{
  "assetType": "ouaccount",
  "accountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "userId": "idcqa",
  "orgId": "appdev",
  "totalAccounts": 0,
  "totalFtAccounts": 0,
  "associatedFtAccounts": [],
  "associatedNftAccount": ""
}
createTokenAccount
This method creates a fungible or non-fungible token account to associate with a user account.

A user can have multiple fungible token accounts with unique account IDs. Fungible token account IDs are formed by an SHA-256 hash of the orgId parameter, the userId parameter, the constant string ft separated by the tilde symbol (~), and a counter number that signifies the index of the fungible account that is being created separated by the tilde symbol (~).

A user can have only one non-fungible token account. Non-fungible token account IDs are unique and are formed by an SHA-256 hash of the orgId parameter, the userId parameter, and the constant string nft separated by the tilde symbol (~). All non-fungible tokens that a user owns, whether whole or fractional, are linked to this single non-fungible token account.

This method can be called only by a Token Admin of the chaincode.

Ctx.ERC1155Account.createTokenAccount(orgId: string, userId: string, tokenType: string)
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • tokenType: TokenType – The type of token account to create. The only supported token types are nonfungible and fungible.
Returns:
  • On success, a JSON object of the token account that was created.
Return Value Example:
{
  "assetType": "ouaccount",
  "accountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "userId": "idcqa",
  "orgId": "appdev",
  "totalAccounts": 1,
  "totalFtAccounts": 1,
  "associatedFtAccounts": [
    {
      "accountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
      "tokenId": ""
    }
  ],
  "associatedNftAccount": ""
}
associateTokenToToken
This method associates a user's fungible token account to a particular fungible token.
Ctx.ERC1155Account.associateTokenToToken(accountId: string, tokenId: string)
Parameters:
  • accountId: string – The user account ID.
  • tokenId: string – The ID of the token.
Returns:
  • On success, a JSON object of the user account, which shows that the fungible token was associated to the token account. For example, in the following example, the first object in the associatedFtAccounts array shows that the fungible token account ID and the token ID are associated.
Return Value Example:
{
  "assetType": "ouaccount",
  "accountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
  "userId": "idcqa",
  "orgId": "appdev",
  "totalAccounts": 1,
  "totalFtAccounts": 1,
  "associatedFtAccounts": [
    {
      "accountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
      "tokenId": "tokenOne"
    }
  ],
  "associatedNftAccount": ""
}
getAccountHistory
This method returns history for a specified token account.
Ctx.ERC1155Account.getAccountHistory(accountId: string)
Parameters:
  • accountId: string – The user account ID.
Returns:
  • On success, an array of JSON objects that describes the account history.
Return Value Example:
[
    {
        "trxId": "a2cfc6fc064334d6b9931cdf67193711ec2ff5c50a4714f11855fe7384f00e35",
        "timeStamp": "2023-06-06T14:44:31.000Z",
        "value": {
            "accountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "assetType": "oaccount",
            "bapAccountVersion": 1,
            "balance": 100,
            "orgId": "appdev",
            "tokenId": "loy1",
            "tokenName": "loyalty",
            "tokenType": "fungible",
            "userId": "idcqa"
        }
    },
    {
        "trxId": "de483cf7505ae4e7018c4b604c3ab9327c2fb1f802d9408e22735667c1d6997f",
        "timeStamp": "2023-06-06T14:43:23.000Z",
        "value": {
            "assetType": "oaccount",
            "bapAccountVersion": 0,
            "accountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "userId": "idcqa",
            "orgId": "appdev",
            "tokenType": "fungible",
            "tokenId": "loy1",
            "tokenName": "loyalty",
            "balance": 0
        }
    },
    {
        "trxId": "db053e653d3ad9aa5b7b6e04b7cd51aacfbb413272d857a155b60d2a6a12bf4d",
        "timeStamp": "2023-06-05T16:59:08.000Z",
        "value": {
            "assetType": "oaccount",
            "bapAccountVersion": 0,
            "accountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "userId": "idcqa",
            "orgId": "appdev",
            "tokenType": "fungible",
            "tokenId": "",
            "balance": 0
        }
    }
]
getAccountWithStatus
This method returns token account details, including account status, for a specified user. This method can be called only by a Token Admin of the chaincode or the Account Owner of the account.
Ctx.ERC1155Account.GetAccountWithStatus(accountId, tokenId...)
Parameters:
  • userAccountId: string – The account ID of the user.
  • tokenId?: string – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
Returns:
  • On success, a JSON object that includes token account details, including the account status.
Return Value Example (Non-Fungible Token Account):
{
    "assetType": "oaccount",
    "bapAccountVersion": 1,
    "status": "active",
    "accountId": "oaccount~cc301bee057f14236a97d434909ec1084970921b008f6baab09c2a0f5f419a9a",
    "userId": "idcqa",
    "orgId": "appdev",
    "tokenType": "nonfungible",
    "noOfNfts": 1
  }
Return Value Example (Fungible Token Account):
{
  "bapAccountVersion": 0,
  "assetType": "oaccount",
  "status": "active",
  "accountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "userId": "idcqa",
  "orgId": "appdev",
  "tokenType": "fungible",
  "tokenId": "t1",
  "tokenName": "loyalty",
  "balance": 0
}
getAccount
This method returns token account details for a specified user. This method can be called only by a Token Admin of the chaincode or the Account Owner of the account.
Ctx.ERC1155Account.getAccount(userAccountId: string, tokenId: string)
Parameters:
  • userAccountId: string – The account ID of the user.
  • tokenId?: string – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
Returns:
  • On success, a JSON object that includes token account details. The bapAccountVersion parameter is defined in the account object for internal use.
Return Value Example (Non-Fungible Token Account):
{
    "assetType": "oaccount",
    "bapAccountVersion": 0,
    "accountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
    "userId": "idcqa",
    "orgId": "appdev",
    "tokenType": "nonfungible",
    "noOfNfts": 3
}
Return Value Example (Fungible Token Account):
{
    "assetType": "oaccount",
    "bapAccountVersion": 0,
    "accountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
    "userId": "idcqa",
    "orgId": "appdev",
    "tokenType": "fungible",
    "tokenId": "loy1",
    "tokenName": "loyalty",
    "balance": 50
}
getAllAccounts
This method returns details of all user accounts.
Ctx.ERC1155Account.getAllAccounts()
Parameters:
  • none
Return Value Example:
[
        {
            "assetType": "ouaccount",
            "accountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
            "userId": "idcqa",
            "orgId": "appdev",
            "totalAccounts": 2,
            "totalFtAccounts": 1,
            "associatedFtAccounts": [
                {
                    "accountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
                    "tokenId": "loy1"
                }
            ],
            "associatedNftAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371"
        },
        {
            "assetType": "ouaccount",
            "accountId": "ouaccount~9501bb774c156eb8354dfe489250ea91f757523d70f08ee494bda98bb352003b",
            "userId": "user1_minter",
            "orgId": "appdev",
            "totalAccounts": 2,
            "totalFtAccounts": 1,
            "associatedFtAccounts": [
                {
                    "accountId": "oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c",
                    "tokenId": "loy1"
                }
            ],
            "associatedNftAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446"
        },
    ]
getAccountDetailsByUser
This method returns an account summary for a specified user and details of fungible and non-fungible tokens that are associated with the user..
Ctx.ERC1155Account.getAccountDetailsByUser(orgId: string, userId: string)
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a JSON account object that includes and account summary for the specified user and details of fungible and non-fungible tokens that are associated with the user. For fractional non-fungible tokens, the tokenShare property in the associatedNFTs section shows the share that the user owns
Return Value Example:
{
    "userAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
    "associatedFTAccounts": [
        {
            "accountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "tokenId": "FT",
            "balance": 50
        }
    ],
    "associatedNFTAccount": {
        "accountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "associatedNFTs": [
            {
                "nftTokenId": "FNFT",
                "tokenShare": 100
            },
            {
                "nftTokenId": "FNFT2",
                "tokenShare": 110
            },
            {
                "nftTokenId": "NFT"
            }
        ]
    }
}
getUserByAccountId
This method returns the user details of a specified account ID.
Ctx.ERC1155Account.getUserByAccountId(accountId: string)
Parameters:
  • accountId: string – The ID of the account.
Returns:
  • On success, a JSON object of the user details (orgId and userId).
Return Value Example:
{
    "orgId": "appdev",
    "userId": "idcqa"
}

Methods for Role Management

AddRoleMember
This method adds a role to a specified user and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
Ctx.ERC1155Token.addRoleMember(role: string, userAccountId: string, token: any)
Parameters:
  • userAccountId: string – The account ID of the user.
  • role: string – The name of the role to add to the specified user.
  • token: any – The token asset.
Returns:
  • On success, a message with account details.
Return Value Example:
{
  "msg": "Successfully added role 'minter' to Account Id: oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (Org-Id: appdev, User-Id: idcqa)"
}
isInRole
This method returns a Boolean value to indicate if a user has a specified role. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
Ctx.ERC1155Token.isInRole(role: string, userAccountId: string, token: any)
Parameters:
  • userAccountId: string – The account ID of the user.
  • role: string – The name of the role to search for.
  • token: any – The token asset.
Return Value Example:
{
    "result": true,
    "msg": "Account Id oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (Org-Id: appdev, User-Id: idcqa) has minter role"
}
removeRoleMember
This method removes a role from a specified user and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
Ctx.ERC1155Token.removeRoleMember(role: string, userAccountId: string, token: any)
Parameters:
  • userAccountId: string – The account ID of the user.
  • role: string – The name of the role to remove from the specified user.
  • token: any – The token asset.
Return Value Example:
{
  "msg": "Successfully removed role 'minter' from Account Id: oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b (Org-Id: appdev, User-Id: user1)"
}
getAccountsByRole
This method returns a list of all account IDs for a specified role and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
Ctx.ERC1155Token.getAccountsByRole(role: string, token: any)
Parameters:
  • role: string – The name of the role to search for.
  • token: any – The token asset.
Return Value Example:
{
  "accounts": [
    "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
    "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b"
  ]
}
getUsersByRole
This method returns a list of all users for a specified role and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
Ctx.ERC1155Token.getUsersByRole(role: string, token: any)
Parameters:
  • role: string – The name of the role to search for.
  • token: any – The token asset.
Return Value Example:
{
    "users": [
        {
            "accountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
            "orgId": "appdev",
            "userId": "idcqa"
        },
        {
            "accountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
            "orgId": "appdev",
            "userId": "user1"
        }
    ]
}

Methods for Transaction History Management

getAccountTransactionHistory
This method returns account transaction history. This method can be called only by a Token Admin of the chaincode or by the account owner. For non-fungible tokens, this method can only be called when connected to the remote Oracle Blockchain Platform network.
Ctx.ERC1155Account.getAccountTransactionHistory(accountId: string)
Parameters:
  • accountId: string – The token account ID.
Return Value Example:
[
    {
        "transactionId": "otransaction~3a6b23c3003626f3947e990eddbd7ac23398d2200e2eb3eac745e6ddfae140bc~7c88c736df38d5622512f1e8dcdd50710eb47c953f1ecb24ac44790a9e2f475b",
        "timestamp": "2023-06-06T14:48:08.000Z",
        "tokenId": "FNFT",
        "transactedAmount": 10,
        "triggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "transactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "transactionType": "DEBIT",
        "balance": 90
    },
    {
        "transactionId": "otransaction~3a6b23c3003626f3947e990eddbd7ac23398d2200e2eb3eac745e6ddfae140bc~178e3730bc5bee50d02f1464a4eebf733a051905f651e5789039adb4a3edc114",
        "timestamp": "2023-06-06T14:48:08.000Z",
        "tokenId": "NFT",
        "triggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "transactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "transactionType": "DEBIT"
    },
    {
        "transactionId": "otransaction~c369929e28e78de06c72d020f1418c9a154a7dd280b2e22ebb4ea4485e249124~a7cefb22ff39ee7e36967be71de27da6798548c872061a62dabc56d88d50b930",
        "timestamp": "2023-06-06T14:47:08.000Z",
        "tokenId": "NFT",
        "triggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "transactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "transactionType": "MINT"
    },
    {
        "transactionId": "otransaction~114a1bc78d04be48ee6dc140c32c042ee9481cb118959626f090eec744522422~e4eb15d9354f694230df8835ade012100d82aa43672896a2c7125a86e3048f9f",
        "timestamp": "2023-06-05T17:17:57.000Z",
        "tokenId": "FNFT",
        "transactedAmount": 100,
        "triggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "transactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "transactionType": "MINT",
        "balance": 100
    }
]
getTransactionById
This method returns the transaction details for a specified transaction ID.
Ctx.ERC1155Transaction.getTransactionById(transactionId: string)
Parameters:
  • transactionId: string – The ID of the transaction.
Return Value Example:
{
  "transactionId": "otransaction~9ea7b05ab099f7ff4db8342b8c3609031f1d54f11205906e7f1fe88661fe3cbe~33b59ce0c89e96c1e16449f24301581e8e71954f38ad977c7eb6f065e87f2a53",
  "history": [
    {
      "trxId": "9ea7b05ab099f7ff4db8342b8c3609031f1d54f11205906e7f1fe88661fe3cbe",
      "timeStamp": "2022-12-08T09:01:28.000Z",
      "value": {
        "assetType": "otransaction",
        "transactionId": "otransaction~9ea7b05ab099f7ff4db8342b8c3609031f1d54f11205906e7f1fe88661fe3cbe~33b59ce0c89e96c1e16449f24301581e8e71954f38ad977c7eb6f065e87f2a53",
        "tokenId": "tokenOne",
        "fromAccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
        "toAccountId": "",
        "transactionType": "BURN",
        "amount": 5,
        "timestamp": "2022-12-08T09:01:28.000Z",
        "triggeredByUserAccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc"
      }
    }
  ]
}
deleteTransactions
This method deletes transactions before a specified time stamp from the state database.
Ctx.ERC1155Transaction.deleteTransactions(referenceTime: Date)
Parameters:
  • referenceTime: Date – All transactions before this time stamp will be deleted.
Return Value Example:
{
  "msg": "Successfuly deleted transaction older than date: Thu Apr 07 2022 21:18:59 GMT+0000 (Coordinated Universal Time).",
  "transactions": [
    "otransaction~30513757d8b647fffaafac440d743635f5c1b2e41b25ebd6b70b5bbf78a2643f",
    "otransaction~ac0e908c735297941ba58bb208ee61ff4816a1e54c090d68024f82adf743892b"
  ]
}

Methods for Token Behavior Management - Mintable Behavior

mintBatch
This method creates (mints) multiple tokens in a batch operation. This method creates only fungible tokens or fractional non-fungible tokens.

For fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method. If not, any user can use this method to mint tokens. You cannot mint more than the max_mint_quantity property of the token, if that property was specified when the token was created or updated.

For non-fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method. If not, any user can use this method to mint tokens. Additionally, the caller must also be the creator of the token. There is no upper limit to the quantity of fractional non-fungible tokens that can be minted.

You cannot use this method to mint a whole non-fungible token.

Ctx.ERC1155Token.mintBatch(accountId: string, tokenIds: string[], quantities: number[])
Parameters:
  • accountId: string – The account ID of the user.
  • tokenIds: string[] – The list of token IDs to mint tokens for.
  • quantity: number[] – The list of quantities of tokens to mint, corresponding to the token ID array.
Returns:
  • On success, a JSON object that includes details on the minted tokens.
Return Value Example:
{
    "msg": "Successfully minted batch of tokens for User-Account-Id ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38 (Org-Id: appdev, User-Id: idcqa).",
    "details": [
        {
            "msg": "Successfully minted 100 tokens of fractional tokenId: plot55 to Org-Id: appdev, User-Id: idcqa"
        },
        {
            "msg": "Successfully minted 100 tokens of tokenId: loyalty to Token-Account-Id oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e"
        }
    ]
}

Methods for Token Behavior Management - Transferable Behavior

batchTransferFrom
This method completes a batch operation that transfers tokens specified in a list of token IDs from one user to another user.

For NFTs, because the method transfers ownership of the NFT, the sender of the NFT must own the token.

For fractional NFTs, if a user (including the creator of the token) transfers all of the shares that they own, then they lose ownership of the token. If any share of a token is transferred to a user, that user automatically becomes one of the owners of the fractional NFT.

This method does not validate that the caller of the method is the specified sender.

Ctx.ERC1155Token.batchTransferFrom(fromUserAccountId: string, toUserAccountId: string, tokenIds: string[], quantities: number[])
Parameters:
  • fromUserAccountId: string – The account ID of the sender and token owner in the current organization.
  • toUserAccountId: string – The account ID of the receiver.
  • tokenIds: string[] – A list of token IDs for the tokens to transfer.
  • quantity: number[] – The list of quantities of tokens to transfer, corresponding to the token ID array.
Returns:
  • On success, a message with details for each token transfer.
Return Value Example:
[
    {
        "msg": "Successfully transferred NFT token: 'FNFT' of '10' quantity from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred 10 FT token: 'FT' from Account-Id: oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred NFT token: 'NFT' from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    }
]
safeBatchtransferFrom
This method completes a batch operation that transfers tokens specified in a list of token IDs from one user to another user.

For NFTs, because the method transfers ownership of the NFT, the sender of the NFT must own the token.

For fractional NFTs, if a user (including the creator of the token) transfers all of the shares that they own, then they lose ownership of the token. If any share of a token is transferred to a user, that user automatically becomes one of the owners of the fractional NFT.

The caller of the method must be the specified sender.

Ctx.ERC1155Token.safeBatchTransferFrom(fromUserAccountId: string, toUserAccountId: string, tokenIds: string[], quantities: number[])
Parameters:
  • fromUserAccountId: string – The account ID of the sender and token owner in the current organization.
  • toUserAccountId: string – The account ID of the receiver.
  • tokenIds: string[] – A list of token IDs for the tokens to transfer.
  • quantity: number[] – The list of quantities of tokens to transfer, corresponding to the token ID array.
Returns:
  • On success, a message with details for each token transfer.
Return Value Example:
[
    {
        "msg": "Successfully transferred NFT token: 'FNFT' of '10' quantity from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred 10 FT token: 'FT' from Account-Id: oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (Org-Id: appdev, User-Id: user1_minter)"
    },
    {
        "msg": "Successfully transferred NFT token: 'NFT' from Account-Id: oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (Org-Id: appdev, User-Id: idcqa) to Account-Id: oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446 (Org-Id: appdev, User-Id: user1_minter)"
    }
]
balanceOfBatch
This method completes a batch operation that gets the balance of token accounts. The account details are specified in three separate lists of organization IDs, user IDs, and token IDs. This method can be called only by a Token Admin of the chaincode or by account owners. Account owners can see balance details only for accounts that they own.
Ctx.ERC1155Account.balanceOfBatch(accountIds: string[], tokenIds: string[])
Parameters:
  • accountIds: string[] – A list of the user account IDs.
  • tokenIds: string[] – A list of the token IDs.
Return Value Example:
[
    {
        "orgId": "appdev",
        "userId": "idcqa",
        "userAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "tokenAccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "tokenId": "FNFT",
        "balance": 100
    },
    {
        "orgId": "appdev",
        "userId": "idcqa",
        "userAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "tokenAccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
        "tokenId": "FT",
        "balance": 50
    },
    {
        "orgId": "appdev",
        "userId": "user1_minter",
        "userAccountId": "ouaccount~9501bb774c156eb8354dfe489250ea91f757523d70f08ee494bda98bb352003b",
        "tokenAccountId": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "tokenId": "FNFT",
        "balance": 10
    }
]
exchangeToken
This method exchanges tokens between specified accounts. This method only supports exchanging between an NFT (whole or fractional) and a fungible token or a fungible token and an NFT (whole or fractional). This method can be called only by the account owner.
Ctx.ERC1155Token.exchangeToken( fromTokenId: string, fromUserAccountId: string, fromTokenQuantity: number, toTokenId: string, toUserAccountId: string, toTokenQuantity: number)
Parameters:
  • fromTokenId: string – The ID of the token that the sender owns.
  • fromUserAccountId: string – The account ID of the sender.
  • fromTokenQuantity: number – The quantity of tokens from the sender to exchange with the receiver.
  • toTokenId: string – The ID of the token that the receiver owns.
  • toUserAccountId: string – The account ID of the receiver.
  • toTokenQuantity: number – The quantity of tokens from the receiver to exchange with the sender.
Returns:
  • On success, a message with token exchange details.
Return Value Example:
{
    "msg": "Succesfully exchanged 10 tokens of type nonfungible with tokenId: [r1] from Account oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371 (OrgId: appdev, UserId: idcqa) to 10 tokens of type fungible with tokenId: [loy1] from Account oaccount~1089ee5122f367ee0ca38c6660298f4b81f199627e4f67f3691c0f628237974c (OrgId: appdev, UserId: user1_minter)"
}

Methods for Token Behavior Management - Burnable Behavior

burn
This method deactivates, or burns, the specified fungible and non-fungible tokens.
Ctx.ERC1155Token.burn(accountId: string, tokenIds: string[], quantities: number[])
Parameters:
  • accountId: string – The account ID of the user.
  • tokenIds: string[] – The list of token IDs to burn.
  • quantity: number[] – The list of quantities of tokens to burn, corresponding to the token ID array.
Returns:
  • On success, a message with details about the burn operations.
Return Value Example:
[
  {
    "msg": "Successfully burned NFT token: 'art' from Account-Id: oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6 (Org-Id: appdev, User-Id: idcqa)"
  },
  {
    "msg": "Successfully burned 5 tokens of tokenId: tokenOne from Account-ID oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (Org-Id: appdev, User-Id: idcqa)"
  },
  {
    "msg": "Successfully burned 2 token share of tokenId: FNFT from Account-ID oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a (Org-Id: AutoF1377358917, User-Id: idcqa)"
  }
]