Scaffolded Go 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 Go Chaincode Project.

Model

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

package model

type ArtCollection struct {
	AssetType     string `json:"AssetType" final:"otoken"`
	TokenId       string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
	TokenName     string `json:"TokenName" final:"artcollection"`
	TokenDesc     string `json:"TokenDesc" validate:"max=256"`
	TokenStandard string `json:"TokenStandard" final:"erc1155+"`
	TokenType     string `json:"TokenType" final:"nonfungible" validate:"regexp=^nonfungible$"`
	TokenUnit     string `json:"TokenUnit" final:"whole" validate:"regexp=^whole$"`

	Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":20000}"`

	Behaviors []string `json:"Behaviors" final:"[\"indivisible\",\"singleton\",\"mintable\",\"transferable\",\"burnable\",\"roles\"]"`

	Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`

	Owner           string `json:"Owner,omitempty" validate:"string"`
	CreatedBy       string `json:"CreatedBy,omitempty" validate:"string"`
	TransferredBy   string `json:"TransferredBy,omitempty" validate:"string"`
	CreationDate    string `json:"CreationDate,omitempty" validate:"string"`
	TransferredDate string `json:"TransferredDate,omitempty" validate:"string"`
	IsBurned        bool   `json:"IsBurned" validate:"bool"`
	BurnedBy        string `json:"BurnedBy,omitempty" validate:"string"`
	BurnedDate      string `json:"BurnedDate,omitempty" validate:"string"`
	TokenUri        string `json:"TokenUri" mandatory:"true" validate:"string,max=2000"`

	TokenMetadata ArtCollectionMetadata `json:"TokenMetadata"`

	Price        int  `json:"Price" validate:"int"`
	On_sale_flag bool `json:"On_sale_flag" validate:"bool"`
}

type ArtCollectionMetadata struct {
	Painting_name string `json:"Painting_name" validate:"string"`
	Description   string `json:"Description" validate:"string"`
	Image         string `json:"Image" validate:"string"`
	Painter_name  string `json:"Painter_name" validate:"string"`
}

type Loyalty struct {
	AssetType     string `json:"AssetType" final:"otoken"`
	TokenId       string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
	TokenName     string `json:"TokenName" final:"loyalty"`
	TokenDesc     string `json:"TokenDesc" validate:"max=256"`
	TokenStandard string `json:"TokenStandard" final:"erc1155+"`
	TokenType     string `json:"TokenType" final:"fungible" validate:"regexp=^fungible$"`
	TokenUnit     string `json:"TokenUnit" final:"fractional" validate:"regexp=^fractional$"`

	Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":10000}"`

	Divisible map[string]interface{} `json:"Divisible" final:"{\"Decimal\":2}"`

	Behaviors []string `json:"Behaviors" final:"[\"divisible\",\"mintable\",\"transferable\",\"burnable\",\"roles\"]"`

	Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`

	Currency_name           string      `json:"Currency_name" validate:"string"`
	Token_to_currency_ratio int         `json:"Token_to_currency_ratio" validate:"int"`
	Metadata                interface{} `json:"Metadata,omitempty"`
}
The following model shows a fractional non-fungible token.
type RealEstateProperty struct {
      AssetType string `json:"AssetType" final:"otoken"`
      TokenId string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
      TokenName string `json:"TokenName" final:"realestateproperty"`
      TokenDesc string `json:"TokenDesc" validate:"max=256"`
      TokenStandard string `json:"TokenStandard" final:"erc1155+"`
      TokenType string `json:"TokenType" final:"nonfungible" validate:"regexp=^nonfungible$"`
      TokenUnit string `json:"TokenUnit" final:"fractional" validate:"regexp=^fractional$"`

      Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":0}"`
      Behaviors []string `json:"Behaviors" final:"[\"divisible\",\"mintable\",\"transferable\",\"roles\"]"`

      Divisible map[string]interface{} `json:"Divisible" final:"{\"Decimal\":0}"`

      Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`

      CreatedBy string `json:"CreatedBy,omitempty" validate:"string"`
      CreationDate string `json:"CreationDate,omitempty" validate:"string"`
      IsBurned bool `json:"IsBurned" validate:"bool"`
      TokenUri string `json:"TokenUri" mandatory:"true" validate:"string,max=2000"`
      Quantity float64 `json:"Quantity,omitempty"`
      TokenMetadata RealEstatePropertyMetadata `json:"TokenMetadata"`

      PropertySellingPrice int `json:"PropertySellingPrice" validate:"int"`
      PropertyRentingPrice int `json:"PropertyRentingPrice" validate:"int"`
}

type RealEstatePropertyMetadata struct {
      PropertyType string `json:"PropertyType" validate:"string"`
      PropertyName string `json:"PropertyName" validate:"string"`
      PropertyAddress string `json:"PropertyAddress" validate:"string"`
      PropertyImage string `json:"PropertyImage" validate:"string"`
}

Controller

There is only one main controller.

type Controller struct {
    Ctx trxcontext.TrxContext
}

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 be public to be invokable. Public method names begin with an upper case character. Method names that begin with a lower case character are private.

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 the Token Admin of the chaincode.
func (t *Controller) IsTokenAdmin(orgId string, userId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Admin.IsUserTokenAdmin", "TOKEN", map[string]string{"orgId": orgId, "userId": userId})
            if err != nil || !auth {
                  return false, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Auth.IsUserTokenAdmin(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.
func (t *Controller) AddTokenAdmin(orgId string, userId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Admin.AddAdmin", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.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.
func (t *Controller) RemoveTokenAdmin(orgId string, userId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Admin.RemoveAdmin", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.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 the Token Admin of the chaincode.
func (t *Controller) GetAllTokenAdmins() (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Admin.GetAllAdmins", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Admin.GetAllAdminUsers()
      }
Parameters:
  • none
Returns:
  • On success, an admins array in JSON format.
Return Value Example:
{
  "admins": [
    {
      "OrgId": "appdev",
      "UserId": "idcqa"
    },
    {
      "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.
func (t *Controller) Init(adminList []erc1155Admin.ERC1155TokenAdminAsset) (interface{}, error) {
      list, err := t.Ctx.ERC1155Admin.InitAdmin(adminList)
      if err != nil {
            return nil, fmt.Errorf("initialising admin list failed %s", err.Error())
      }
      <1st Token Name> := <1st TokenClassName>{}
      _, err = t.Ctx.ERC1155Token.SaveClassInfo(&<1st Token Name>)
      if err != nil {
            return nil, err
      }
         .
         .
      <nth Token Name> := <nth TokenClassName>{}
      _, err = t.Ctx.ERC1155Token.SaveClassInfo(&<nth Token Name>)
      if err != nil {
            return nil, err
      }
      _, err = t.Ctx.ERC1155Token.SaveDeleteTransactionInfo()
      if err != nil {
            fmt.Println("error: ", err)
      }
      return list, err
}
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:
func (t *Controller) Create<Token Name>Token(tokenAsset <Token Class>) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.Save", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.Save(&tokenAsset)
    }
Non-Fungible Tokens:
func (t *Controller) Create<Token Name>Token(tokenAsset <Token Class>, quantity float64) (interface{}, error) {
         quantityToPass := []float64{quantity}
          return t.Ctx.ERC1155Token.Save(&tokenAsset, quantityToPass...)
    }
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.
  • Behaviors – A list of token behaviors. This property cannot be edited.
  • 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.
  • 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.
  • Symbol – The symbol of the token. This property cannot be edited.
  • TokenDesc – The description of the token.
  • TokenMetadata – JSON information that describes the token.
  • TokenName – The name 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.
  • TokenUri – The URI of the token.
  • Quantity – The quantity of the token.
Return Value Example (Whole NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-12-29T09:57:03+05:30",
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 500
    },
    "OnSaleFlag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 100,
    "Quantity": 1,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "token description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
Return Value Example (Fungible Token):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Currency_name": "Dollar",
    "Divisible": {
        "Decimal": 2
    },
    "Mintable": {
        "Max_mint_quantity": 10000
    },
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "Loyalty",
    "TokenName": "loyalty",
    "TokenStandard": "erc1155+",
    "TokenType": "fungible",
    "TokenUnit": "fractional",
    "Token_to_currency_ratio": 0
}
Return Value Example (Fractional NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-06-14T09:53:53+05:30",
    "Divisible": {
        "Decimal": 2
    },
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Price": 1000,
    "Quantity": 100,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "realEstate",
    "TokenMetadata": {
        "Description": "Painting Description",
        "Image": "",
        "Painter_name": "",
        "Painting_name": "Paint"
    },
    "TokenName": "realestate",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "fractional",
    "TokenUri": "www.realestate.example.com"
}
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:
func (t *Controller) Update<%=tokenModelName%>Token(tokenAsset <%=tokenModelName%>) (interface{}, error) {
        auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.Update", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.Update(&tokenAsset)
    }
Non-Fungible Tokens:
func (t *Controller) Update<%=tokenModelName%>Token(tokenAsset <%=tokenModelName%>) (interface{}, error) {
            return t.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):
{
    "AssetType": "otoken",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-12-29T09:57:03+05:30",
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 500
    },
    "OnSaleFlag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 100,
    "Quantity": 1,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "token description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
GetTokenHistory
This method returns the history for a specified token ID. Anyone can call this method.
func (t *Controller) GetTokenHistory(tokenId string) (interface{}, error) {
            return t.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):
[
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-08T09:54:11Z",
    "TxId": "823sa7c7a00941c62285c86f922bc4d3f5326a20f4bf2f82daa5bc661e4682e8",
    "Value": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "Rupees",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "Updated Token Description",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-08T09:54:11Z",
    "TxId": "711bb7c7a00941c62285c86f922bc3b3f5326a20f4bf2f82daa5bc661e4682e8",
    "Value": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "Dollar",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  }
]
Return Value Example (Fractional NFT):
[
    {
        "Timestamp": "2023-06-20T01:06:33Z",
        "TrxId": "16e53db4f8107f9634b7c3a0a2a81a00f69b634f2a52902b809e544d07f272b1",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:02:27Z",
            "Divisible": {
                "Decimal": 2
            },
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owners": [
                {
                    "AccountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "TokenShare": 10
                },
                {
                    "AccountId": "oaccount~3cddfdaa855900579d963aa6f755a4aed1f3a474a2462c1b45bd7f36df673224",
                    "TokenShare": 10
                }
            ],
            "Price": 2000,
            "Quantity": 20,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "FNFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "realestate",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "fractional",
            "TokenUri": "www.FNFT.example.com"
        }
    },
    {
        "Timestamp": "2023-06-20T01:02:27Z",
        "TrxId": "cec80910d087682554048f911d2cf98b66382bbcf1615483fa1c96c7ea08077c",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:02:27Z",
            "Divisible": {
                "Decimal": 2
            },
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owners": [
                {
                    "AccountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "TokenShare": 20
                }
            ],
            "Price": 2000,
            "Quantity": 20,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "FNFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "realestate",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "fractional",
            "TokenUri": "www.FNFT.example.com"
        }
    }
]
Return Value Example (Whole NFT):
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-20T01:15:56Z",
        "TxId": "89a3df3ebbe6dca2bcfbd51fc7dca9aab818a2af746b79a92dc8155b729ab22d",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:15:56Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owner": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "Price": 2000,
            "Quantity": 1,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "Updated Token Description",
            "TokenId": "NFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "artcollection",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "www.NFT.example.com"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-20T01:15:56Z",
        "TxId": "90d6af3ebbe6dca2bcfbd51fc7dca9aab818a2af746b79a92dc8155b729ab22d",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:15:56Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owner": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "Price": 2000,
            "Quantity": 1,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "NFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "artcollection",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "www.NFT.example.com"
        }
    }
]
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.
func (t *Controller) GetAllTokens() (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.GetAllTokens", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.GetAllTokens()
      }
