Scaffolded Go NFT Project for ERC-721

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

The project automatically generates NFT 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 NFTs, see Scaffolded Go Chaincode Project.

Model

Transparent Persistence Capability, or simplified ORM, is captured in the OchainModel class.

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"`
	Symbol        string `json:"Symbol" final:"ART"`
	TokenStandard string `json:"TokenStandard" final:"erc721+"`
	TokenType     string `json:"TokenType" final:"nonfungible" validate:"regexp=^nonfungible$"`
	TokenUnit     string `json:"TokenUnit" final:"whole" validate:"regexp=^whole$"`

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

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

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

	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" 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"`
}

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 NFT Methods

Blockchain App Builder automatically generates methods to support NFTs and NFT life cycles. You can use these methods to initialize NFTs, manage roles and accounts, and complete other NFT lifecycle tasks without any additional coding.

Blockchain App Builder automatically generates methods to support NFTs and NFT life cycles. You can use these methods to initialize NFTs, manage roles and accounts, and complete other NFT 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

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.ERC721Auth.CheckAuthorization("ERC721ADMIN.AddAdmin", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Admin.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: Org1MSP, 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 use this method to remove yourself as a Token Admin.
func (t *Controller) RemoveTokenAdmin(orgId string, userId string) (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ADMIN.RemoveAdmin", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Admin.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 Org1MSP UserId user1)"}
IsTokenAdmin
This method returns the Boolean value true if the caller of the function is a Token Admin, otherwise it returns false. A Token Admin can call this function on any other user in the blockchain network. Other users can call this method only on their own accounts.
func (t *Controller) IsTokenAdmin(orgId string, userId string) (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ADMIN.IsTokenAdmin", "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.ERC721Auth.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}
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.ERC721Auth.CheckAuthorization("ERC721ADMIN.GetAllAdmins", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Admin.GetAllAdminUsers()
}
Parameters:
  • none
Returns:
  • On success, a JSON list of admins that includes OrgId and UserId objects.
Return Value Example:
{
    "admins": [
        {
            "OrgId":"Org1MSP",
            "UserId":"admin"
        }
    ]
}

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 ([]). Any other information in the adminList parameter is ignored during upgrades.
func (t *Controller) Init(adminList []erc721Admin.ERC721TokenAdminAsset) (interface{}, error) {
      list, err := t.Ctx.ERC721Admin.InitAdmin(adminList)
      if err != nil {
            return nil, fmt.Errorf("initialising admin list failed %s", err.Error())
      }
      <Token Name> := <Token Class>{}
      _, err = t.Ctx.ERC721Token.SaveClassInfo(&<Token Name>)
      if err != nil {
            return nil, err
      }
      _, err = t.Ctx.ERC721Token.SaveDeleteTransactionInfo()
      if err != nil {
            fmt.Println("error: ", err)
      }
      return list, nil
}
Parameters:
  • adminList array – An array of {OrgId, UserId} information that specifies the list of token admins. The adminList array is a mandatory parameter.
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.ERC721Auth.CheckAuthorization("ERC721TOKEN.GetAllTokens", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Token.GetAllTokens()
}
Parameters:
  • none
Returns:
  • A list of all token assets in JSON format.
Return Value Example:
[
    {
        "key": "monalisa",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "CreationDate": "2022-04-10T11:01:42Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 0,
            "Owner": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "token Description",
            "TokenId": "monalisa",
            "TokenMetadata": {
                 "Description": "Mona Lisa Painting",
                 "Image": "monalisa.jpeg",
                 "PainterName": "Leonardo_da_Vinci",
                 "PaintingName": "Mona_Lisa"
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
        }
    },
    {
        "key": "monalisa2",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "CreationDate": "2022-04-10T11:04:44Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 100,
            "Owner": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "",
            "TokenId": "monalisa1",
            "TokenMetadata": {
                 "Description": "Mona Lisa Painting",
                 "Image": "monalisa.jpeg",
                 "PainterName": "Leonardo_da_Vinci",
                 "PaintingName": "Mona_Lisa"
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
        }
        }
    }
]
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.ERC721Account.GenerateAccountId(orgId, userId)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.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.ERC721Token.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.
Returns:
  • A list of token assets in JSON format.
Return Value Example:
[
    {
        "key": "monalisa",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "CreationDate": "2022-04-10T11:01:42Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 0,
            "Owner": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "token Description",
            "TokenId": "monalisa",
            "TokenMetadata": {
                 "Description": "Mona Lisa Painting",
                 "Image": "monalisa.jpeg",
                 "PainterName": "Leonardo_da_Vinci",
                 "PaintingName": "Mona_Lisa"
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
        }
    },
    {
        "key": "monalisa2",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "CreationDate": "2022-04-10T11:04:44Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 100,
            "Owner": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "",
            "TokenId": "monalisa1",
            "TokenMetadata": {
                 "Description": "Mona Lisa Painting",
                 "Image": "monalisa.jpeg",
                 "PainterName": "Leonardo_da_Vinci",
                 "PaintingName": "Mona_Lisa"
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
        }
        }
    }
]
GetTokenById
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.
func (t *Controller) GetTokenById(tokenId string) (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.Get", "TOKEN", map[string]string{"tokenId": tokenId})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      tokenAsset, err := t.getTokenObject(tokenId)
      if err != nil {
            return nil, err
      }
      return tokenAsset.Interface(), nil
}
Parameters:
  • tokenId: string – The ID of the token to get.
Returns:
  • The token asset in JSON format.
Return Value Example:
{
    "AssetType": "otoken",
    "Behavior": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-04-06T00:35:42Z",
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "NftBasePrice": 200,
    "Owner": "oaccount~ec32cff8635a056f3dda3da70b1d6090d61f66c6a170c4a95fd008181f729dba",
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "Symbol": "PNT",
    "TokenDesc": "Token Description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "paintingnft",
    "TokenStandard": "erc721+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
    "TransferredBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "TransferredDate": "2022-04-06T00:51:56Z"
}
GetTokenHistory
This method returns the history for a specified token ID. This method can only be called when connected to the remote Oracle Blockchain Platform network. Anyone can call this method.
func (t *Controller) GetTokenHistory(tokenId string) (interface{}, error) {
      /*
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.GetTokenHistory", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      */
      return t.Ctx.ERC721Token.History(tokenId)
}
Parameters:
  • tokenId: string – The ID of the token.
Return Value Example:
[
    {
        "IsDelete": "false",
        "Timestamp": "2022-04-06T19:22:52z",
        "TxId": "6b7989be322956164a8d1cd7bf2a7187d59eba73ce756e6bf946ab48b349bbc0",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "CreationDate": "2022-04-06T19:22:23z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 100,
            "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "token Description",
            "TokenId": "monalisa",
            "TokenMetadata": {
               "Description": "Mona Lisa Painting",
               "Image": "monalisa.jpeg",
               "PainterName": "Leonardo_da_Vinci",
               "PaintingName": "Mona_Lisa"
            },
           "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg""
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2022-04-06T19:22:23z",
        "TxId": "e61bcb3cb61c8920f7e6d8f0d19726c7c88d876e0ad6cfb052cfb92d49985c3f",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "CreationDate": "2022-04-06T19:22:23z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 100,
            "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "",
            ""TokenId": "monalisa",
            "TokenMetadata": {
                "Description": "Mona Lisa Painting",
                "Image": "monalisa.jpeg",
                "PainterName": "Leonardo_da_Vinci",
                "PaintingName": "Mona_Lisa"
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
        }
    }
]
getTokenObject
This is a utility method that returns an instance of the token for a specified token ID. This method is used by many of the automatically generated methods to fetch token objects. You can call this method as needed from your custom methods. When you create a tokenized asset or class, update the switch case with the corresponding Token class to return the correct token object. The ochain sync command in Blockchain App Builder automatically creates a switch case when a tokenized asset is created in the specification file. Because this method is private, it is not directly invokable and can only be called from other methods.
func (t *Controller) getTokenObject(tokenId string) (reflect.Value, error) {
      if tokenId == "" {
            return reflect.Value{}, fmt.Errorf("error in retrieving token, token_id cannot be empty")
      }
      tokenAsset, err := t.Ctx.ERC721Token.Get(tokenId)
      if err != nil {
            return reflect.Value{}, fmt.Errorf("no token exists with id %s %s", tokenId, err.Error())
      }
      tokenName := tokenAsset.(map[string]interface{})["TokenName"].(string)
      switch tokenName {
      case "<Token Name>":
            var asset <Token Class>
            _, err := t.Ctx.ERC721Token.Get(tokenId, &asset)
            if err != nil {
                  return reflect.Value{}, err
            }
            return reflect.ValueOf(&asset), nil
      default:
            return reflect.Value{}, fmt.Errorf("no token exists with token name %s", tokenName)
      }
}
Parameters:
  • tokenId: string – The ID of the token.
OwnerOf
This method returns the account 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.ERC721Token.OwnerOf(tokenId)
}
Parameters:
  • tokenId: string – The ID of the token.
Returns:
  • A JSON object of the owner's account ID.
Return Value Example:
{"Owner": "oaccount~ec32cff8635a056f3dda3da70b1d6090d61f66c6a170c4a95fd008181f729dba"}
Name
This method returns the name of the token class. Anyone can call this method.
func (t *Controller) Name() (interface{}, error) {
      return t.Ctx.ERC721Token.Name()
}
Parameters:
  • none
Returns:
  • A JSON object of the token name.
Return Value Example:
{"TokenName": "paintingnft"}
Symbol
This method returns the symbol of the token class. Anyone can call this method.
func (t *Controller) Symbol() (interface{}, error) {
      return t.Ctx.ERC721Token.Symbol()
}
Parameters:
  • none
Returns:
  • A JSON object of the token symbol.
Return Value Example:
{"Symbol": "PNT"}
TokenURI
This method returns the URI of a specified token. Anyone can call this method.
func (t *Controller) TokenURI(tokenId string) (interface{}, error) {
      return t.Ctx.ERC721Token.TokenURI(tokenId)
}
Parameters:
  • tokenId: string – The ID of the token.
Returns:
  • On success, a JSON object of the token URI.
Return Value Example:
{"TokenURI": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"}
TotalSupply
This method returns the total number of minted tokens. This method can be called only by a Token Admin of the chaincode.
func (t *Controller) TotalSupply() (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.TotalSupply", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Token.TotalSupply()
}
Parameters:
  • none
Returns:
  • On success, a JSON object of the token count.
Return Value Example:
{"TotalSupply": 3}
TotalNetSupply
This method returns the total number of minted tokens minus the number of burned tokens. This method can be called only by a Token Admin of the chaincode.
func (t *Controller) TotalNetSupply() (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.TotalNetSupply", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Token.GetTotalMintedTokens()
}
Parameters:
  • none
Returns:
  • On success, a JSON object of the token count.
Return Value Example:
{"TotalNetSupply": 2}

Methods for Account Management

CreateAccount
This method creates an account for a specified user and token. An account must be created for any user who will have tokens at any point. Accounts track the number of NFTs a user has. Users must have accounts in the network to complete token-related operations. You can create only one NFT account per user.

An account ID is an alphanumeric set of characters, prefixed with oaccount~ and followed by an SHA-256 hash of the membership service provider ID (OrgId) of the user in the current network organization, the user name or email ID (UserId) of the instance owner or the user who is logged in to the instance, and the constant string nft. This method can be called only by the Token Admin of the chaincode.

func (t *Controller) CreateAccount(orgId string, userId string, tokenType string) (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ACCOUNT.CreateAccount", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Account.CreateAccount(orgId, userId, tokenType)
}
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
  • tokenType: string – The only supported token type is nonfungible.
Returns:
  • On success, a JSON object of the account that was created.
Return Value Example:
{
    "AssetType": "oaccount",
    "BapAccountVersion" : 0,
    "AccountId": "oaccount~a0a60d54ba9e2ff349737d292ea10ebd9cc8f1991c11443c19d20aea299a9507",
    "UserId": "admin",
    "OrgId": "Org1MSP",
    "TokenType": "nonfungible",
    "NoOfNfts": 0
}
BalanceOf
This method returns the total number of NFTs that a specified user holds. This method can be called only by a Token Admin of the chaincode or by the account owner.
func (t *Controller) BalanceOf(orgId string, userId string) (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ACCOUNT.BalanceOf", "TOKEN", map[string]string{"orgId": orgId, "userId": userId})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      accountId, err := t.Ctx.ERC721Account.GenerateAccountId(orgId, userId)
      if err != nil{
            return nil,err
      }
      return t.Ctx.ERC721Account.BalanceOf(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.
Returns:
  • A JSON object of the current NFT count.
Return Value Example:
{"totalNfts": 0}
GetAllAccounts
This method returns a list of all accounts. 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) GetAllAccounts() (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ACCOUNT.GetAllAccounts", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Account.GetAllAccounts()
}
Parameters:
  • none
Returns:
  • On success, a JSON array of all accounts.
Return Value Example:
[
    {
        "key": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
        "valueJson": {
            "AccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "AssetType": "oaccount",
            "BapAccountVersion" : 0,
            "NoOfNfts": 5,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user1"
        }
    },
    {
        "key": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
        "valueJson": {
            "AccountId": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
            "AssetType": "oaccount",
            "BapAccountVersion" : 0,
            "NoOfNfts": 0,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user_minter"
        }
    },
    {
        "key": "oaccount~5541fb520058d83664b844e7a55fe98d574ddeda765d0e795d4779e9ccc271ce",
        "valueJson": {
            "AccountId": "oaccount~5541fb520058d83664b844e7a55fe98d574ddeda765d0e795d4779e9ccc271ce",
            "AssetType": "oaccount",
            "BapAccountVersion" : 0,
            "NoOfNfts": 0,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user_burner"
        }
    }
]
GetAccountByUser
This method returns 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) GetAccountByUser(orgId string, userId string) (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ACCOUNT.GetAccountByUser", "TOKEN", map[string]string{"orgId": orgId, "userId": userId})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Account.GetAccountWithStatusByUser(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 the following properties:
  • AccountId – The ID of the user account.
  • UserId – The user name or email ID of the user.
  • OrgId – The membership service provider (MSP) ID of the user in the current organization.
  • TokenType – The type of token that the account holds.
  • NoOfNfts – The total number of NFTs held by the account.
  • BapAccountVersion – An account object parameter for internal use.
  • Status – The current status of the user account.
Return Value Example:
{
  "AccountId": "oaccount~cc301bee057f14236a97d434909ec1084970921b008f6baab09c2a0f5f419a9a",
  "AssetType": "oaccount",
  "BapAccountVersion": 0,
  "NoOfNfts": 0,
  "OrgId": "appdev",
  "Status": "active",
  "TokenType": "nonfungible",
  "UserId": "idcqa"
}
GetUserByAccountId
This method returns the user details of a specified account. This method can be called by any user.
func (t *Controller) GetUserByAccountId(accountId string) (interface{}, error) {
      return t.Ctx.ERC721Account.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": "Org1MSP",
    "UserId": "admin"
}
GetAccountHistory
This method returns account history for a specified user. This method can be called only by a Token Admin of the chaincode or by the account owner.
func (t *Controller) GetAccountHistory(orgId string, userId string) (interface{}, error) {
      accountId, err := t.Ctx.ERC721Account.GenerateAccountId(orgId, userId)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ACCOUNT.History", "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.ERC721Account.History(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.
Returns:
  • On success, a list of objects.
Return Value Example:
[
    {
        "IsDelete": "false",
        "Timestamp": "2022-04-06T08:16:53Z",
        "TxId": "750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7",
        "Value": {
            "AccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "AssetType": "oaccount",
            "BapAccountVersion" : 1,
            "NoOfNfts": 1,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user1"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2022-04-06T08:15:19Z",
        "TxId": "49eb84c42d452e5ba0028d8ebb4190454cf9013a11c0bad3e96594af452d4982",
        "Value": {
            "AccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "AssetType": "oaccount",
            "BapAccountVersion" : 0,
            "NoOfNfts": 0,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user1"
        }
    }
]

Methods for Role Management

AddRole
This method adds a role to a specified user. This method can be called only by a Token Admin of the chaincode.
func (t *Controller) AddRole(role string, orgId string, userId string) (interface{}, error) {
      accountId, err := t.Ctx.ERC721Account.GenerateAccountId(orgId, userId)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.AddRoleMember", "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.ERC721Token.AddRoleMember(role, accountId)
}
Parameters:
  • userRole: string – The name of the role to add to the specified user. The mintable and burnable behaviors correspond to the minter_role_name and burner_role_name properties of the specification file.
  • 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 with user details.
Return Value Example:
{"msg": "Successfully added role minter to oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (orgId : Org1MSP, userId : admin)"}
RemoveRole
This method removes a role from a specified user. This method can be called only by a Token Admin of the chaincode.
func (t *Controller) RemoveRole(userRole string, orgId string, userId string) (interface{}, error) {
      accountId, err := t.Ctx.ERC721Account.GenerateAccountId(orgId, userId)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.RemoveRoleMember", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Token.RemoveRoleMember(userRole, accountId)
}
Parameters:
  • userRole: string – The name of the role to remove from the specified user. The mintable and burnable behaviors correspond to the minter_role_name and burner_role_name properties of the specification file.
  • 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 with user details.
Return Value Example:
{"msg": "successfully removed memberId oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (orgId : Org1MSP, userId : admin) from role minter"}
GetAccountsByRole
This method returns a list of all account IDs for a specified role. This method can be called only by a Token Admin of the chaincode.
func (t *Controller) GetAccountsByRole(userRole string) (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ROLE.GetAccountsByRole", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Role.GetAccountsByRole(userRole)
}
Parameters:
  • userRole: string – The name of the role to search for.
Returns:
  • On success, a JSON array of account IDs.
Return Value Example:
{
    "accounts": [
        "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d"
    ]
}
GetUsersByRole
This method returns a list of all users for a specified role. This method can be called only by a Token Admin of the chaincode.
func (t *Controller) GetUsersByRole(userRole string) (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ROLE.GetUsersByRole", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Role.GetUsersByRole(userRole)
}
Parameters:
  • userRole: string – The name of the role to search for.
Returns:
  • On success, a JSON array of the user objects (orgId and userId).
Return Value Example:
{
    "Users": [
        {
            "OrgId": "Org1MSP",
            "UserId": "admin"
        }
    ]
}
IsInRole
This method returns a Boolean value to indicate if a user has a specified role. This method can be called only by a Token Admin of the chaincode or the Account Owner of the account.
func (t *Controller) IsInRole(orgId string, userId string, role string) (interface{}, error) {
      accountId, err := t.Ctx.ERC721Account.GenerateAccountId(orgId, userId)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.IsInRole", "TOKEN", map[string]string{"accountId": accountId})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      result, err := t.Ctx.ERC721Token.IsInRole(role, accountId)
      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.
  • userRole: string – The name of the role to search for.
Returns:
  • On success, a JSON string of the Boolean result.
Return Value Example:
{"result":"true"}

Methods for Transaction History Management

GetAccountTransactionHistory
This method returns account transaction history for a specified user. This method can be called by the Token Admin of the chaincode or the owner of the account.
func (t *Controller) GetAccountTransactionHistory(orgId string, userId string) (interface{}, error) {
      accountId, err := t.Ctx.ERC721Account.GenerateAccountId(orgId, userId)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ACCOUNT.GetAccountTransactionHistory", "TOKEN", map[string]string{"accountId": accountId})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }

      transactionArray, err := t.Ctx.ERC721Account.GetAccountTransactionHistory(accountId)
      return transactionArray, err
}
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 list of objects.
Return Value Example:
[
     {
        "Timestamp": "2022-04-06T08:31:39Z",
        "TokenId": "monalisa",
        "TransactedAccount": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
        "TransactionId": "otransaction~5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7",
        "TransactionType": "DEBIT"
    }
    {
        "Timestamp": "2022-04-06T08:16:53Z",
        "TokenId": "monalisa",
        "TransactedAccount": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
        "TransactionId": "otransaction~750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7",
        "TransactionType": "MINT"
    }
]
GetAccountTransactionHistoryWithFilters
This method returns account transaction history for a specified user, filtered by PageSize, Bookmark, StartTime and EndTime. This method 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) GetAccountTransactionHistoryWithFilters(orgId string, userId string, filters ...erc721Account.AccountHistoryFilters) (interface{}, error) {
      accountId, err := t.Ctx.ERC721Account.GenerateAccountId(orgId, userId)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721ACCOUNT.GetAccountTransactionHistoryWithFilters", "TOKEN", map[string]string{"accountId": accountId})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }

      transactionArray, err := t.Ctx.ERC721Account.GetAccountTransactionHistoryWithFilters(accountId, filters...)
      return transactionArray, err
}
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.
  • filters: string – An optional parameter. If empty, all records are returned. The PageSize property determines the number of records to return. If PageSize is 0, the default page size is 20. The Bookmark property determines the starting index of the records to return. For more information, see the Hyperledger Fabric documentation. The StartTime and EndTime properties must be specified in RFC-3339 format.
Returns:
  • On success, a list of objects.
Return Value Example:
[
     {
        "Timestamp": "2022-04-06T08:31:39Z",
        "TokenId": "monalisa",
        "TransactedAccount": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
        "TransactionId": "otransaction~5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7",
        "TransactionType": "DEBIT"
    }
    {
        "Timestamp": "2022-04-06T08:16:53Z",
        "TokenId": "monalisa",
        "TransactedAccount": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
        "TransactionId": "otransaction~750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7",
        "TransactionType": "MINT"
    }
]
GetTransactionById
This method returns transaction history for a specified transaction ID. This method can be called only by a Token Admin of the chaincode or by the account owner.
func (t *Controller) GetTransactionById(transactionId string) (interface{}, error) {
      return t.Ctx.ERC721Transaction.GetTransactionById(transactionId)
}
Parameters:
  • transactionId: string – The id of the transaction asset.
Returns:
  • On success, a list of objects.
Return Value Example:
{
    "History": [
        {
            "IsDelete": "false",
            "Timestamp": "2022-04-06T08:31:39Z",
            "TxId": "5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7",
            "Value": {
                "AssetType": "otransaction",
                "Data": "",
                "FromAccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
                "Timestamp": "2022-04-06T08:31:39Z",
                "ToAccountId": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
                "TokenId": "monalisa",
                "TransactionId": "otransaction~5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7",
                "TransactionType": "TRANSFER",
                "TriggeredByAccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1"
            }
        }
    ],
    "TransactionId": "otransaction~5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7"
}
DeleteHistoricalTransactions
This method deletes transactions older than a specified time stamp in the state database. This method can be called only by the Token Admin of the chaincode.
func (t *Controller) DeleteHistoricalTransactions(timestamp string) (interface{}, error) {
      auth, err := t.Ctx.ERC721Auth.CheckAuthorization("ERC721TRANSACTION.DeleteHistoricalTransactions", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.ERC721Transaction.DeleteHistoricalTransactions(timestamp)
}
Parameters:
  • timestamp: Date – A time stamp. All transactions before the time stamp will be deleted.
Returns:
  • On success, a list of objects.
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

Create<Token Name>Token
This method creates (mints) an NFT. The asset and associated properties are saved in the state database. The caller of this transaction must have a token account. The caller of this transaction becomes the owner of the NFT. If the token specification file includes the roles section for behaviors and the minter_role_name property for roles, then the caller of the transaction must have the minter role. Otherwise, any caller can mint NFTs.
func (t *Controller) Create<Token Name>Token(tokenAsset <Token Class>) (interface{}, error) {
      return t.Ctx.ERC721Token.CreateToken(&tokenAsset)
}
Parameters:
  • tokenAsset: <Token Class> – The token asset to mint. For more information about the properties of the token asset, see the input specification file.
Returns:
  • On success, a JSON token asset object that includes the following properties:
  • Behavior – A description of all token behaviors.
  • CreatedBy – The account ID of the user who called the transaction to mint the token.
  • CreationDate – The time stamp of the transaction.
  • IsBurned – A Boolean value that indicates if the NFT identified by tokenId is burned.
  • Mintable – A description of the properties of mintable behavior. The max_mint_quantity property specifies the maximum number of NFTs of this token class that can be created.
  • Owner – The account ID of the current owner of the token. During the minting process, the caller of this method becomes the owner of the token.
  • Symbol – The symbol of the token.
  • TokenDesc – The description of the token.
  • TokenMetadata – JSON information that describes the token.
  • TokenName – The name of the token.
  • TokenStandard – The standard of the token.
  • TokenType – The type of token held by this account.
  • TokenUnit – The unit of the token.
  • TokenUri – The URI of the token.
Return Value Example:
{
    "AssetType": "otoken",
    "Behavior": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",        
    "CreationDate": "2022-04-06T08:16:53Z",
    "IsBurned": false,
     "Mintable": {
        "Max_mint_quantity": 20000
    },
    "NftBasePrice": 100,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "Symbol": "PNT",
    "TokenDesc": "token Description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "paintingnft",
    "TokenStandard": "erc721+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
Update<Token Name>Token
This method updates token properties. This method can be called only by the user who is the owner or creator of the token. After a token asset is created, only the token owner can update the token custom properties. If the user is both token owner and creator of a token, they can also update the TokenDesc property. Token metadata cannot be updated. You must pass all token properties to this method, even if you want to update only certain properties.
func (t *Controller) Update<Token Name>Token(tokenAsset <Token Class>) (interface{}, error) {
      return t.Ctx.ERC721Token.UpdateToken(&tokenAsset)
}
Parameters:
  • tokenAsset: <Token Class> – The token asset to update. For more information about the the properties of the token asset, see the input specification file.
Returns:
  • On success, an updated JSON token asset object
Return Value Example:
{
    "AssetType": "otoken",
    "Behavior": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",      
    "CreationDate": "2022-04-06T08:16:53Z",
    "IsBurned": false,    
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "NftBasePrice": 200,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "Symbol": "PNT",
    "TokenDesc": "Token Description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "paintingnft",
    "TokenStandard": "erc721+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
}

Methods for Token Behavior Management - Transferable Behavior

SafeTransferFrom
This method transfers ownership of the specified NFT from the caller to another account. This method includes the following validations:
  • The token exists and is not burned.
  • The sender account and receiver account exist and are not the same account.
  • The sender account owns the token.
  • The caller of the function is the sender.
func (t *Controller) SafeTransferFrom(fromOrgId string, fromUserId string, toOrgId string, toUserId string, tokenId string, data ...string) (interface{}, error) {
      tokenAssetValue, err := t.getTokenObject(tokenId)
      if err != nil {
            return nil, err
      }
      fromAccountId, err := t.Ctx.ERC721Account.GenerateAccountId(fromOrgId, fromUserId)
      if err != nil {
            return nil, err
      }
      toAccountId, err := t.Ctx.ERC721Account.GenerateAccountId(toOrgId, toUserId)
      if err != nil {
            return nil, err
      }
      return t.Ctx.ERC721Token.SafeTransferFrom(fromAccountId, toAccountId, tokenAssetValue.Interface(), data...)
}
Parameters:
  • 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.
  • 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.
  • tokenId: string – The ID of the token to transfer.
  • data: string – Optional additional information to store in the transaction record.
Returns:
  • On success, a message with the sender and receiver account details.
Return Value Example:
{"msg": "Successfully transferred NFT token: 'monalisa' from Account-Id: oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (Org-Id: Org1MSP, User-Id: admin) to Account-Id: oaccount~ec32cff8635a056f3dda3da70b1d6090d61f66c6a170c4a95fd008181f729dba (Org-Id: Org1MSP, User-Id: user1)"}
TransferFrom
This method transfers ownership of the specified NFT from a sender account to a receiver account. It is the responsibility of the caller to pass the correct parameters. This method can be called by any user, not only the token owner. This method includes the following validations:
  • The token exists and is not burned.
  • The sender account and receiver account exist and are not the same account.
  • The sender account owns the token.
func (t *Controller) TransferFrom(fromOrgId string, fromUserId string, toOrgId string, toUserId string, tokenId string) (interface{}, error) {
      tokenAssetValue, err := t.getTokenObject(tokenId)
      if err != nil {
            return nil, err
      }
      fromAccountId, err := t.Ctx.ERC721Account.GenerateAccountId(fromOrgId, fromUserId)
      if err != nil {
            return nil, err
      }
      toAccountId, err := t.Ctx.ERC721Account.GenerateAccountId(toOrgId, toUserId)
      if err != nil {
            return nil, err
      }
      return t.Ctx.ERC721Token.TransferFrom(fromAccountId, toAccountId, tokenAssetValue.Interface())
}
Parameters:
  • 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.
  • 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.
  • tokenId: string – The ID of the token to transfer.
Returns:
  • On success, a message with the sender and receiver account details.
Return Value Example:
{"msg": "Successfully transferred NFT token: 'monalisa' from Account-Id: oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (Org-Id: Org1MSP, User-Id: admin) to Account-Id: oaccount~ec32cff8635a056f3dda3da70b1d6090d61f66c6a170c4a95fd008181f729dba (Org-Id: Org1MSP, User-Id: user1)"}

Methods for Token Behavior Management - Burnable Behavior

Burn
This method deactivates, or burns, the specified NFT from the caller's account. The caller of this method must have an account. A token cannot be burned unless the token specification file includes the burnable behavior. If no burner_role_name property is specified in the roles section of the specification file, then the owner of the token can burn the token. If a burner_role_name property is specified in the roles section, then the user assigned the burner role who is also the minter (creator) of the token can burn the token.
func (t *Controller) Burn(tokenId string) (interface{}, error) {
      tokenAssetValue, err := t.getTokenObject(tokenId)
      if err != nil {
            return nil, err
      }
      return t.Ctx.ERC721Token.Burn(tokenAssetValue.Interface())
}
Parameters:
  • tokenId: string – The ID of the token to burn.
Returns:
  • On success, a message with the account details.
Return Value Example:
{"msg": "Successfully burned NFT token: 'monalisa' from Account-Id: oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (Org-Id: Org1MSP, User-Id: admin"}
BurnNFT
This method deactivates, or burns, the specified NFT from the caller's account, and returns a token object and token history. The caller of this method must have an account. A token cannot be burned unless the token specification file includes the burnable behavior. If no burner_role_name property is specified in the roles section of the specification file, then the owner of the token can burn the token. If a burner_role_name property is specified in the roles section, then the user assigned the burner role who is also the minter (creator) or owner of the token can burn the token.
func (t *Controller) BurnNFT(tokenId string) (interface{}, error) {
      tokenAsset, err := t.Ctx.ERC721Token.Get(tokenId)
      if err != nil {
            return nil, err
      }
      tokenHistory, err := t.Ctx.ERC721Token.History(tokenId)
      if err != nil {
            return nil, err
      }
      token := tokenAsset.(map[string]interface{})
      if token[constants.IsBurned] == true {
            return nil, fmt.Errorf("token with tokenId %s is already burned", tokenId)
      }
      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)
      token[constants.IsBurned] = true
      _, err = t.Burn(tokenId)
      if err != nil {
            return nil, err
      }
      return token, nil
}
Parameters:
  • tokenId: string – The ID of the token to burn.
Returns:
  • On success, a token object that includes token history information.
Return Value Example:
{
    "AssetType": "otoken",
    "Behavior": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2023-08-22T13:19:33+05:30",
    "IsBurned": true,
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "On_sale_flag": false,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Price": 120,
    "Roles": {
        "minter_role_name": "minter"
    },
    "Symbol": "ART",
    "TokenDesc": "",
    "TokenHistory": "[{\"IsDelete\":\"false\",\"Timestamp\":\"2023-08-22T13:19:33+05:30\",\"TxId\":\"0219099bcaaecd5f76f7f08d719384fd5ed34103a55bd8d3754eca0bfc691594\",\"Value\":{\"AssetType\":\"otoken\",\"Behavior\":[\"indivisible\",\"singleton\",\"mintable\",\"transferable\",\"burnable\",\"roles\"],\"CreatedBy\":\"oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d\",\"CreationDate\":\"2023-08-22T13:19:33+05:30\",\"IsBurned\":false,\"Mintable\":{\"Max_mint_quantity\":20000},\"On_sale_flag\":false,\"Owner\":\"oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d\",\"Price\":120,\"Roles\":{\"minter_role_name\":\"minter\"},\"Symbol\":\"ART\",\"TokenDesc\":\"\",\"TokenId\":\"1\",\"TokenMetadata\":{\"Description\":\"\",\"Image\":\"\",\"Painter_name\":\"\",\"Painting_name\":\"\"},\"TokenName\":\"artcollection\",\"TokenStandard\":\"erc721+\",\"TokenType\":\"nonfungible\",\"TokenUnit\":\"whole\",\"TokenUri\":\"example.com\"}}]",
    "TokenId": 1,
    "TokenMetadata": {
        "Description": "",
        "Image": "",
        "Painter_name": "",
        "Painting_name": ""
    },
    "TokenName": "artcollection",
    "TokenStandard": "erc721+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "example.com"
}

Custom Methods

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

The following example shows how to use token SDK methods in custom methods. When the Sell method is called, it posts a token for sale for a specified price.

func (t *Controller) Sell(tokenId string, sellingPrice int) (interface{}, error) {
	var tokenAsset ArtCollection
	_, err := t.Ctx.ERC721Token.Get(tokenId, &tokenAsset)
    if err != nil {
       return nil, err
	}

 /**  * price is a custom asset
      attribute to set the price of a non-fungible token in the
      marketplace  */
	tokenAsset.Price = sellingPrice
 /**  * on_sale_flag is a
      custom asset attribute that maintains non-fungible token selling status in the
      marketplace  */
	tokenAsset.On_sale_flag = true

	_, err = t.Ctx.ERC721Token.UpdateToken(tokenAsset)
    if err != nil {
		return nil, err
	}
	
	msg := fmt.Sprintf("Token ID : %s has been posted for selling in the marketplace", tokenId)
	return msg, nil
}

NFT SDK Methods

Methods for Access Control Management

The NFT SDK provides an access control function. Some methods can be called only by a Token Admin or Account Owner of the token. You can use this feature to ensure that operations are carried out only by the intended users. Any unauthorized access results in an error. To use the access control function, import the Authorization class from the ../lib/auth module.
import { ERC721Authorization } from '../lib/erc721-auth';
CheckAuthorization
Use this method to add an access control check to an operation. Most automatically generated methods include access control. Certain token methods can be run only by an ERC721Admin or the Account Owner of the token or by the MultipleAccountOwner for users with multiple accounts. The CheckAuthorization method is part of the erc721Auth package, which you access via the Ctx struct (receiver). 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. To use your own access control or to disable access control, remove the access control code from the automatically generated controller methods and custom methods.
  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
     auth.IsTokenAdmin = []string{"Admin", "MultipleAccountOwner"}

      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"}

      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
Ctx.ERC721Auth.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 tokenId parameter.
Returns:
  • A Boolean response and, if required, an error.
Examples:
t.Ctx.ERC721Auth.CheckAuthorization(<parameters>)

Admin access

t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.GetAllTokens", "TOKEN")

AccountOwner access

t.Ctx.ERC721Auth.CheckAuthorization("ERC721ACCOUNT.History", "TOKEN", accountId)

MultipleAccountOwner access

t.Ctx.ERC721Auth.CheckAuthorization("ERC721ACCOUNT.BalanceOf", "TOKEN", orgId, userId)

TokenOwner access

t.Ctx.ERC721Auth.CheckAuthorization("ERC721TOKEN.Get", "TOKEN", tokenId)
IsUserTokenAdmin
This method returns a map with the Boolean value true if the caller of the function is a Token Admin. Otherwise the method returns false.
Ctx.ERC721Auth.IsUserTokenAdmin(orgId string, userId string)  (interface{}, error)
Parameters:
  • orgId – The membership service provider (MSP) ID of the user in the current network organization.
  • userId – The user name or email ID of the user.
Returns:
  • A Boolean response.
Example:

t.Ctx.ERC721Auth.IsUserTokenAdmin(orgId, userId)

{"result":true}
AddAdmin
This method adds a user as a Token Admin of the token chaincode.
Ctx.ERC721Admin.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. On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Admin.AddAdmin(orgId, userId)

{"msg":"Successfully added Admin (OrgId: Org1MSP, UserId: user1)"}
RemoveAdmin
This method removes a user as a Token Admin of the token chaincode.
Ctx.ERC721Admin.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. On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Admin.RemoveAdmin(orgId, userId)

{"msg":"Successfuly removed Admin (OrgId Org1MSP UserId user1)"}
GetAllAdmins
This method returns a list of all Token Admin users.
Ctx.ERC721Admin.GetAllAdmins() (Admin[], error) 
Parameters:
  • none
Returns:
  • On success, a list of all Token Admin users. On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Admin.GetAllAdmins()

{
    "admins": [
        {
            "OrgId":"Org1MSP",
            "UserId":"admin"
        }
    ]
}
GetAllAdminUsers
This method returns a list of all Token Admin users.
Ctx.ERC721Admin.GetAllAdminUsers() (interface{}, error) 
Parameters:
  • none
Returns:
  • On success, a list of all Token Admin users in map[string]interface{} format. On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Admin.GetAllAdminUsers()

{
    "admins": [
        {
            "OrgId":"Org1MSP",
            "UserId":"admin"
        }
    ]
}

Methods for Token Configuration Management

CreateToken
This method creates a token and saves its properties in the state database. This method can be called only by users with the minter role.
Ctx.ERC721Token.CreateToken(args ...interface{})
Parameters:
  • A variable argument where args[0] contains a reference to the token struct of the required type.
Returns:
  • On success, an interface[] with token details. On error, a non-nil object with an error message.
Example:

t.Ctx.ERC721Token.CreateToken(&tokenAsset)

{
    "AssetType": "otoken",
    "Behavior": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",        
    "CreationDate": "2022-04-06T08:16:53Z",
    "IsBurned": false,
     "Mintable": {
        "Max_mint_quantity": 20000
    },
    "NftBasePrice": 100,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "Symbol": "PNT",
    "TokenDesc": "token Description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "paintingnft",
    "TokenStandard": "erc721+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"
}
GetTokenUri
This method returns the token URI for a specified token.
Ctx.ERC721Token.GetTokenURI(tokenId string) (interface{}, error)
Parameters:
  • tokenId: string – The ID of the token.
Returns:
  • On success, it returns a map of the new token URI in the string data type. On error, a non-nil object with an error message.
Example:

t.Ctx.ERC721Token.GetTokenURI(tokenId)

{"TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"}
TokenUri
This method returns the token URI for a specified token.
Ctx.ERC721Token.TokenURI(tokenId string) (interface{}, error)
Parameters:
  • tokenId: string – The ID of the token.
Returns:
  • On success, it returns a map of the new token URI in the string data type. On error, a non-nil object with an error message.
Return Value Example:

t.Ctx.ERC721Token.TokenURI(tokenId)

{"TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg"}
Symbol
This method returns the symbol of the token class.
Ctx.ERC721Token.Symbol() (interface{}, error)
Parameters:
  • none
Returns:
  • On success, a map of the symbol in the string data type. On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Token.Symbol()

{"Symbol": "PNT"}
Name
This method returns the name of the token class.
Ctx.ERC721Token.Name() (interface{}, error)
Parameters:
  • none
Returns:
  • On success, a map of the token name in the string data type. On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Token.Name()

{"TokenName": "paintingnft"}
OwnerOf
This method returns the account ID of the owner of a specified token.
Ctx.ERC721Token.OwnerOf(tokenId string) (interface{}, error)
Parameters:
  • tokenId: string – The ID of the token.
Returns:
  • On success, a map of the account ID of the owner in the string data type. On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Token.OwnerOf(tokenId)

{"Owner": "oaccount~ec32cff8635a056f3dda3da70b1d6090d61f66c6a170c4a95fd008181f729dba"}
TotalSupply
This method returns the total number of minted NFTs.
Ctx.ERC721Token.TotalSupply() (map[string]interface{}, error)
Parameters:
  • tokenId: string – The ID of the token.
Returns:
  • On success, a map of the total supply of tokens in the number data type. On error, a rejection with an error message.
Example:

t.Ctx.ERC721Token.TotalSupply();

{"TotalSupply": 3}
GetAllTokens
This method returns all of the token assets that are saved in the state database. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
Ctx.ERC721Token.GetAllTokens()  (interface{}, error)
Parameters:
  • none
Returns:
  • On success, a map of all of the token assets. On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Token.GetAllTokens()

[
    {
        "key": "monalisa",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintab
 
le",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "CreationDate": "2022-04-10T11:01:42Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 0,
            "Owner": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "token Description",
            "TokenId": "monalisa",
            "TokenMetadata": {
                 "Description": "Mona Lisa Painting",
                 "Image": "monalisa.jpeg",
                 "PainterName": "Leonardo_da_Vinci",
                 "PaintingName": "Mona_Lisa"
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
        }
    },
    {
        "key": "monalisa2",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "CreationDate": "2022-04-10T11:04:44Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 100,
            "Owner": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "",
            "TokenId": "monalisa1",
            "TokenMetadata": {
                 "Description": "Mona Lisa Painting",
                 "Image": "monalisa.jpeg",
                 "PainterName": "Leonardo_da_Vinci",
                 "PaintingName": "Mona_Lisa"
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
        }
        }
    }
]
GetAllTokensByUser
This method returns all tokens that are owned by a specified account ID. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
Ctx.ERC721Token.GetAllTokensByUser(accountId string) (interface{}, error)
Parameters:
  • accountId: string – The ID of the account.
Returns:
  • On success, a map of token assets for the specified account. On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Token.GetAllTokensByUser(accountId)

[
    {
        "key": "monalisa",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "CreationDate": "2022-04-10T11:01:42Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 0,
            "Owner": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "token Description",
            "TokenId": "monalisa",
            "TokenMetadata": {
                 "Description": "Mona Lisa Painting",
                 "Image": "monalisa.jpeg",
                 "PainterName": "Leonardo_da_Vinci",
                 "PaintingName": "Mona_Lisa"
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
        }
    },
    {
        "key": "monalisa2",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "CreationDate": "2022-04-10T11:04:44Z",
            "IsBurned": false,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 100,
            "Owner": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "",
            "TokenId": "monalisa1",
            "TokenMetadata": {
                 "Description": "Mona Lisa Painting",
                 "Image": "monalisa.jpeg",
                 "PainterName": "Leonardo_da_Vinci",
                 "PaintingName": "Mona_Lisa"
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
        }
        }
    }
]
Get
This method returns the specified token object if it is present in the state database.
Ctx.Get(Id string, result ...interface{}) (interface{}, error)
Parameters:
  • tokenId: string – The ID of the token.
  • result – A variable argument, where the first argument result[0] is a reference to an empty Token object of the correct type, which will contain the token data after a successful call of the method.
Returns:
  • On success, a map with the token asset data. Also, if result[0] is passed then the data is assigned to result[0]. On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Token.Get(tokenId, &asset)

{
    "AssetType": "otoken",
    "Behavior": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "CreationDate": "2022-04-06T00:35:42z",
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "NftBasePrice": 200,
    "Owner": "oaccount~ec32cff8635a056f3dda3da70b1d6090d61f66c6a170c4a95fd008181f729dba",
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "Symbol": "PNT",
    "TokenDesc": "Token Description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "paintingnft",
    "TokenStandard": "erc721+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
    "TransferredBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "TransferredDate": "2022-04-06T00:51:56z"
}
UpdateToken
This method updates token properties. This method can be called only by the owner or creator of the token. After a token asset is created, only the token owner can update the token custom properties. If the user is both token owner and creator of a token, they can also update the TokenDesc property. Token metadata cannot be updated. You must pass all token properties to this method, even if you want to update only certain properties.
Ctx.ERC721Token.UpdateToken(asset interface{}) (interface{}, error)
Parameters:
  • A reference to the token struct data of the required type
Returns:
  • On success, a promise message with token details. On error, a rejection with an error message.
Example:

t.Ctx.ERC721Token.UpdateToken(&asset)

{
    "AssetType": "otoken",
    "Behavior": [
        "indivisible",
        "singleton",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",     
    "CreationDate": "2022-04-06T08:16:53Z",
    "IsBurned": false,   
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "NftBasePrice": 200,
    "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter"
    },
    "Symbol": "PNT",
    "TokenDesc": "Token Description",
    "TokenId": "monalisa",
    "TokenMetadata": {
        "Description": "Mona Lisa Painting",
        "Image": "monalisa.jpeg",
        "PainterName": "Leonardo_da_Vinci",
        "PaintingName": "Mona_Lisa"
    },
    "TokenName": "paintingnft",
    "TokenStandard": "erc721+",
    "TokenType": "nonfungible",
    "TokenUnit": "whole",
    "TokenUri": "https://bafybeid6pmpp62bongoip5iy2skosvyxh3gr7r2e35x3ctvawjco6ddmsq\\ .ipfs.infura-ipfs.io/?filename=MonaLisa.jpeg",
}
History
This method returns history for the specified token.
Ctx.ERC721Token.History(tokenId: string)  (interface{}, error)
Parameters:
  • tokenId: string – The ID of the token.
Returns:
  • On success, an array of maps. On error, a rejection with an error message.
Example:

t.Ctx.ERC721Token.History(tokenId)

[
    {
        "IsDelete": "false",
        "Timestamp": "2022-04-06T11:34:06z",
        "TxId": "3184eac8738c73ef45501fe23c9e14517892e04e4eb03ec9be834b89c29ea17b",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "BurnedBy": null,
            "BurnedDate": null,
            "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "CreationDate": "2022-04-06T11:33:40+05:30",
            "IsBurned": null,
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 0,
            "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "",
            "TokenId": "t1",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "PainterName": "",
                "PaintingName": ""
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": "",
            "TransferredBy": null,
            "TransferredDate": null
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2022-04-06T11:33:40z",
        "TxId": "d37dba907a849c308b2a38d47cf8a68cdcb4e3d93fa74050774379fccfcd43be",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "indivisible",
                "singleton",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "CreatedBy": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "CreationDate": "2022-04-06T11:33:40+05:30",
            "Mintable": {
                "Max_mint_quantity": 20000
            },
            "NftBasePrice": 0,
            "Owner": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter"
            },
            "Symbol": "PNT",
            "TokenDesc": "",
            "TokenId": "t1",
            "TokenMetadata": {
                "Description": "",
                "Image": "",
                "PainterName": "",
                "PaintingName": ""
            },
            "TokenName": "paintingnft",
            "TokenStandard": "erc721+",
            "TokenType": "nonfungible",
            "TokenUnit": "whole",
            "TokenUri": ""
        }
    }
]
GetNewCtx
This method returns a new TrxContext object. The trxcontext struct holds references to all of the SDK libraries. Access the sdk methods by using only this object. The trxcontext object maintains the mutual exclusivity of transaction stubs in SDK libraries when concurrent transactions are running.
GetNewCtx(stub shim.ChaincodeStubInterface) TrxContext
Parameters:
  • stub – The transaction stub.
Returns:
  • A trxcontext struct.
Example:

trxcontext.GetNewCtx(stub)

trxcontext object.

Methods for Account Management

GenerateAccountId
This method returns an account ID, which is formed by concatenating the membership service provider ID (orgId) and the user name or email ID (userId) and then creating a SHA-256 hash.
Ctx.ERC721Account.GenerateAccountId(orgId string, userId string) (string, 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, the generated account ID. On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Account.GenerateAccountId(orgId, userId)

oaccount~a0a60d54ba9e2ff349737d292ea10ebd9cc8f1991c11443c19d20aea299a9507
CreateAccount
This method creates an account for a specified user. An account must be created for any user who will have tokens at any point. Accounts track the number of NFTs a user has. Users must have accounts in the network to complete token-related operations. You can create only one NFT account per user.

An account ID is an alphanumeric set of characters, prefixed with oaccount~ and followed by an SHA-256 hash of the membership service provider ID (org_id) of the user in the current network organization, the user name or email ID (userId) of the instance owner or the user who is logged in to the instance, and the constant string nft.

Ctx.ERC721Account.CreateAccount(orgId string, userId string, tokenType string) (ERC721Account, 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: string – The only supported token type is nonfungible.
Returns:
  • On success, the new account object. On error, a non-nil object containing an error message
Example:

t.Ctx.ERC721Account.CreateAccount(orgId, userId, tokenType)

{
    "AssetType": "oaccount",
    "AccountId": "oaccount~a0a60d54ba9e2ff349737d292ea10ebd9cc8f1991c11443c19d20aea299a9507",
    "UserId": "admin",
    "BapAccountVersion" : 0,
    "OrgId": "Org1MSP",
    "TokenType": "nonfungible",
    "NoOfNfts": 0
}
GetAllAccounts
This method returns a list of all accounts. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
Ctx.ERC721Account.GetAllAccounts() (interface{}, error)
Parameters:
  • none
Returns:
  • A JSON array of all accounts.
Example:

t.Ctx.ERC721Account.GetAllAccounts()

[
    {
        "key": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
        "valueJson": {
            "AccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "BapAccountVersion" : 0,
            "AssetType": "oaccount",
            "NoOfNfts": 5,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user1"
        }
    },
    {
        "key": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
        "valueJson": {
            "AccountId": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
            "AssetType": "oaccount",
            "BapAccountVersion" : 0,
            "NoOfNfts": 0,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user_minter"
        }
    },
    {
        "key": "oaccount~5541fb520058d83664b844e7a55fe98d574ddeda765d0e795d4779e9ccc271ce",
        "valueJson": {
            "AccountId": "oaccount~5541fb520058d83664b844e7a55fe98d574ddeda765d0e795d4779e9ccc271ce",
            "AssetType": "oaccount",
            "BapAccountVersion" : 0,
            "NoOfNfts": 0,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user_burner"
        }
    }
]
History
This method returns an array of the account history details for a specified account.
Ctx.ERC721Account.History(accountId string) (interface{}, error)
Parameters:
  • accountId: string – The ID of the account.
Returns:
  • On success, a map[string]interface{} array that contains the account history details for the specified account. The account data is shown under the value key in the map. On error, a non-nil error object containing an error message.
Example:

t.Ctx.ERC721Account.History(accountId)

[
    {
        "IsDelete": "false",
        "Timestamp": "2022-04-06T08:16:53Z",
        "TxId": "750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7",
        "Value": {
            "AccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "AssetType": "oaccount",
            "BapAccountVersion" : 1,
            "NoOfNfts": 1,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user1"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2022-04-06T08:15:19Z",
        "TxId": "49eb84c42d452e5ba0028d8ebb4190454cf9013a11c0bad3e96594af452d4982",
        "Value": {
            "AccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
            "AssetType": "oaccount",
            "NoOfNfts": 0,
            "BapAccountVersion" : 0,
            "OrgId": "apPart",
            "TokenType": "nonfungible",
            "UserId": "user1"
        }
    }
]
GetUserByAccountId
This method returns the user details for a specified account.
Ctx.ERC721Account.GetUserByAccountId(accountId string) (interface{}, error)
Parameters:
  • accountId: string – The ID of the account.
Returns:
  • On success, a JSON object that includes user details in the following properties:
    • OrgId – The membership service provider (MSP) ID of the user in the current network organization.
    • UserId – The user name or email ID of the user.
  • On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Account.GetUserByAccountById(accountId)

{
    "OrgId": "Org1MSP",
    "UserId": "admin"
}
GetAccountWithStatusByUser
This method returns 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.ERC721Account.GetAccountWithStatusByUser(orgId, userId) (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 the following properties:
  • AccountId – The ID of the user account.
  • UserId – The user name or email ID of the user.
  • OrgId – The membership service provider (MSP) ID of the user in the current organization.
  • TokenType – The type of token that the account holds.
  • NoOfNfts – The total number of NFTs held by the account.
  • BapAccountVersion – An account object parameter for internal use.
  • Status – The current status of the user account.
  • On error, a non-nil object that contains an error message.
Example:
{
  "AccountId": "oaccount~cc301bee057f14236a97d434909ec1084970921b008f6baab09c2a0f5f419a9a",
  "AssetType": "oaccount",
  "BapAccountVersion": 0,
  "NoOfNfts": 0,
  "OrgId": "appdev",
  "Status": "active",
  "TokenType": "nonfungible",
  "UserId": "idcqa"
}
GetAccountByUser
This method returns 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.ERC721Account.GetAccountByUser(orgId, userId) (ERC721Account, 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 the following properties:
  • AccountId – The ID of the user account.
  • UserId – The user name or email ID of the user.
  • OrgId – The membership service provider (MSP) ID of the user in the current organization.
  • TokenType – The type of token that the account holds.
  • NoOfNfts – The total number of NFTs held by the account.
  • On error, a non-nil object that contains an error message.
Example:
{
    "AssetType": "oaccount",
    "AccountId": "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d",
    "BapAccountVersion" : 0,
    "UserId": "admin",
    "OrgId": "Org1MSP",
    "TokenType": "nonfungible",
    "NoOfNfts": 0
}
BalanceOf
This method returns the total number of NFTs the specified user holds.
Ctx.ERC721Account.BalanceOf(accountId string) (interface{}, error)
Parameters:
  • accountId: string – The account ID of the user.
Returns:
  • On success, an interface with a message and the total number of NFTs. On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Account.BalanceOf(accountId)

{"TotalNfts": 0}

Methods for Role Management

AddRoleMember
This method adds a role to a specified user.
Ctx.ERC721Token.AddRoleMember(role string, accountId string) (interface{}, error)
Parameters:
  • role: string – The name of the role to add to the specified user. The mintable and burnable behaviors correspond to the minter_role_name and burner_role_name properties of the specification file.
  • accountId: number – The account ID to operate on.
Returns:
  • On success, a map with a success message. On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Token.AddRoleMember(userRole, accountId)

{"msg": "Successfully added role minter to oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (orgId : Org1MSP, userId : admin)"}
RemoveRoleMember
This method removes a role from a specified user and token. An account ID is formed by creating an SHA-256 hash of the concatenated membership service provider ID (orgId) and the user name or email ID (userId).
Ctx.Token.RemoveRoleMember(role string, accountId string) (interface{}, error)
Parameters:
  • role: string – The name of the role to remove from the specified user. The mintable and burnable behaviors correspond to the minter_role_name and burner_role_name properties of the specification file.
  • accountId: number – The account ID to operate on.
Returns:
  • On success, a map with a success message. On error, a non-nil object containing an error message.
Example:

t.Ctx.ERC721Token.RemoveRoleMember(userRole, accountId)

{"msg": "successfully removed memberId oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (orgId : Org1MSP, userId : admin) from role minter"}
IsInRole
This method returns a Boolean value to indicate if a user and token has a specified role. An account ID is formed by creating an SHA-256 hash of the concatenated membership service provider ID (orgId) and the user name or email ID (userId).
Ctx.ERC721Token.IsInRole(role string, accountId string) (bool, error)
Parameters:
  • role: string – The name of the role to check for the specified user. The mintable and burnable behaviors correspond to the minter_role_name and burner_role_name properties of the specification file.
  • accountId: number – The account ID to operate on.
Returns:
  • On success, a Boolean value that is true if the role is present for the specified account ID, otherwise false. On error, a non-nil object containing an error message
Example:

t.Ctx.ERC721Token.IsInRole(userRole, accountId)

{"result": false}
GetAccountsByRole
This method returns a list of all account IDs for a specified role.
Ctx.ERC721Role.GetAccountsByRole(roleName string) (interface{}, error)
Parameters:
  • roleName: string – The name of the role to search for.
Returns:
  • On success, a JSON array of account IDs. On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Role.GetAccountsByRole(userRole)

{
    "accounts": [
        "oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d"
    ]
}
GetUsersByRole
This method returns a list of all users for a specified role.
Ctx.ERC721Role.GetUsersByRole(roleName string) (interface{}, error)
Parameters:
  • roleName: string – The name of the role to search for.
Returns:
  • On success, a JSON array of user objects. Each object contains the user ID and organization ID. On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Role.GetUsersByRole(userRole)

{
    "Users": [
        {
            "OrgId": "Org1MSP",
            "UserId": "admin"
        }
    ]
}

Methods for Transaction History Management

GetAccountTransactionHistory
This method returns an array of the transaction history details for a specified account.
Ctx.ERC721Account.GetAccountTransactionHistory(accountId string) (interface{}, error)
Parameters:
  • accountId: string – The ID of the account.
Returns:
  • On success, an array of account transaction objects in JSON format:
    • TransactionId – The ID of the transaction.
    • TransactedAccount – The account with which the transaction took place.
    • TransactionType – The type of transaction.
    • Timestamp – The time of the transaction.
    • On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Account.GetAccountTransactionHistory(accountId)

[
     {
        "Timestamp": "2022-04-06T08:31:39Z",
        "TokenId": "monalisa",
        "TransactedAccount": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
        "TransactionId": "otransaction~5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7",
        "TransactionType": "DEBIT"
    }
    {
        "Timestamp": "2022-04-06T08:16:53Z",
        "TokenId": "monalisa",
        "TransactedAccount": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
        "TransactionId": "otransaction~750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7",
        "TransactionType": "MINT"
    }
]
GetAccountTransactionHistoryWithFilters
This method returns account transaction history for a specified user, filtered by PageSize, Bookmark, startTime and endTime. This method can only be called when connected to the remote Oracle Blockchain Platform network.
Ctx.ERC721Account.GetAccountTransactionHistoryWithFilters(accountId string, filters ...erc721Account.AccountHistoryFilters)
Parameters:
  • accountId: string – ID of the account.
  • filters: string – An optional parameter. If empty, all records are returned. The PageSize property determines the number of records to return. If PageSize is 0, the default page size is 20. The Bookmark property determines the starting index of the records to return. For more information, see the Hyperledger Fabric documentation. The StartTime and EndTime properties must be specified in RFC-3339 format.
Returns:
  • On success, an array of account transaction objects in JSON format:
    • TransactionId – The ID of the transaction.
    • TransactedAccount – The account with which the transaction took place.
    • TransactionType – The type of transaction.
    • Timestamp – The time of the transaction.
    • On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Account.GetAccountTransactionHistoryWithFilters(accountId, filters...)

[
     {
        "Timestamp": "2022-04-06T08:31:39Z",
        "TokenId": "monalisa",
        "TransactedAccount": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
        "TransactionId": "otransaction~5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7",
        "TransactionType": "DEBIT"
    }
    {
        "Timestamp": "2022-04-06T08:16:53Z",
        "TokenId": "monalisa",
        "TransactedAccount": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
        "TransactionId": "otransaction~750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7",
        "TransactionType": "MINT"
    }
]
GetTransactionById
This method returns the history of a Transaction asset.
Ctx.ERC721Transaction.GetTransactionById(trxId string) (interface{}, error)
Parameters:
  • trxId: string – The ID of the transaction asset.
Returns:
  • On success, an array of maps of transaction assets. On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Transaction.GetTransactionById(transactionId)

{
    "History": [
        {
            "IsDelete": "false",
            "Timestamp": "2022-04-06T08:31:39Z",
            "TxId": "5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7",
            "Value": {
                "AssetType": "otransaction",
                "Data": "",
                "FromAccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1",
                "Timestamp": "2022-04-06T08:31:39Z",
                "ToAccountId": "oaccount~0829f0996744ca9dc8b4e9165a7a8f5db3fdffdc46c96b94f5d625041502cec4",
                "TokenId": "monalisa",
                "TransactionId": "otransaction~5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7",
                "TransactionType": "TRANSFER",
                "TriggeredByAccountId": "oaccount~543c2258e351c3e7a40ea59b81e62154d38fbfc9d1b5b79f30ac5e08e7d0dfd1"
            }
        }
    ],
    "TransactionId": "otransaction~5a353e02e657c2c8fddce41dd4e7260025fe7beef634ca3351fc366a440e8ac7"
}
DeleteHistoricalTransactions
This method deletes transactions that are older than a specified date from the state database.
func (t *Controller) DeleteHistoricalTransactions(referenceTime string) (interface{}, error)
Parameters:
  • referenceTime: string – Transactions older than the specified time will be deleted.
Returns:
  • On success, an array of the deleted transaction IDs and a success message. On error, a non-nil error object that contains an error message.
Example:

t.Ctx.ERC721Transaction.DeleteHistoricalTransactions(timestamp)

{
    "Transactions": [
        "otransaction~750f68538451847f57948f7d5261dcb81570cd9e429f928a4cb7bfa76392ecf7"
    ],
    "msg": "Successfuly deleted transaction older than date:2022-04-06T08:17:53Z"
}

Token Behavior Management - Mintable Behavior

GetMaxMintQuantity
This method returns the maximum mintable quantity of a token. If the max_mint_quantity behavior is not configured in the specification file, then the default value is 0 and an infinite number of tokens can be minted.
Ctx.ERC721Token.GetMaxMintQuantity(id string) (float64, error)
Parameters:
  • id – The ID of the token to operate on.
Returns:
  • On success, the maximum mintable quantity of the token, in the number data type. On error, a non-nil object with an error message.
Example:

t.Ctx.ERC721Token.GetMaxMintQuantity(tokenId);

20000
GetTotalMintedTokens
This method returns the total net number of tokens available in the system for the specified token. The net number of tokens available is the total number of minted tokens minus the number of burned tokens.
Ctx.ERC721Token.GetTotalMintedTokens() (map[string]interface{}, error)
Parameters:
  • none
Returns:
  • On success, a map of the total minted tokens, in the number data type, and a success message. On error, a non-nil object with an error message.
Example:

t.Ctx.ERC721Token.GetTotalMintedTokens()

{"TotalNetSupply": 5}

Token Behavior Management - Transferable Behavior

SafeTransferFrom
This method transfers ownership of the specified NFT from the caller to another account. This method includes the following validations:
  • The token exists and is not burned.
  • The sender account and receiver account exist and are not the same account.
  • The sender account owns the token.
  • The caller of the function is the sender.
Ctx.ERC721Token.SafeTransferFrom(fromAccountId string, toAccountId string, tokenAsset interface{}, data ...string) (interface{}, error)
Parameters:
  • fromAccountId: string – The account ID of the sender in the current organization.
  • toAccountId: string – The account ID of the receiver in the current organization.
  • tokenAsset – The reference to the token asset to operate on.
  • data: string – Optional additional information to store in the transaction.
Returns:
  • On success, a promise with a success message that includes account details. On error, a non-nil object with an error message.
Example:

t.Ctx.ERC721Token.SafeTransferFrom(fromAccountId, toAccountId, tokenAssetValue.Interface(), data...)

{"msg": "Successfully transferred NFT token: 'monalisa' from Account-Id: oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (Org-Id: Org1MSP, User-Id: admin) to Account-Id: oaccount~ec32cff8635a056f3dda3da70b1d6090d61f66c6a170c4a95fd008181f729dba (Org-Id: Org1MSP, User-Id: user1"}
TransferFrom
This method transfers ownership of the specified NFT from a sender account to a receiver account. It is the responsibility of the caller to pass the correct parameters. This method can be called by any user, not only the token owner. This method includes the following validations:
  • The token exists and is not burned.
  • The sender account and receiver account exist and are not the same account.
  • The sender account owns the token.
Ctx.ERC721Token.TransferFrom(fromAccountId string, toAccountId string, tokenAsset interface{}) (interface{}, error)
Parameters:
  • fromAccountId: string – The account ID of the sender in the current organization.
  • toAccountId: string – The account ID of the receiver in the current organization.
  • tokenAsset – The reference to the token asset to operate on.
Returns:
  • On success, a promise with a success message that includes account details. Account IDs have the prefix oaccount~. On error, a non-nil object with an error message.
\Example:

t.Ctx.ERC721Token.TransferFrom(fromAccountId, toAccountId, tokenAssetValue.Interface())

{"msg": "Successfully transferred NFT token: 'monalisa' from Account-Id: oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (Org-Id: Org1MSP, User-Id: admin) to Account-Id: oaccount~ec32cff8635a056f3dda3da70b1d6090d61f66c6a170c4a95fd008181f729dba (Org-Id: Org1MSP, User-Id: user1"}

Token Behavior Management - Burnable Behavior

Burn
This method deactivates, or burns, the specified NFT from the caller's account. The caller of this method must have an account. A token cannot be burned unless the token specification file includes the burnable behavior. If no burner_role_name property is specified in the roles section of the specification file, then the owner of the token can burn the token. If a burner_role_name property is specified in the roles section, then the user assigned the burner role who is also the minter (creator) of the token can burn the token. The burn method is part of the ERC721Token package, which you access via the receiver of the Ctx struct.
Ctx.Token.Burn(tokenAsset interface{}) (interface{}, error)
Parameters:
  • tokenAsset – The reference to the token asset to operate on.
Returns:
  • On success, a promise with a success message that includes account details. On error, a non-nil object with an error message.
Example:

t.Ctx.ERC721Token.Burn(tokenAssetValue.Interface())

{"msg": "Successfully burned NFT token: 'monalisa' from Account-Id: oaccount~42e89f4c72dfde9502814876423c6da630d466e87436dd1aae201d347ad1288d (Org-Id: Org1MSP, User-Id: admin"}