Parameters:
  • none
Returns:
  • A list of all token assets in JSON format.
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenTwo",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "art",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "BurnedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "BurnedDate": "2022-12-08T10:49:37Z",
      "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "CreationDate": "2022-12-08T10:45:10Z",
      "IsBurned": true,
      "Mintable": {
        "Max_mint_quantity": 20000
      },
      "OnSaleFlag": false,
      "Owner": "",
      "Price": 0,
      "Roles": {
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "art",
      "TokenMetadata": {
        "Description": "",
        "Image": "",
        "PainterName": "",
        "PaintingName": ""
      },
      "TokenName": "artcollection",
      "TokenStandard": "erc1155+",
      "TokenType": "nonfungible",
      "TokenUnit": "whole",
      "TokenUri": "art.example.com",
      "TransferredBy": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
      "TransferredDate": "2022-12-08T10:47:04Z"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "AssetType": "otoken",
        "Behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "CreationDate": "2023-06-20T01:02:27Z",
        "Divisible": {
            "Decimal": 2
        },
        "IsBurned": false,
        "Mintable": {
            "Max_mint_quantity": 20000
        },
        "On_sale_flag": true,
        "Price": 2000,
        "Quantity": 20,
        "Roles": {
            "burner_role_name": "burner",
            "minter_role_name": "minter"
        },
        "TokenDesc": "",
        "TokenId": "FNFT",
        "TokenMetadata": {
            "Description": "",
            "Image": "",
            "Painter_name": "",
            "Painting_name": ""
        },
        "TokenName": "realestate",
        "TokenStandard": "erc1155+",
        "TokenType": "nonfungible",
        "TokenUnit": "fractional",
        "TokenUri": "www.FNFT.example.com"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "AssetType": "otoken",
        "Behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "CreationDate": "2023-06-20T01:02:27Z",
        "Divisible": {
            "Decimal": 2
        },
        "IsBurned": false,
        "Mintable": {
            "Max_mint_quantity": 20000
        },
        "On_sale_flag": true,
        "Price": 2000,
        "Quantity": 20,
        "Roles": {
            "burner_role_name": "burner",
            "minter_role_name": "minter"
        },
        "TokenDesc": "",
        "TokenId": "FNFT",
        "TokenMetadata": {
            "Description": "",
            "Image": "",
            "Painter_name": "",
            "Painting_name": ""
        },
        "TokenName": "realestate",
        "TokenStandard": "erc1155+",
        "TokenType": "nonfungible",
        "TokenUnit": "fractional",
        "TokenUri": "www.FNFT.example.com"
    }
  }
]
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.
func (t *Controller) GetTokenById(tokenId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.Get", "TOKEN", map[string]string{"tokenId": tokenId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.GetTokenById(tokenId)
      }
Parameters:
  • tokenId string – The ID of the token to get.
Return Value Example (Whole NFT):
{
  "AssetType": "otoken",
  "Behaviors": [
    "indivisible",
    "singleton",
    "mintable",
    "transferable",
    "burnable",
    "roles"
  ],
  "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "CreationDate": "2022-12-08T10:55:29Z",
  "IsBurned": false,
  "Mintable": {
    "Max_mint_quantity": 20000
  },
  "OnSaleFlag": false,
  "Owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "Price": 0,
  "Quantity": 1,
  "Roles": {
    "minter_role_name": "minter"
  },
  "TokenDesc": "",
  "TokenId": "nftToken",
  "TokenMetadata": {
    "Description": "",
    "Image": "",
    "PainterName": "",
    "PaintingName": ""
  },
  "TokenName": "artcollection",
  "TokenStandard": "erc1155+",
  "TokenType": "nonfungible",
  "TokenUnit": "whole",
  "TokenUri": "nftToken.example.com"
}
Return Value Example (Fungible Token):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Currency_name": "Dollar",
    "Divisible": {
        "Decimal": 2
    },
    "Mintable": {
        "Max_mint_quantity": 10000
    },
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "Loyalty",
    "TokenName": "loyalty",
    "TokenStandard": "erc1155+",
    "TokenType": "fungible",
    "TokenUnit": "fractional",
    "Token_to_currency_ratio": 0
}
Return Value Example (Fractional NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-06-14T09:53:53+05:30",
    "Divisible": {
        "Decimal": 2
    },
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Owners": [
        {
            "AccountId": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "TokenShare": 100
        }
    ],
    "Price": 1000,
    "Quantity": 100,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "realEstate",
    "TokenMetadata": {
        "Description": "Painting Description",
        "Image": "",
        "Painter_name": "",
        "Painting_name": "Paint"
    },
    "TokenName": "realestate",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "fractional",
    "TokenUri": "www.realestate.example.com"
}
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.
func (t *Controller) GetAllTokensByUser(orgId string, userId string) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAllTokensByUser. Error: %s", err)
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.GetAllTokensByUser", "TOKEN", map[string]string{"accountId": accountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.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",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "nftToken",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "CreationDate": "2022-12-08T10:55:29Z",
      "IsBurned": false,
      "Mintable": {
        "Max_mint_quantity": 20000
      },
      "OnSaleFlag": false,
      "Owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "Price": 0,
      "Quantity": 1,
      "Roles": {
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "nftToken",
      "TokenMetadata": {
        "Description": "",
        "Image": "",
        "PainterName": "",
        "PaintingName": ""
      },
      "TokenName": "artcollection",
      "TokenStandard": "erc1155+",
      "TokenType": "nonfungible",
      "TokenUnit": "whole",
      "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.
func (t *Controller) OwnerOf(tokenId string) (interface{}, error) {
            return t.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.
func (t *Controller) URI(tokenId string) (interface{}, error) {
            return t.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.
func (t *Controller) Name(tokenId string) (interface{}, error) {
            return t.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.
func (t *Controller) TotalSupply(tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.TotalSupply", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Token.TotalSupply(token)
      }
Parameters:
  • tokenDetails erc1155Role.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": 100
}
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.
func (t *Controller) TotalNetSupply(tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.TotalNetSupply", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Token.TotalNetSupply(token)
      }
Parameters:
  • tokenDetails erc1155Role.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": 900
}
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.
func (t *Controller) GetTokensByName(tokenName string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.GetTokensByName", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Token.GetTokensByName(tokenName)
      }
Parameters:
  • tokenName: string – The name of the token.
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenTwo",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  }
]
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.
func (t *Controller) GetTokenDecimal(tokenId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.GetTokenDecimal", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            tokenDecimal, err := t.Ctx.ERC1155Token.GetDecimals(tokenId)
            if err != nil {
                  return nil, fmt.Errorf("error in GetTokenDecimal: %s", err.Error())
            }
            response := make(map[string]interface{})
            response["msg"] = fmt.Sprintf("Token Id: %s has %d decimal places.", tokenId, tokenDecimal)
            return response, nil
      }
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 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 account.

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

func (t *Controller) CreateAccount(orgId string, userId string, ftAccount bool, nftAccount bool) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.CreateAccount", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.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 bool – If true, a fungible token account is created and associated with the user account.
  • nftAccount bool – 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.

func (t *Controller) CreateUserAccount(orgId string, userId string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.CreateUserAccount", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.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": "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 account.

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

func (t *Controller) CreateTokenAccount(orgId string, userId string, tokenType erc1155Token.TokenType) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.CreateTokenAccount", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            typeOfToken, err := tokenType.GetTokenType()
          if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Account.CreateTokenAccount(orgId, userId, typeOfToken)
      }
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 erc1155Token.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": ""
}
AssociateFungibleTokenAccount
This method associates a user's fungible token account to a particular fungible token.

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

func (t *Controller) AssociateFungibleTokenToAccount(orgId string, userId string, tokenId string) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in generating accountId. Error: %s", err)
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.AssociateFungibleTokenToAccount", "TOKEN", map[string]string{"accountId": accountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.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": "idcqa",
    "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 the Token Admin of the chaincode or by the account owner.
func (t *Controller) GetAccountHistory(orgId string, userId string, tokenId ...string) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountHistory. Error: %s", err)
            }
            _, err = t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.History", "TOKEN", map[string]string{"accountId": userAccountId})
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountHistory. Error: %s", err)
            }
            tokenAccount, err := t.Ctx.ERC1155Account.Get(userAccountId, tokenId...)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountHistory. Error: %s", err)
            }
            tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountHistory. Error: %s", err)
            }
            return t.Ctx.ERC1155Account.GetAccountHistory(tokenAccountId)
      }
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:
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-06T11:03:48Z",
        "TxId": "c5180f3be3d9130f25a4b4e866f38a4283117dcbfbffb4f55e2c5b03dba0dd29",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 100,
            "BapAccountVersion": 1
            "OrgId": "appdev",
            "TokenId": "loy1",
            "TokenName": "loyalty",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-06T11:02:39Z",
        "TxId": "6f81b0c94b451d375a3892446aefbdf78d9fd1ac43699daa89f0dff10db5fd22",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 0,
            "BapAccountVersion": 0
            "OrgId": "appdev",
            "TokenId": "loy1",
            "TokenName": "loyalty",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-05T16:28:46Z",
        "TxId": "8185af648546e909488e72149be497b210f74f95ada252c42da9c35cb9d98691",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 0,
            "BapAccountVersion": 0
            "OrgId": "appdev",
            "TokenId": "",
            "TokenName": "",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    }
]
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.
func (t *Controller) GetAccount(orgId string, userId string, tokenId ...string) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.GetAccount", "TOKEN", map[string]string{"accountId": accountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Account.GetAccountWithStatus(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 – 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 and AccountCategory parameters are defined in the account object for internal use.
Return Value Example (Non-Fungible Token Account):
{
  "AccountId": "oaccount~cc301bee057f14236a97d434909ec1084970921b008f6baab09c2a0f5f419a9a",
  "AssetType": "oaccount",
  "BapAccountVersion": 1,
  "NoOfNfts": 1,
  "OrgId": "appdev",
  "Status": "active",
  "TokenType": "nonfungible",
  "UserId": "idcqa"
}
Return Value Example (Fungible Token Account):
{
  "AccountCategory": "",
  "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "AssetType": "oaccount",
  "Balance": 0,
  "BapAccountVersion": 0,
  "OrgId": "appdev",
  "Status": "active",
  "TokenId": "t1",
  "TokenName": "loyalty",
  "TokenType": "fungible",
  "UserId": "idcqa"
}
GetAllAccounts
This method returns details of all user accounts. This method can be called only by a Token Admin of the chaincode.
func (t *Controller) GetAllAccounts() (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.GetAllAccounts", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.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": 3,
        "TotalFtAccounts": 2,
        "AssociatedFtAccounts": [
            {
                "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
                "TokenId": "loy1"
            },
            {
                "AccountId": "oaccount~58c5a6b09a41befca2a9ea2550439838c4dcf4d8a2a4f7c98e9319cf8479bfc4",
                "TokenId": ""
            }
        ],
        "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.
func (t *Controller) GetAccountDetailsByUser(orgId string, userId string) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.GetAccountDetailsByUser", "TOKEN", map[string]string{"accountId": accountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.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:
{
    "AssociatedFTAccounts": [
        {
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "Balance": 90,
          "TokenId": "FT"
        },
    ],
    "AssociatedNFTAccount": {
        "AccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "AssociatedNFTs": [
            {
              "NFTTokenId": "FNFT",
                "TokenShare": 230
            },
            {
              "NFTTokenId": "NFT"
            },
            {
              "NFTTokenId": "NFT2"
            }
        ]
    },
    "UserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
}
GetUserByAccountId
This method returns the user details of a specified account ID. This method can be called by any user.
func (t *Controller) GetUserByAccountId(accountId string) (interface{}, error) {
            return t.Ctx.ERC1155Account.GetUserByAccountById(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.
func (t *Controller) AddRole(orgId string, userId string, role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.AddRoleMember", "TOKEN", map[string]string{"accountId": userAccountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.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 erc1155Role.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 oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (orgId : appdev, userId : 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 the 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.
func (t *Controller) IsInRole(orgId string, userId string, role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.IsInRole", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            var result bool
            result, err = t.Ctx.ERC1155Token.IsInRole(role, userAccountId, token)
            if err != nil {
                  return nil, fmt.Errorf("error in IsInRole %s", err.Error())
            }
            response := make(map[string]interface{})
            response["result"] = result
            return response, nil
      }
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 erc1155Role.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
}
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 the 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.
func (t *Controller) RemoveRole(orgId string, userId string, role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, err
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Token.RemoveRoleMember", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.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 erc1155Role.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~ec7e4de2f81e3ea071710e07b6ff7d9346e84ef665ca4650885dbe8c3e2bd4c0 (Org-Id: appdev, User-Id: idcqa)"
}
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 the Token Admin of the chaincode.
func (t *Controller) GetAccountsByRole(role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Role.GetAccountsByRole", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Role.GetAccountsByRole(role, token)
      }
Parameters:
  • role: string – The name of the role to search for.
  • tokenDetails erc1155Role.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 the Token Admin of the chaincode.
func (t *Controller) GetUsersByRole(role string, tokenDetail erc1155Role.TokenDetail) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Role.GetUsersByRole", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            token, err := t.Ctx.ERC1155Token.GetTokenByIdOrName(tokenDetail)
            if err != nil {
                  return nil, err
            }
            return t.Ctx.ERC1155Role.GetUsersByRole(role, token)
      }
Parameters:
  • role: string – The name of the role to search for.
  • tokenDetails erc1155Role.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": "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.
func (t *Controller) GetAccountTransactionHistory(orgId string, userId string, tokenId ...string) (interface{}, error) {
            userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountTransactionHistory. Error: %s", err)
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.GetAccountTransactionHistory", "TOKEN", map[string]string{"accountId": userAccountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            tokenAccount, err := t.Ctx.ERC1155Account.Get(userAccountId, tokenId...)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountTransactionHistory. Error: %s", err)
            }
            tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
            if err != nil {
                  return nil, fmt.Errorf("error in GetAccountTransactionHistory. Error: %s", err)
            }
            return t.Ctx.ERC1155Account.GetAccountTransactionHistory(tokenAccountId)
      }
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:
[
    {
        "Balance": 90,
        "Timestamp": "2023-06-06T11:11:09Z",
        "TokenId": "FNFT",
        "TransactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TransactedAmount": 10,
        "TransactionId": "otransaction~0f4d96fbf8fed88ea8a3133428977721091467c701848d595ebc3fffa88b3657~7c88c736df38d5622512f1e8dcdd50710eb47c953f1ecb24ac44790a9e2f475b",
        "TransactionType": "DEBIT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Timestamp": "2023-06-06T11:11:09Z",
        "TokenId": "NFT",
        "TransactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TransactionId": "otransaction~0f4d96fbf8fed88ea8a3133428977721091467c701848d595ebc3fffa88b3657~178e3730bc5bee50d02f1464a4eebf733a051905f651e5789039adb4a3edc114",
        "TransactionType": "DEBIT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Timestamp": "2023-06-06T11:06:54Z",
        "TokenId": "NFT",
        "TransactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TransactionId": "otransaction~6a13667ea3f6edc4c854e85b127526eccb58783f653c348b42a3869f0f29a4fb~a7cefb22ff39ee7e36967be71de27da6798548c872061a62dabc56d88d50b930",
        "TransactionType": "MINT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Balance": 100,
        "Timestamp": "2023-06-05T16:34:33Z",
        "TokenId": "FNFT",
        "TransactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TransactedAmount": 100,
        "TransactionId": "otransaction~2bc15de1766d582d821bd8d61756bca02837dc683c0aa61f69657ccd1d95e335~e4eb15d9354f694230df8835ade012100d82aa43672896a2c7125a86e3048f9f",
        "TransactionType": "MINT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    }
]
GetTransactionById
This method returns the transaction details for a specified transaction ID. Anyone can call this method.
func (t *Controller) GetTransactionById(transactionId string) (interface{}, error) {
            return t.Ctx.ERC1155Transaction.GetTransactionById(transactionId)
      }
Parameters:
  • transactionId: string – The ID of the transaction.
Return Value Example:
{
    "history": [
        {
            "IsDelete": "false",
            "Timestamp": "2022-12-08T10:45:56Z",
            "TxId": "2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98",
            "Value": {
                "Amount": 5,
                "AssetType": "otransaction",
                "FromAccountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
                "Timestamp": "2022-12-08T10:45:56Z",
                "ToAccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
                "TokenId": "tokenOne",
                "TransactionId": "otransaction~2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98~9c3ce5f21abd98ca018c196086d73a812f2f49dba323f1de4f6867eecfeec8ff",
                "TransactionType": "TRANSFER",
                "TriggeredByUserAccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc"
            }
        }
    ],
    "transactionId": "otransaction~2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98~9c3ce5f21abd98ca018c196086d73a812f2f49dba323f1de4f6867eecfeec8ff"
}
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.
func (t *Controller) DeleteHistoricalTransactions(timestamp string) (interface{}, error) {
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Transaction.DeleteHistoricalTransactions", "TOKEN")
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            return t.Ctx.ERC1155Transaction.DeleteHistoricalTransactions(timestamp)
      }
Parameters:
  • timestamp: string – All transactions before this time stamp will be deleted.
Return Value Example:
{
    "Transactions": [
        "otransaction~750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7"
    ],
    "msg": "Successfuly deleted transaction older than date:2022-04-06T08:17:53Z"
}

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.

func (t *Controller) MintBatch(orgId string, userId string, tokenIds []string, quantity []float64) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in generating the accountId. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  tokens = append(tokens, tokenAssetValue.Interface())
            }
            return t.Ctx.ERC1155Token.MintBatch(accountId, tokens, 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 []float64 – 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:
{
    "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'"
        }
    ],
    "msg": "Successfully minted batch of tokens for User-Account-Id 'ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38' (Org-Id: 'appdev', User-Id: 'idcqa')"
}

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.

func (t *Controller) BatchTransferFrom(fromOrgId string, fromUserId string, toOrgId string, toUserId string, tokenIds []string, quantity []float64) (interface{}, error) {
            fromAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(fromOrgId, fromUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            toAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(toOrgId, toUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  tokens = append(tokens, tokenAssetValue.Interface())
            }
            return t.Ctx.ERC1155Token.BatchTransferFrom(fromAccountId, toAccountId, tokens, 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 float64[] – 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.

func (t *Controller) SafeBatchTransferFrom(fromOrgId string, fromUserId string, toOrgId string, toUserId string, tokenIds []string, quantity []float64) (interface{}, error) {
            fromAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(fromOrgId, fromUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            toAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(toOrgId, toUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  tokens = append(tokens, tokenAssetValue.Interface())
            }
            return t.Ctx.ERC1155Token.SafeBatchTransferFrom(fromAccountId, toAccountId, tokens, 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 float64[] – 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.
func (t *Controller) BalanceOfBatch(orgIds []string, userIds []string, tokenIds []string) (interface{}, error) {
            callerAccountCheck := false
            _, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.BalanceOfBatch", "TOKEN")
            if err != nil {
                  callerAccountCheck = true
            }
            accountIds, err := t.Ctx.ERC1155Account.GenerateAccountIds(orgIds, userIds, callerAccountCheck)
            if err != nil {
                  return nil, fmt.Errorf("error in BalanceOfBatch. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        tokens = append(tokens, map[string]interface{}{"TokenId": tokenId})
                  } else {
                        tokens = append(tokens, tokenAssetValue.Interface())
                  }
            }
            return t.Ctx.ERC1155Account.BalanceOfBatch(accountIds, tokens)
      }
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. This method can be called only by the account owner.
func (t *Controller) ExchangeToken(fromTokenId string, fromOrgId string, fromUserId string, fromTokenQuantity float64, toTokenId string, toOrgId string, toUserId string, toTokenQuantity float64) (interface{}, error) {
            fromUserAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(fromOrgId, fromUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155Account.ExchangeToken", "TOKEN", map[string]string{"accountId": fromUserAccountId})
            if err != nil && !auth {
                  return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
            }
            toUserAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(toOrgId, toUserId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            return t.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 float64 – 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 float64 – 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 can call this method.
func (t *Controller) BurnBatch(orgId string, userId string, tokenIds []string, quantity []float64) (interface{}, error) {
            accountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
            if err != nil {
                  return nil, fmt.Errorf("error in BatachTransferFrom. Error: %s", err)
            }
            var tokens []interface{}
            for _, tokenId := range tokenIds {
                  tokenAssetValue, err := t.getTokenObject(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  tokens = append(tokens, tokenAssetValue.Interface())
            }
            return t.Ctx.ERC1155Token.Burn(accountId, tokens, 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 []float64 – 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 2 tokens of tokenId: FT from Account-ID oaccount~9a940587fd322ccc8400233244cd3b13f3aa2a52e418e4c71fb819a2217bc49e (Org-Id: AutoF1377358917, 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.
func (t *Controller) BurnNFT(orgId string, userId string, tokenId string) (interface{}, error) {
            tokenAsset, err := t.Ctx.ERC1155Token.Get(tokenId)
            if err != nil {
                  return nil, err
            }
            token := tokenAsset.(map[string]interface{})
            if token[constants.TokenType] != constants.NonFungible {
                  return nil, fmt.Errorf("only nonfungible tokens are allowed")
            }
            if token[constants.IsBurned] == true {
                  return nil, fmt.Errorf("token with tokenId %s is already burned", tokenId)
            }
            tokenQuantity := float64(1)
            tokenUnit := token[constants.TokenUnit]
            tokenHistory, err := t.Ctx.ERC1155Token.History(tokenId)
            if err != nil {
                  return nil, err
            }
            if tokenUnit == constants.Fractional {
                  owners, err := t.Ctx.ERC1155Token.OwnerOf(tokenId)
                  if err != nil {
                        return nil, err
                  }
                  ownersList := owners.([]map[string]interface{})
                  if len(ownersList) != 1 {
                        return nil, fmt.Errorf("NFT has multiple owners, to completely burn this NFT it should have only one owner")
                  }
                  tokenQuantity = token[constants.Quantity].(float64)
            }
            token[constants.TokenId], err = strconv.Atoi(token[constants.TokenId].(string))
            if err != nil {
                  return nil, fmt.Errorf("tokenId is expected to be integer but found %s", tokenId)
            }
            tokenHistoryBytes, err := json.Marshal(tokenHistory)
            if err != nil {
                  return nil, err
            }
            var tokenHistoryAsRawJson json.RawMessage
            err = json.Unmarshal(tokenHistoryBytes, &tokenHistoryAsRawJson)
            if err != nil {
                  return nil, err
            }
            token[constants.TokenHistory] = string(tokenHistoryAsRawJson)
            tokenIds := []string{tokenId}
            tokenQuantities := []float64{tokenQuantity}
            token[constants.IsBurned] = true
            _, err = t.BurnBatch(orgId, userId, tokenIds, tokenQuantities)
            if err != nil {
                  return nil, err
            }
            return token, nil
      }
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",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-08-22T13:14:46+05:30",
    "IsBurned": true,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 120,
    "Quantity": 1,
    "Roles": {
        "minter_role_name": "minter"
    },
    "TokenDesc": "",
    "TokenHistory": "[{\"IsDelete\":\"false\",\"Timestamp\":\"2023-08-22T13:14:46+05:30\",\"TxId\":\"c0ea212f19197c5b86323bfca11c6ca545aa0af5d40cd04f9e955b5371fd40ae\",\"Value\":{\"AssetType\":\"otoken\",\"Behaviors\":[\"indivisible\",\"singleton\",\"mintable\",\"transferable\",\"burnable\",\"roles\"],\"CreatedBy\":\"oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d\",\"CreationDate\":\"2023-08-22T13:14:46+05:30\",\"IsBurned\":false,\"Mintable\":{\"Max_mint_quantity\":20000},\"On_sale_flag\":false,\"Owner\":\"oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d\",\"Price\":120,\"Quantity\":1,\"Roles\":{\"minter_role_name\":\"minter\"},\"TokenDesc\":\"\",\"TokenId\":\"1\",\"TokenMetadata\":{\"Description\":\"\",\"Image\":\"\",\"Painter_name\":\"\",\"Painting_name\":\"\"},\"TokenName\":\"artcollection\",\"TokenStandard\":\"erc1155+\",\"TokenType\":\"nonfungible\",\"TokenUnit\":\"whole\",\"TokenUri\":\"example.com\"}}]",
    "TokenId": 1,
    "TokenMetadata": {
        "Description": "",
        "Image": "",
        "Painter_name": "",
        "Painting_name": ""
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "example.com"
}

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. Most automatically generated methods include access control. Certain token methods can be run only by the ERC721Admin or Account Owner of the token or by a MultipleAccountOwner for users with multiple accounts. The CheckAuthorization method is part of the erc721Auth class, which you access via the Ctx object. The access control mapping is described in the oChainUtil.go file, as shown in the following text. You can modify access control by editing the oChainUtil.go file.
  var t TokenAccess
      var r RoleAccess
      var a AccountAccess
      var as AccountStatusAccess
      var h HoldAccess
      var ad AdminAccess
      var trx TransactionAccess
      var tc TokenConversionAccess
      var auth AuthAccess
      var erc721ad ERC721AdminAccess
      var erc721t ERC721TokenAccess
      var erc721r ERC721RoleAccess
      var erc721a ERC721AccountAccess
      var erc721as ERC721AccountStatusAccess
      var erc721trx ERC721TransactionAccess

      var erc1155ad ERC1155AdminAccess
      var erc1155t ERC1155TokenAccess
      var erc1155a ERC1155AccountAccess
      var erc1155as ERC1155AccountStatusAccess
      var erc1155trx ERC1155TransactionAccess
      var erc1155role ERC1155RoleAccess
      trx.DeleteHistoricalTransactions = []string{"Admin"}
      ad.AddAdmin = []string{"Admin"}
      ad.RemoveAdmin = []string{"Admin"}
      ad.GetAllAdmins = []string{"Admin", "OrgAdmin"}
      ad.AddOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"}
      ad.RemoveOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"}
      ad.GetOrgAdmins = []string{"Admin", "OrgAdmin"}
      ad.IsTokenAdmin = []string{"Admin", "MultipleAccountOwner", "OrgAdmin"}
      t.Save = []string{"Admin"}
      t.GetAllTokens = []string{"Admin", "OrgAdmin"}
      t.Update = []string{"Admin"}
      t.GetTokenDecimals = []string{"Admin", "OrgAdmin"}
      t.GetTokensByName = []string{"Admin", "OrgAdmin"}
      t.AddRoleMember = []string{"Admin", "OrgAdminRoleCheck"}
      t.RemoveRoleMember = []string{"Admin", "OrgAdminRoleCheck"}
      t.IsInRole = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      t.GetTotalMintedTokens = []string{"Admin", "OrgAdmin"}
      t.GetNetTokens = []string{"Admin", "OrgAdmin"}
      t.Get = []string{"Admin", "OrgAdmin"}
      t.GetTokenHistory = []string{"Admin", "OrgAdmin"}
      a.CreateAccount = []string{"Admin", "OrgAdminOrgIdCheck"}
      a.AssociateToken = []string{"Admin", "OrgAdminAccountIdCheck"}
      a.GetAllAccounts = []string{"Admin"}
      a.GetAllOrgAccounts = []string{"Admin", "OrgAdminOrgIdCheck"}
      a.GetAccount = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.History = []string{"Admin", "AccountOwner"}
      a.GetAccountTransactionHistory = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetSubTransactionsById = []string{"Admin", "TransactionInvoker"}
      a.GetSubTransactionsByIdWithFilters = []string{"Admin", "TransactionInvoker"}
      a.GetAccountBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetAccountOnHoldBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetOnHoldIds = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetAccountsByUser = []string{"Admin", "OrgAdminOrgIdCheck", "MultipleAccountOwner"}

      as.Get = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      as.ActivateAccount = []string{"Admin", "OrgAdminOrgIdCheck"}
      as.SuspendAccount = []string{"Admin", "OrgAdminOrgIdCheck"}
      as.DeleteAccount = []string{"Admin", "OrgAdminOrgIdCheck"}

      r.GetAccountsByRole = []string{"Admin"}
      r.GetUsersByRole = []string{"Admin"}
      r.GetOrgAccountsByRole = []string{"Admin", "OrgAdminOrgIdCheck"}
      r.GetOrgUsersByRole = []string{"Admin", "OrgAdminOrgIdCheck"}
      tc.InitializeExchangePoolUser = []string{"Admin"}
      tc.AddConversionRate = []string{"Admin"}
      tc.UpdateConversionRate = []string{"Admin"}
      tc.GetConversionRate = []string{"Admin", "OrgAdmin", "AnyAccountOwner"}
      tc.GetConversionRateHistory = []string{"Admin", "OrgAdmin", "AnyAccountOwner"}
      tc.TokenConversion = []string{"Admin", "AnyAccountOwner"}
      tc.GetExchangePoolUser = []string{"Admin"}

      erc721ad.AddAdmin = []string{"Admin"}
      erc721ad.GetAllAdmins = []string{"Admin"}
      erc721ad.IsTokenAdmin = []string{"Admin"}
      erc721ad.RemoveAdmin = []string{"Admin"}
      erc721trx.DeleteHistoricalTransactions = []string{"Admin"}
      erc721t.Save = []string{"Admin"}
      erc721t.GetAllTokens = []string{"Admin"}
      erc721t.Update = []string{"Admin"}
      erc721t.GetTokensByName = []string{"Admin"}
      erc721t.AddRoleMember = []string{"Admin"}
      erc721t.RemoveRoleMember = []string{"Admin"}
      erc721t.IsInRole = []string{"Admin", "AccountOwner"}
      erc721t.Get = []string{"Admin", "TokenOwner"}
      erc721t.GetAllTokensByUser = []string{"Admin", "AccountOwner"}
      erc721t.TotalSupply = []string{"Admin"}
      erc721t.TotalNetSupply = []string{"Admin"}
      erc721t.History = []string{"Admin"}
      erc721a.CreateAccount = []string{"Admin"}
      erc721a.CreateUserAccount = []string{"Admin"}
      erc721a.CreateTokenAccount = []string{"Admin"}
      erc721a.AssociateFungibleTokenToAccount = []string{"Admin", "AccountOwner"}
      erc721a.GetAllAccounts = []string{"Admin"}
      erc721a.History = []string{"Admin", "AccountOwner"}
      erc721a.GetAccountTransactionHistory = []string{"Admin", "AccountOwner"}
      erc721a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "AccountOwner"}
      erc721a.GetAccountByUser = []string{"Admin", "MultipleAccountOwner"}
      erc721a.BalanceOf = []string{"Admin", "MultipleAccountOwner"}

      erc721as.Get = []string{"Admin", "AccountOwner"}
      erc721as.ActivateAccount = []string{"Admin"}
      erc721as.SuspendAccount = []string{"Admin"}
      erc721as.DeleteAccount = []string{"Admin"}

      erc721r.GetAccountsByRole = []string{"Admin"}
      erc721r.GetUsersByRole = []string{"Admin"}

      erc1155ad.AddAdmin = []string{"Admin"}
      erc1155ad.GetAllAdmins = []string{"Admin"}
      erc1155ad.IsUserTokenAdmin = []string{"Admin"}
      erc1155ad.RemoveAdmin = []string{"Admin"}
      erc1155t.AddRoleMember = []string{"Admin"}
      erc1155t.IsInRole = []string{"Admin"}
      erc1155t.GetAllTokens = []string{"Admin"}
      erc1155t.GetAllTokensByUser = []string{"Admin", "AccountOwner"}
      erc1155t.Get = []string{"Admin", "TokenOwner"}
      erc1155t.RemoveRoleMember = []string{"Admin"}
      erc1155t.TotalNetSupply = []string{"Admin"}
      erc1155t.TotalSupply = []string{"Admin"}
      erc1155t.GetTokenDecimal = []string{"Admin"}
      erc1155t.GetTokensByName = []string{"Admin"}
      erc1155t.GetTotalMintedTokens = []string{"Admin"}
      erc1155t.GetNetTokens = []string{"Admin"}
      erc1155t.Save = []string{"Admin"}
      erc1155t.Update = []string{"Admin"}

      erc1155trx.DeleteHistoricalTransactions = []string{"Admin"}

      erc1155role.GetAccountsByRole = []string{"Admin"}
      erc1155role.GetUsersByRole = []string{"Admin"}
      erc1155a.AssociateFungibleTokenToAccount = []string{"Admin", "AccountOwner"}
      erc1155a.BalanceOfBatch = []string{"Admin"}
      erc1155a.CreateAccount = []string{"Admin"}
      erc1155a.CreateTokenAccount = []string{"Admin"}
      erc1155a.CreateUserAccount = []string{"Admin"}
      erc1155a.GetAccountTransactionHistory = []string{"Admin", "AccountOwner"}
      erc1155a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "AccountOwner"}
      erc1155a.GetAccountsByUser = []string{"Admin", "AccountOwner"}
      erc1155a.GetAccount = []string{"Admin", "AccountOwner"}
      erc1155a.History = []string{"Admin", "AccountOwner"}
      erc1155a.GetAllAccounts = []string{"Admin"}
      erc1155a.ExchangeToken = []string{"AccountOwner"}
      erc1155a.GetAccountDetailsByUser = []string{"Admin", "AccountOwner"}

      erc1155as.Get = []string{"Admin", "AccountOwner"}
      erc1155as.ActivateAccount = []string{"Admin"}
      erc1155as.SuspendAccount = []string{"Admin"}
      erc1155as.DeleteAccount = []string{"Admin"}
      var accessMap TokenAccessControl
      accessMap.Token = t
      accessMap.Account = a
      accessMap.AccountStatus = as
      accessMap.Hold = h
      accessMap.Role = r
      accessMap.Admin = ad
      accessMap.Auth = auth
      accessMap.TokenConversion = tc
      accessMap.ERC721ADMIN = erc721ad
      accessMap.ERC721TOKEN = erc721t
      accessMap.ERC721ACCOUNT = erc721a
      accessMap.ERC721AccountStatus = erc721as
      accessMap.ERC721ROLE = erc721r
      accessMap.ERC721TRANSACTION = erc721trx
      accessMap.ERC1155Account = erc1155a
      accessMap.ERC1155AccountStatus = erc1155as
      accessMap.ERC1155Admin = erc1155ad
      accessMap.ERC1155Token = erc1155t
      accessMap.ERC1155Transaction = erc1155trx
      accessMap.ERC1155Role = erc1155role
Ctx.ERC1155Auth.CheckAuthorization(funcName string, args []string) (bool, error)
Parameters:
  • funcName string – The map value between the receivers and methods as described in the oChainUtil.go file.
  • args – A variable argument where args[0] takes the constant 'TOKEN' and args[1] takes the accountId parameter to add an access control check for an AccountOwner. To add an access control check for a MultipleAccountOwner, args[1] takes the orgId parameter and args[2] takes the userId parameter. To add an access control check for a TokenOwner, args[1] takes the token ID parameter.
Returns:
  • A bool response of error as required.
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) (interface{}, error)
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) (interface{}, error)
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) (interface{}, error)
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)"
}
GetAllAdminUsers
This method returns a list of all Token Admin users.
Ctx.ERC1155Admin.GetAllAdminUsers() (interface{}, error)
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(token interface{}, quantity ...float64) (interface{}, error)
Parameters:
  • tokenAsset: interface{} – 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.
  • Behavior or Behaviors – A list of token behaviors. This property cannot be edited.
  • 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.
  • 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.
  • Symbol – The symbol of the token. This property cannot be edited.
  • TokenDesc – The description of the token.
  • TokenMetadata – JSON information that describes the token.
  • TokenName – The name 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.
  • TokenUri – The URI of the token.
  • Quantity – The quantity of the token.
Return Value Example (Whole NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-12-29T09:57:03+05:30",
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 500
    },
    "OnSaleFlag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 100,
    "Quantity": 1,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "token description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
Return Value Example (Fungible Token):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Currency_name": "Dollar",
    "Divisible": {
        "Decimal": 2
    },
    "Mintable": {
        "Max_mint_quantity": 10000
    },
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "Loyalty",
    "TokenName": "loyalty",
    "TokenStandard": "erc1155+",
    "TokenType": "fungible",
    "TokenUnit": "fractional",
    "Token_to_currency_ratio": 0
}
Return Value Example (Fractional NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-06-14T09:53:53+05:30",
    "Divisible": {
        "Decimal": 2
    },
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Price": 1000,
    "Quantity": 100,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "realEstate",
    "TokenMetadata": {
        "Description": "Painting Description",
        "Image": "",
        "Painter_name": "",
        "Painting_name": "Paint"
    },
    "TokenName": "realestate",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "fractional",
    "TokenUri": "www.realestate.example.com"
}
Update
This method updates tokens. You cannot update token metadata or the token URI of non-fungible tokens.
Ctx.ERC1155Token.Update(tokenAsset interface{}) (interface{}, error)
Parameters:
  • tokenAsset: interface{} – 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):
{
    "AssetType": "otoken",
    "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-12-29T09:57:03+05:30",
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 500
    },
    "OnSaleFlag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 100,
    "Quantity": 1,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "token description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
History (Token)
This method returns the history for a specified token ID.
Ctx.ERC1155Token.History(tokenId string) (interface{}, error)
Parameters:
  • tokenId string – The ID of the token.
Returns:
  • On success, a JSON array that contains the token history.
Return Value Example (Fungible Token):
[
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-08T09:54:11Z",
    "TxId": "823sa7c7a00941c62285c86f922bc4d3f5326a20f4bf2f82daa5bc661e4682e8",
    "Value": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "Rupees",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "Updated Token Description",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-08T09:54:11Z",
    "TxId": "711bb7c7a00941c62285c86f922bc3b3f5326a20f4bf2f82daa5bc661e4682e8",
    "Value": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "Dollar",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  }
]
Return Value Example (Fractional NFT):
[
    {
        "Timestamp": "2023-06-20T01:06:33Z",
        "TrxId": "16e53db4f8107f9634b7c3a0a2a81a00f69b634f2a52902b809e544d07f272b1",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:02:27Z",
            "Divisible": {
                "Decimal": 2
            },
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owners": [
                {
                    "AccountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "TokenShare": 10
                },
                {
                    "AccountId": "oaccount~3cddfdaa855900579d963aa6f755a4aed1f3a474a2462c1b45bd7f36df673224",
                    "TokenShare": 10
                }
            ],
            "Price": 2000,
            "Quantity": 20,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "FNFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "realestate",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "fractional",
            "TokenUri": "www.FNFT.example.com"
        }
    },
    {
        "Timestamp": "2023-06-20T01:02:27Z",
        "TrxId": "cec80910d087682554048f911d2cf98b66382bbcf1615483fa1c96c7ea08077c",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:02:27Z",
            "Divisible": {
                "Decimal": 2
            },
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owners": [
                {
                    "AccountId": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
                    "TokenShare": 20
                }
            ],
            "Price": 2000,
            "Quantity": 20,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "FNFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "realestate",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "fractional",
            "TokenUri": "www.FNFT.example.com"
        }
    }
]
Return Value Example (Whole NFT):
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-20T01:15:56Z",
        "TxId": "89a3df3ebbe6dca2bcfbd51fc7dca9aab818a2af746b79a92dc8155b729ab22d",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:15:56Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owner": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "Price": 2000,
            "Quantity": 1,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "Updated Token Description",
            "TokenId": "NFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "artcollection",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "www.NFT.example.com"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-20T01:15:56Z",
        "TxId": "90d6af3ebbe6dca2bcfbd51fc7dca9aab818a2af746b79a92dc8155b729ab22d",
        "Value": {
            "AssetType": "otoken",
            "Behaviors": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "roles"
            ],
            "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "CreationDate": "2023-06-20T01:15:56Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "On_sale_flag": true,
            "Owner": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
            "Price": 2000,
            "Quantity": 1,
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "TokenDesc": "",
            "TokenId": "NFT",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "Painter_name": "",
                "Painting_name": ""
            },
            "TokenName": "artcollection",
            "TokenStandard": "erc1155+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "www.NFT.example.com"
        }
    }
]
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()() (interface{}, error)
Parameters:
  • none
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenTwo",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "art",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "BurnedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "BurnedDate": "2022-12-08T10:49:37Z",
      "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "CreationDate": "2022-12-08T10:45:10Z",
      "IsBurned": true,
      "Mintable": {
        "Max_mint_quantity": 20000
      },
      "OnSaleFlag": false,
      "Owner": "",
      "Price": 0,
      "Roles": {
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "art",
      "TokenMetadata": {
        "Description": "",
        "Image": "",
        "PainterName": "",
        "PaintingName": ""
      },
      "TokenName": "artcollection",
      "TokenStandard": "erc1155+",
      "TokenType": "nonfungible",
      "TokenUnit": "whole",
      "TokenUri": "art.example.com",
      "TransferredBy": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc",
      "TransferredDate": "2022-12-08T10:47:04Z"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "AssetType": "otoken",
        "Behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "CreationDate": "2023-06-20T01:02:27Z",
        "Divisible": {
            "Decimal": 2
        },
        "IsBurned": false,
        "Mintable": {
            "Max_mint_quantity": 20000
        },
        "On_sale_flag": true,
        "Price": 2000,
        "Quantity": 20,
        "Roles": {
            "burner_role_name": "burner",
            "minter_role_name": "minter"
        },
        "TokenDesc": "",
        "TokenId": "FNFT",
        "TokenMetadata": {
            "Description": "",
            "Image": "",
            "Painter_name": "",
            "Painting_name": ""
        },
        "TokenName": "realestate",
        "TokenStandard": "erc1155+",
        "TokenType": "nonfungible",
        "TokenUnit": "fractional",
        "TokenUri": "www.FNFT.example.com"
    }
  },
  {
    "key": "FNFT",
    "valueJson": {
        "AssetType": "otoken",
        "Behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "roles"
        ],
        "CreatedBy": "oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a",
        "CreationDate": "2023-06-20T01:02:27Z",
        "Divisible": {
            "Decimal": 2
        },
        "IsBurned": false,
        "Mintable": {
            "Max_mint_quantity": 20000
        },
        "On_sale_flag": true,
        "Price": 2000,
        "Quantity": 20,
        "Roles": {
            "burner_role_name": "burner",
            "minter_role_name": "minter"
        },
        "TokenDesc": "",
        "TokenId": "FNFT",
        "TokenMetadata": {
            "Description": "",
            "Image": "",
            "Painter_name": "",
            "Painting_name": ""
        },
        "TokenName": "realestate",
        "TokenStandard": "erc1155+",
        "TokenType": "nonfungible",
        "TokenUnit": "fractional",
        "TokenUri": "www.FNFT.example.com"
    }
  }
]
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. For fractional NFTs, the list of owners is also returned.
Ctx.ERC1155Token.Get(id string, result ...interface{}) (interface{}, error)
Parameters:
  • id string – The ID of the token to get.
Return Value Example (Whole NFT):
{
  "AssetType": "otoken",
  "Behaviors": [
    "indivisible",
    "singleton",
    "mintable",
    "transferable",
    "burnable",
    "roles"
  ],
  "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "CreationDate": "2022-12-08T10:55:29Z",
  "IsBurned": false,
  "Mintable": {
    "Max_mint_quantity": 20000
  },
  "OnSaleFlag": false,
  "Owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
  "Price": 0,
  "Quantity": 1,
  "Roles": {
    "minter_role_name": "minter"
  },
  "TokenDesc": "",
  "TokenId": "nftToken",
  "TokenMetadata": {
    "Description": "",
    "Image": "",
    "PainterName": "",
    "PaintingName": ""
  },
  "TokenName": "artcollection",
  "TokenStandard": "erc1155+",
  "TokenType": "nonfungible",
  "TokenUnit": "whole",
  "TokenUri": "example.com"
}
Return Value Example (Fungible Token):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Currency_name": "Dollar",
    "Divisible": {
        "Decimal": 2
    },
    "Mintable": {
        "Max_mint_quantity": 10000
    },
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "Loyalty",
    "TokenName": "loyalty",
    "TokenStandard": "erc1155+",
    "TokenType": "fungible",
    "TokenUnit": "fractional",
    "Token_to_currency_ratio": 0
}
Return Value Example (Fractional NFT):
{
    "AssetType": "otoken",
    "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-06-14T09:53:53+05:30",
    "Divisible": {
        "Decimal": 2
    },
    "IsBurned": false,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Owners": [
        {
            "AccountId": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "TokenShare": 100
        }
    ],
    "Price": 1000,
    "Quantity": 100,
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "TokenDesc": "Token Description",
    "TokenId": "realEstate",
    "TokenMetadata": {
        "Description": "Painting Description",
        "Image": "",
        "Painter_name": "",
        "Painting_name": "Paint"
    },
    "TokenName": "realestate",
    "TokenStandard": "erc1155+",
    "TokenType": "nonfungible",
    "TokenUnit": "fractional",
    "TokenUri": "www.realestate.example.com"
}
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) (interface{}, error)
Parameters:
  • accountId string – The account ID of the user.
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "nftToken",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
      ],
      "CreatedBy": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "CreationDate": "2022-12-08T10:55:29Z",
      "IsBurned": false,
      "Mintable": {
        "Max_mint_quantity": 20000
      },
      "OnSaleFlag": false,
      "Owner": "oaccount~76cb672eeb1bd535899562a840d0c15a356db89e24bc8b43ac1dba845a4282c6",
      "Price": 0,
      "Quantity": 1,
      "Roles": {
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "nftToken",
      "TokenMetadata": {
        "Description": "",
        "Image": "",
        "PainterName": "",
        "PaintingName": ""
      },
      "TokenName": "artcollection",
      "TokenStandard": "erc1155+",
      "TokenType": "nonfungible",
      "TokenUnit": "whole",
      "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) (interface{}, error)
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) (interface{}, error)
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) (interface{}, error)
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(tokenAsset interface{}) (map[string]interface{}, error)
Parameters:
  • tokenAsset interface{} – The token asset.
Return Value Example:
{"TotalSupply": 100}
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 interface{}) (interface{}, error)
Parameters:
  • token interface{} – The token asset.
Return Value Example:
{"TotalNetSupply": 100}
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) (interface{}, error)
Parameters:
  • tokenName: string – The name of the token.
Return Value Example:
[
  {
    "key": "tokenOne",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenOne",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  },
  {
    "key": "tokenTwo",
    "valueJson": {
      "AssetType": "otoken",
      "Behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "roles"
      ],
      "Currency_name": "",
      "Divisible": {
        "Decimal": 2
      },
      "Mintable": {
        "Max_mint_quantity": 1000
      },
      "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
      },
      "TokenDesc": "",
      "TokenId": "tokenTwo",
      "TokenName": "moneytok",
      "TokenStandard": "erc1155+",
      "TokenType": "fungible",
      "TokenUnit": "fractional",
      "Token_to_currency_ratio": 0
    }
  }
]
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(tokenId string) (int, error)
Parameters:
  • tokenId: string – The ID of the token.
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 bool, nftAccount bool) (ERC1155UserAccount, error)
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 bool – If true, a fungible token account is created and associated with the user account.
  • nftAccount bool – 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.

Ctx.ERC1155Account.CreateUserAccount(orgId string, userId string) (interface{}, error)
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) (ERC1155UserAccount, error)
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 erc1155Token.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) (interface{}, error)
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 token account ID.
Returns:
  • On success, an array of JSON objects that describes the account history.
Return Value Example:
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-06T11:03:48Z",
        "TxId": "c5180f3be3d9130f25a4b4e866f38a4283117dcbfbffb4f55e2c5b03dba0dd29",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 100,
            "BapAccountVersion": 1
            "OrgId": "appdev",
            "TokenId": "loy1",
            "TokenName": "loyalty",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-06T11:02:39Z",
        "TxId": "6f81b0c94b451d375a3892446aefbdf78d9fd1ac43699daa89f0dff10db5fd22",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 0,
            "BapAccountVersion": 0
            "OrgId": "appdev",
            "TokenId": "loy1",
            "TokenName": "loyalty",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-06-05T16:28:46Z",
        "TxId": "8185af648546e909488e72149be497b210f74f95ada252c42da9c35cb9d98691",
        "Value": {
            "AccountCategory": "",
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "AssetType": "oaccount",
            "Balance": 0,
            "BapAccountVersion": 0
            "OrgId": "appdev",
            "TokenId": "",
            "TokenName": "",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    }
]
GetAccountWithStatus
This method returns token account details for a specified user, including account status. This method can be called only by a Token Admin of the chaincode or the Account Owner of the account.
Ctx.ERC1155Account.GetAccountWithStatus(userAccountId string, tokenId ...string) (interface{}, error)
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 account status.
Return Value Example (Non-Fungible Token Account):
{
    "AccountId": "oaccount~cc301bee057f14236a97d434909ec1084970921b008f6baab09c2a0f5f419a9a",
    "AssetType": "oaccount",
    "BapAccountVersion": 1,
    "NoOfNfts": 1,
    "OrgId": "appdev",
    "Status": "active",
    "TokenType": "nonfungible",
    "UserId": "idcqa"
}
Return Value Example (Fungible Token Account):
{
    "AccountCategory": "",
    "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
    "AssetType": "oaccount",
    "Balance": 0,
    "BapAccountVersion": 0,
    "OrgId": "appdev",
    "Status": "active",
    "TokenId": "t1",
    "TokenName": "loyalty",
    "TokenType": "fungible",
    "UserId": "idcqa"
}
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.Get(accountId string, tokenId ...string) (interface{}, error) 
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.
Return Value Example (Non-Fungible Token Account):
{
    "AccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
    "BapAccountVersion": 0,
    "AssetType": "oaccount",
    "NoOfNfts": 4,
    "OrgId": "appdev",
    "TokenType": "nonfungible",
    "UserId": "idcqa"
}
Return Value Example (Fungible Token Account):
{
    "AssetType": "oaccount",
    "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
    "UserId": "idcqa",
    "OrgId": "appdev",
    "BapAccountVersion": 0,
    "TokenType": "fungible",
    "TokenId": "loy1",
    "TokenName": "loyalty",
    "Balance": 90,
    "AccountCategory": ""
}
GetAllAccounts
This method returns details of all user accounts.
Ctx.ERC1155Account.GetAllAccounts() (interface{}, error)
Parameters:
  • none
Return Value Example:
[
    {
        "AssetType": "ouaccount",
        "AccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38",
        "UserId": "idcqa",
        "OrgId": "appdev",
        "TotalAccounts": 3,
        "TotalFtAccounts": 2,
        "AssociatedFtAccounts": [
            {
                "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
                "TokenId": "loy1"
            },
            {
                "AccountId": "oaccount~58c5a6b09a41befca2a9ea2550439838c4dcf4d8a2a4f7c98e9319cf8479bfc4",
                "TokenId": ""
            }
        ],
        "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) (interface{}, error)
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:
{
    "AssociatedFTAccounts": [
        {
            "AccountId": "oaccount~21206f309941a2a23c4f158a0fe1b8f12bb8e2b0c9a2e1358f5efebc0c7d410e",
            "Balance": 90,
            "TokenId": "FT"
        },
    ],
    "AssociatedNFTAccount": {
        "AccountId": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "AssociatedNFTs": [
            {
                "NFTTokenId": "FNFT",
                "TokenShare": 230
            },
            {
                "NFTTokenId": "NFT"
            },
            {
                "NFTTokenId": "NFT2"
            }
        ]
    },
    "UserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
}
GetUserByAccountId
This method returns the user details of a specified account ID.
Ctx.ERC1155Account.GetUserByAccountById(accountId string) (map[string]interface{}, error)
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(userRole string, userAccountId string, asset interface{}) (interface{}, error)
Parameters:
  • userRole: string – The name of the role to add to the specified user.
  • userAccountId: string – The account ID of the user.
  • asset: interface{} – The token asset.
Returns:
  • On success, a message with account details.
Return Value Example:
{
    "msg": "Successfully added role minter to oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a (orgId : appdev, userId : 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(userRole string, userAccountId string, asset interface{}) (bool, error)
Parameters:
  • userRole: string – The name of the role to search for.
  • userAccountId: string – The account ID of the user.
  • asset: interface{} – The token asset.
Return Value Example:
{
    "result": true
}
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(userRole string, userAccountId string, asset interface{}) (interface{}, error) 
Parameters:
  • userRole: string – The name of the role to remove.
  • userAccountId: string – The account ID of the user.
  • asset: interface{} – The token asset.
Return Value Example:
{
    "msg": "Successfully removed role 'minter' from Account Id: oaccount~ec7e4de2f81e3ea071710e07b6ff7d9346e84ef665ca4650885dbe8c3e2bd4c0 (Org-Id: appdev, User-Id: idcqa)"
}
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.ERC1155Role.GetAccountsByRole(roleName string, token interface{}) (interface{}, error)
Parameters:
  • roleName: string – The name of the role to search for.
  • token: interface{} – 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.ERC1155Role.GetUsersByRole(roleName string, token interface{}) (interface{}, error)
Parameters:
  • roleName: string – The name of the role to search for.
  • token: interface{} – 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(tokenAccountId string) (interface{}, error)
Parameters:
  • accountId string – The user account ID.
Return Value Example:
[
    {
        "Balance": 90,
        "Timestamp": "2023-06-06T11:11:09Z",
        "TokenId": "FNFT",
        "TransactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TransactedAmount": 10,
        "TransactionId": "otransaction~0f4d96fbf8fed88ea8a3133428977721091467c701848d595ebc3fffa88b3657~7c88c736df38d5622512f1e8dcdd50710eb47c953f1ecb24ac44790a9e2f475b",
        "TransactionType": "DEBIT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Timestamp": "2023-06-06T11:11:09Z",
        "TokenId": "NFT",
        "TransactedAccount": "oaccount~dcee860665db8740cb77b846e823752185a1e9a185814d0acb305890f5903446",
        "TransactionId": "otransaction~0f4d96fbf8fed88ea8a3133428977721091467c701848d595ebc3fffa88b3657~178e3730bc5bee50d02f1464a4eebf733a051905f651e5789039adb4a3edc114",
        "TransactionType": "DEBIT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Timestamp": "2023-06-06T11:06:54Z",
        "TokenId": "NFT",
        "TransactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TransactionId": "otransaction~6a13667ea3f6edc4c854e85b127526eccb58783f653c348b42a3869f0f29a4fb~a7cefb22ff39ee7e36967be71de27da6798548c872061a62dabc56d88d50b930",
        "TransactionType": "MINT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    },
    {
        "Balance": 100,
        "Timestamp": "2023-06-05T16:34:33Z",
        "TokenId": "FNFT",
        "TransactedAccount": "oaccount~e88276a3be547e31b567346bdddde52d37734da4d5fae83ab2e5c98a10097371",
        "TransactedAmount": 100,
        "TransactionId": "otransaction~2bc15de1766d582d821bd8d61756bca02837dc683c0aa61f69657ccd1d95e335~e4eb15d9354f694230df8835ade012100d82aa43672896a2c7125a86e3048f9f",
        "TransactionType": "MINT",
        "TriggeredByUserAccountId": "ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38"
    }
]
GetTransactionById
This method returns the transaction details for a specified transaction ID.
Ctx.ERC1155Transaction.GetTransactionById(trxId string) (interface{}, error)
Parameters:
  • trxId string – The ID of the transaction.
Return Value Example:
{
    "history": [
        {
            "IsDelete": "false",
            "Timestamp": "2022-12-08T10:45:56Z",
            "TxId": "2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98",
            "Value": {
                "Amount": 5,
                "AssetType": "otransaction",
                "FromAccountId": "oaccount~60bb20c14a83f6e426e1437c479c5891e1c6477dfd7ad18b73acac5d80bc504b",
                "Timestamp": "2022-12-08T10:45:56Z",
                "ToAccountId": "oaccount~1422a74d262a3a55a37cd9023ef8836f765d0be7b49d397696b9961d7434d22a",
                "TokenId": "tokenOne",
                "TransactionId": "otransaction~2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98~9c3ce5f21abd98ca018c196086d73a812f2f49dba323f1de4f6867eecfeec8ff",
                "TransactionType": "TRANSFER",
                "TriggeredByUserAccountId": "ouaccount~24ffd4d32a028a85b4b960f5d55536c837b5429bc7f346150adfa904ec2937cc"
            }
        }
    ],
    "transactionId": "otransaction~2da02a53aa1032602df6c68c5628a4ab8b22ba107c0201520ce495948901aa98~9c3ce5f21abd98ca018c196086d73a812f2f49dba323f1de4f6867eecfeec8ff"
}
DeleteHistoricalTransactions
This method deletes transactions before a specified time stamp from the state database.
Ctx.ERC1155Transaction.DeleteHistoricalTransactions(referenceTime string) (interface{}, error)
Parameters:
  • referenceTime string – All transactions before this time stamp will be deleted.
Return Value Example:
{
    "Transactions": [
        "otransaction~750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7"
    ],
    "msg": "Successfuly deleted transaction older than date:2022-04-06T08:17:53Z"
}

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, tokens []interface{}, quantities []float64) (interface{}, error)
Parameters:
  • accountId string – The account ID of the user.
  • tokenIds []string – The list of token IDs to mint tokens for.
  • quantity []float64 – 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:
{
    "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'"
        }
    ],
    "msg": "Successfully minted batch of tokens for User-Account-Id 'ouaccount~412de5e3998dcd100973e1bad6e8729fddc1c7ff610beab8376d733a35c51f38' (Org-Id: 'appdev', User-Id: 'idcqa')"
}

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(fromAccountId string, toAccountId string, tokens []interface{}, quantities []float64) (interface{}, error) 
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 float64[] – 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(fromAccountId string, toAccountId string, tokens []interface{}, quantities []float64) (interface{}, error)
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 float64[] – 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, tokens []interface{}) (interface{}, error)
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 float64, toTokenId string, toUserAccountId string, toTokenQuantity float64) (interface{}, error) 
Parameters:
  • fromTokenId string – The ID of the token that the sender owns.
  • fromUserAccountId string – The account ID of the sender.
  • fromTokenQuantity float64 – 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 float64 – 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, tokens []interface{}, quantities []float64) (interface{}, error)
Parameters:
  • accountId string – The account ID of the user.
  • tokenIds []string – The list of token IDs to burn.
  • quantity []float64 – 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 2 tokens of tokenId: FT from Account-ID oaccount~9a940587fd322ccc8400233244cd3b13f3aa2a52e418e4c71fb819a2217bc49e (Org-Id: AutoF1377358917, User-Id: idcqa)"
    },
    {
        "msg": "Successfully burned 2 token share of tokenId: FNFT from Account-ID oaccount~87bcb699d507368ee3966cd03ee6d7736ffc55dde8c0f0e16b14866334ac504a (Org-Id: AutoF1377358917, User-Id: idcqa)"
    }
]