Scaffolded TypeScript Token Project for ERC-1155
Blockchain App Builder takes the input from your token specification file and generates a fully-functional scaffolded chaincode project.
The project automatically generates token lifecycle classes and functions, including CRUD and non-CRUD methods. Validation of arguments, marshalling/unmarshalling, and transparent persistence capability are all supported automatically.
For information on the scaffolded project and methods that are not directly related to tokens, see Scaffolded TypeScript Chaincode Project.
Model
Every tokenized model class extends the
OchainModel
class. Transparent Persistence Capability, or
simplified ORM, is captured in the OchainModel
class. The following
model shows a whole non-fungible
token.
import * as yup from "yup";
import { Id, Mandatory, Validate, Default, Embedded, Derived, ReadOnly } from "../../lib/decorators";
import { OchainModel } from "../../lib/ochain-model";
import { STRATEGY } from "../../lib/utils";
import { EmbeddedModel } from "../../lib/ochain-embedded-model";
export class ArtCollectionMetadata extends EmbeddedModel<ArtCollectionMetadata> {
@Validate(yup.string())
public painting_name: string;
@Validate(yup.string())
public description: string;
@Validate(yup.string())
public image: string;
@Validate(yup.string())
public painter_name: string;
}
@Id("tokenId")
export class ArtCollection extends OchainModel<ArtCollection> {
public readonly assetType = "otoken";
@Mandatory()
@Validate(
yup
.string()
.required()
.matches(/^[A-Za-z0-9][A-Za-z0-9_-]*$/)
.max(16)
)
public tokenId: string;
@ReadOnly("artcollection")
public tokenName: string;
@Validate(yup.string().trim().max(256))
public tokenDesc: string;
@ReadOnly("erc1155+")
public tokenStandard: string;
@ReadOnly("nonfungible")
public tokenType: string;
@ReadOnly("whole")
public tokenUnit: string;
@ReadOnly(["indivisible","singleton","mintable","transferable","burnable","roles"])
public behaviors: string[];
@ReadOnly({ minter_role_name: "minter" })
public roles: object;
@ReadOnly({ max_mint_quantity: 20000 })
public mintable: object;
@Validate(yup.string())
public owner: string;
@Validate(yup.string())
public createdBy: string;
@Validate(yup.string())
public transferredBy: string;
@Validate(yup.string())
public creationDate: string;
@Validate(yup.string())
public transferredDate: string;
@Validate(yup.bool())
public isBurned: boolean;
@Validate(yup.string())
public burnedBy: string;
@Validate(yup.string())
public burnedDate: string;
@Mandatory()
@Validate(yup.string().required().max(2000))
public tokenUri: string;
@Embedded(ArtCollectionMetadata)
public tokenMetadata: ArtCollectionMetadata;
@Validate(yup.number())
public price: number;
@Validate(yup.boolean())
public on_sale_flag: boolean;
}
@Id("tokenId")
export class Loyalty extends OchainModel<Loyalty> {
public readonly assetType = "otoken";
@Mandatory()
@Validate(
yup
.string()
.required()
.matches(/^[A-Za-z0-9][A-Za-z0-9_-]*$/)
.max(16)
)
public tokenId: string;
@ReadOnly("loyalty")
public tokenName: string;
@Validate(yup.string().trim().max(256))
public tokenDesc: string;
@ReadOnly("erc1155+")
public tokenStandard: string;
@ReadOnly("fungible")
public tokenType: string;
@ReadOnly("fractional")
public tokenUnit: string;
@ReadOnly(["divisible","mintable","transferable","burnable","roles"])
public behaviors: string[];
@ReadOnly({ minter_role_name: "minter" })
public roles: object;
@ReadOnly({ max_mint_quantity: 10000 })
public mintable: object;
@ReadOnly({ decimal: 2 })
public divisible: object;
@Validate(yup.string())
public currency_name: string;
@Validate(yup.number())
public token_to_currency_ratio: number;
}
The
following model shows a fractional non-fungible
token.export class RealEstatePropertyMetadata extends EmbeddedModel<RealEstatePropertyMetadata> {
@Validate(yup.string())
public propertyType: string;
@Validate(yup.string())
public propertyName: string;
@Validate(yup.string())
public propertyAddress: string;
@Validate(yup.string())
public propertyImage: string;
}
@Id("tokenId")
export class RealEstateProperty extends OchainModel<RealEstateProperty> {
public readonly assetType = "otoken";
@Mandatory()
@Validate(
yup
.string()
.required()
.matches(/^[A-Za-z0-9][A-Za-z0-9_-]*$/)
.max(16)
)
public tokenId: string;
@ReadOnly("realestateproperty")
public tokenName: string;
@Validate(yup.string().trim().max(256))
public tokenDesc: string;
@ReadOnly("erc1155+")
public tokenStandard: string;
@ReadOnly("nonfungible")
public tokenType: string;
@ReadOnly("fractional")
public tokenUnit: string;
@ReadOnly(["divisible","mintable","transferable","roles"])
public behaviors: string[];
@ReadOnly({ minter_role_name: "minter" })
public roles: object;
@ReadOnly({ max_mint_quantity: 0 })
public mintable: object;
@Validate(yup.number().positive())
public quantity: number;
@Validate(yup.string())
public createdBy: string;
@Validate(yup.string())
public creationDate: string;
@ReadOnly({ decimal: 0 })
public divisible: object;
@Validate(yup.bool())
public isBurned: boolean;
@Mandatory()
@Validate(yup.string().required().max(2000))
public tokenUri: string;
@Embedded(RealEstatePropertyMetadata)
public tokenMetadata: RealEstatePropertyMetadata;
@Validate(yup.number())
public propertySellingPrice: number;
@Validate(yup.number())
public propertyRentingPrice: number;
}
Controller
The main controller class extends the OchainController
class. There is only one main controller.
export class DigiCurrCCController extends OchainController{
You can create any number of classes, functions, or files, but only those methods that are defined within the main controller class are invokable. The other methods are hidden.
You can use the token SDK methods to write custom methods for your business application.
Automatically Generated Token Methods
Blockchain App Builder automatically generates methods to support tokens
and token life cycles. You can use these methods to initialize tokens, manage roles
and accounts, and complete other token lifecycle tasks without any additional
coding. Controller methods must have a @Validator(...params)
decorator to be invokable.
- Access Control Management
- Token Configuration Management
- Account Management
- Role Management
- Transaction History Management
- Token Behavior Management
Methods for Access Control Management
-
isTokenAdmin
- This method returns the Boolean value
true
if the caller of the function is aToken Admin
, otherwise it returnsfalse
. This method can be called only by aToken Admin
of the chaincode. -
addTokenAdmin
- This method adds a user as a
Token Admin
of the chaincode. This method can be called only by aToken Admin
of the chaincode. -
removeTokenAdmin
- This method removes a user as a
Token Admin
of the chaincode. This method can be called only by aToken Admin
of the chaincode. You cannot remove yourself as aToken Admin
. -
getAllTokenAdmins
- This method returns a list of all users who are a
Token Admin
of the chaincode. This method can be called only by aToken Admin
of the chaincode.
Methods for Token Configuration Management
-
init
- This method is called when the chaincode is instantiated. Every
Token Admin
is identified by theuserId
andorgId
information in theadminList
parameter. TheuserId
is the user name or email ID of the instance owner or the user who is logged in to the instance. TheorgId
is the membership service provider (MSP) ID of the user in the current network organization. TheadminList
parameter is mandatory the first time you deploy the chaincode. If you are upgrading the chaincode, pass an empty list ([]
). If you are the user who initially deployed the chaincode, you can also specify new admins in theadminList
parameter when you are upgrading the chaincode. Any other information in theadminList
parameter is ignored during upgrades. -
create<Token Name>Token
- This method creates tokens. Every token that is defined has its
own create method. For fungible tokens, this method can be called only by a
Token Admin
of the chaincode. For non-fungible tokens, if the minter role is defined in the specification file, any user with the minter role can call this method to create an NFT. If the minter role is not defined, any user can use this method to create (mint) NFTs. The user who calls this method becomes the owner of the NFT. -
update<Token Name>Token
- This method updates tokens. Every token that is defined has its
own update method. You cannot update token metadata or the token URI of
non-fungible tokens. For fungible tokens, this method can be called only by
a
Token Admin
of the chaincode. For non-fungible tokens, this method can be called only by the token owner. -
getTokenHistory
- This method returns the history for a specified token ID. Anyone can call this method.
-
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. -
getTokenById
- This method returns a token object if the token is present in
the state database. For fractional NFTs, the list of owners is also
returned. This method can be called only by a
Token Admin
of the chaincode or the token owner. -
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. -
ownerOf
- This method returns the account ID, organization ID, and user ID of the owner of the specified token ID. Anyone can call this method.
-
URI
- This method returns the URI of a specified token. Anyone can call this method.
-
name
- This method returns the name of the token class. Anyone can call this method.
-
totalSupply
- This method returns the total number of minted tokens. Fungible
tokens are specified by the token ID. Non-fungible tokens are specified by
the token name. This method can be called only by a
Token Admin
of the chaincode. -
totalNetSupply
- This method returns the total number of minted tokens minus the
number of burned tokens. Fungible tokens are specified by the token ID.
Non-fungible tokens are specified by the token name. This method can be
called only by a
Token Admin
of the chaincode. -
getTokensByName
- This method returns all of the token assets for a specified
token name. This method uses Berkeley DB SQL rich queries and can only be
called when connected to the remote Oracle Blockchain
Platform network. This method can be called only by a
Token Admin
of the chaincode. -
getTokenDecimal
- This method returns the number of decimal places for a
specified token. This method can be called only by a
Token Admin
of the chaincode.
Methods for Account Management
-
createAccount
- This method creates an account for a specified user and
associated token accounts for fungible or non-fungible tokens. An account
must be created for any user who will have tokens at any point. The user
account tracks the NFT account and the fungible token accounts that a user
holds. Users must have accounts in the network to complete token-related
operations. This method can be called only by a
Token Admin
of the chaincode.A user account has a unique ID, which is formed by an SHA-256 hash of the
orgId
parameter and theuserId
parameter.A user can have multiple fungible token accounts with unique account IDs. Fungible token account IDs are formed by an SHA-256 hash of the
orgId
parameter, theuserId
parameter, the constant stringft
separated by the tilde symbol (~
), and a counter number that signifies the index of the fungible account that is being created separated by the tilde symbol (~
).A user can have only one non-fungible token account. Non-fungible token account IDs are unique and are formed by an SHA-256 hash of the
orgId
parameter, theuserId
parameter, and the constant stringnft
separated by the tilde symbol (~
). All non-fungible tokens that a user owns, whether whole or fractional, are linked to this account.User account IDs start with with
ouaccount~
. Token account IDs start withoaccount~
. -
createUserAccount
- This method creates an account for a specified user. An account
must be created for any user who will have tokens at any point. The user
account tracks the NFT account and the fungible token accounts that a user
has. Users must have accounts in the network to complete token-related
operations.
An account ID is an SHA-256 hash of the
orgId
parameter and theuserId
parameter. This method can be called only by aToken Admin
of the chaincode. -
createTokenAccount
- This method creates a fungible or non-fungible token account to
associate with a user account.
A user can have multiple fungible token accounts with unique account IDs. Fungible token account IDs are formed by an SHA-256 hash of the
orgId
parameter, theuserId
parameter, the constant stringft
separated by the tilde symbol (~
), and a counter number that signifies the index of the fungible account that is being created separated by the tilde symbol (~
).A user can have only one non-fungible token account. Non-fungible token account IDs are unique and are formed by an SHA-256 hash of the
orgId
parameter, theuserId
parameter, and the constant stringnft
separated by the tilde symbol (~
). All non-fungible tokens that a user owns, whether whole or fractional, are linked to this account.This method can be called only by a
Token Admin
of the chaincode. -
associateFungibleTokenAccount
- This method associates a user's fungible token account to a
particular fungible token.
This method can be called only by a
Token Admin
of the chaincode. -
getAccountHistory
- This method returns history for a specified token account. This
is an asynchronous method. This method can be called only by a
Token Admin
of the chaincode or by the account owner. -
getAccount
- This method returns token account details for a specified user.
This method can be called only by a
Token Admin
of the chaincode or theAccount Owner
of the account. -
getAllAccounts
- This method returns details of all user accounts. This method
can be called only by a
Token Admin
of the chaincode. -
getAccountDetailsByUser
- This method returns an account summary for a specified user and
details of fungible and non-fungible tokens that are associated with the
user. This method can be called only by a
Token Admin
of the chaincode or theAccount Owner
of the account. -
getUserByAccountId
- This method returns the user details of a specified account ID. This method can be called by any user.
Methods for Role Management
-
addRole
- This method adds a role to a specified user and token. This
method can be called only by a
Token Admin
of the chaincode. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name. The specified user must have a token account that is associated with the fungible token, or a non-fungible token account for NFT roles. The specified role must exist in the specification file for the token. -
isInRole
- This method returns a Boolean value to indicate if a user has a
specified role. Fungible tokens are specified by the token ID. Non-fungible
tokens are specified by the token name. This method can be called only by a
Token Admin
of the chaincode or theAccount Owner
of the account. The specified user must have a token account that is associated with the fungible token, or a non-fungible token account for NFT roles. The specified role must exist in the specification file for the token. -
removeRole
- This method removes a role from a specified user and token.
Fungible tokens are specified by the token ID. Non-fungible tokens are
specified by the token name. This method can be called only by a
Token Admin
of the chaincode. The specified user must have a token account that is associated with the fungible token, or a non-fungible token account for NFT roles. The specified role must exist in the specification file for the token. -
getAccountsByRole
- This method returns a list of all account IDs for a specified
role and token. Fungible tokens are specified by the token ID. Non-fungible
tokens are specified by the token name. This method can be called only by a
Token Admin
of the chaincode. -
getUsersByRole
- This method returns a list of all users for a specified role and
token. Fungible tokens are specified by the token ID. Non-fungible tokens
are specified by the token name. This method can be called only by a
Token Admin
of the chaincode.
Methods for Transaction History Management
-
getAccountTransactionHistory
- This method returns account transaction history. This method can
be called only by a
Token Admin
of the chaincode or by the account owner. For non-fungible tokens, this method can only be called when connected to the remote Oracle Blockchain Platform network. -
getTransactionById
- This method returns the transaction details for a specified transaction ID. Anyone can call this method.
-
deleteHistoricalTransactions
- This method deletes transactions before a specified time stamp
from the state database. This method can be called only by a
Token Admin
of the chaincode.
Methods for Token Behavior Management - Mintable Behavior
-
mintBatch
- This method creates (mints) multiple tokens in a batch
operation. This method creates only fungible tokens or fractional
non-fungible tokens.
For fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method. If not, any user can use this method to mint tokens. You cannot mint more than the
max_mint_quantity
property of the token, if that property was specified when the token was created or updated.For non-fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method. If not, any user can use this method to mint tokens. Additionally, the caller must also be the creator of the token. There is no upper limit to the quantity of fractional non-fungible tokens that can be minted.
You cannot use this method to mint a whole non-fungible token.
Methods for Token Behavior Management - Transferable Behavior
-
batchTransferFrom
- This method completes a batch operation that transfers tokens
specified in a list of token IDs from one user to another user.
For NFTs, because the method transfers ownership of the NFT, the sender of the NFT must own the token.
For fractional NFTs, if a user (including the creator of the token) transfers all of the shares that they own, then they lose ownership of the token. If any share of a token is transferred to a user, that user automatically becomes one of the owners of the fractional NFT.
This method does not validate that the caller of the method is the specified sender. This method can be called by any user.
-
safeBatchTransferFrom
- This method completes a batch operation that transfers tokens
specified in a list of token IDs from one user to another user.
For NFTs, because the method transfers ownership of the NFT, the sender of the NFT must own the token.
For fractional NFTs, if a user (including the creator of the token) transfers all of the shares that they own, then they lose ownership of the token. If any share of a token is transferred to a user, that user automatically becomes one of the owners of the fractional NFT.
The caller of the method must be the specified sender. This method can be called by any user.
-
balanceOfBatch
- This method completes a batch operation that gets the balance
of token accounts. The account details are specified in three separate lists
of organization IDs, user IDs, and token IDs. This method can be called only
by a
Token Admin
of the chaincode or by account owners. Account owners can see balance details only for accounts that they own. -
exchangeToken
- This method exchanges tokens between specified accounts. This method only supports exchanging between an NFT and a fungible token or a fungible token and an NFT. The NFT can be whole or fractional. This method can be called only by the account owner.
Methods for Token Behavior Management - Burnable Behavior
-
burnBatch
- This method deactivates, or burns, the specified fungible and non-fungible tokens. Any user with the burner role can call this method.
-
burnNFT
- This method deactivates, or burns, the specified non-fungible token, and returns a token object and token history. Any user with the burner role can call this method.
SDK Methods
- Access Control Management
- Token Configuration Management
- Account Management
- Role Management
- Transaction History Management
- Token Behavior Management
Methods for Access Control Management
-
checkAuthorization
- Use this method to add an access control check to an operation.
This is an asynchronous function. Certain token methods can be run only by
the
Token Admin
orAccountOwner
of the token or by theMultipleAccountOwner
for users with multiple accounts. The access control mapping is described in the../lib/constant.ts
file. You can modify access control by editing the../lib/constant.ts
file. To use your own access control or to disable access control, remove the access control code from the automatically generated controller methods and custom methods.ADMIN: { isUserTokenAdmin: ["Admin"], addAdmin: ["Admin"], removeAdmin: ["Admin"], getAllAdmins: ["Admin"], }, TOKEN: { save: ["Admin"], getAllTokens: ["Admin"], get: ["Admin"], update: ["Admin"], getDecimals: ["Admin"], getTokensByName: ["Admin"], addRoleMember: ["Admin"], removeRoleMember: ["Admin"], isInRole: ["Admin", "AccountOwner"], getTotalMintedTokens: ["Admin"], getNetTokens: ["Admin"], getTokenHistory: ["Admin"], }, ROLE: { getAccountsByRole: ["Admin"], getUsersByRole: ["Admin"], }, TRANSACTION: { deleteTransactions: ["Admin"], }, ACCOUNT: { createAccount: ["Admin"], associateToken: ["Admin"], getAllAccounts: ["Admin"], getAccountsByUser: ["Admin", "MultipleAccountOwner"], getAccount: ["Admin", "AccountOwner"], history: ["Admin", "AccountOwner"], getAccountTransactionHistory: ["Admin", "AccountOwner"], getAccountTransactionHistoryWithFilters: ["Admin", "AccountOwner"], getSubTransactionsById: ["Admin", TRANSACTION_INVOKER], getSubTransactionsByIdWithFilters: ["Admin", TRANSACTION_INVOKER], getAccountBalance: ["Admin", "AccountOwner"], getAccountOnHoldBalance: ["Admin", "AccountOwner"], getOnHoldIds: ["Admin", "AccountOwner"], getConversionHistory: ["Admin", "AccountOwner"], }, ACCOUNT_STATUS: { get: ["Admin", "AccountOwner"], history: ["Admin", "AccountOwner"], activateAccount: ["Admin"], suspendAccount: ["Admin"], deleteAccount: ["Admin"], }, TOKEN_CONVERSION: { initializeExchangePoolUser: ["Admin"], addConversionRate: ["Admin"], updateConversionRate: ["Admin"], getConversionRate: ["Admin", "AnyAccountOwner"], getConversionRateHistory: ["Admin", "AnyAccountOwner"], tokenConversion: ["Admin", "AnyAccountOwner"], getExchangePoolUser: ["Admin"], }, ERC721ADMIN: { isUserTokenAdmin: ["Admin"], addAdmin: ["Admin"], removeAdmin: ["Admin"], getAllAdmins: ["Admin"], }, ERC721TOKEN: { getAllTokens: ["Admin"], getAllTokensByUser: ["Admin", "AccountOwner"], get: ["Admin", TOKEN_OWNER], getTokensByName: ["Admin"], addRoleMember: ["Admin"], removeRoleMember: ["Admin"], isInRole: ["Admin", "AccountOwner"], totalSupply: ["Admin"], totalNetSupply: ["Admin"], history: ["Admin"], }, ERC721ROLE: { getAccountsByRole: ["Admin"], getUsersByRole: ["Admin"], }, ERC721TRANSACTION: { deleteTransactions: ["Admin"], }, ERC721ACCOUNT: { createAccount: ["Admin"], getAllAccounts: ["Admin"], getAccountByUser: ["Admin", "MultipleAccountOwner"], history: ["Admin", "AccountOwner"], getAccountTransactionHistory: ["Admin", "AccountOwner"], getAccountTransactionHistoryWithFilters: ["Admin", "AccountOwner"], balanceOf: ["Admin", "MultipleAccountOwner"], }, ERC1155ADMIN: { isUserTokenAdmin: ["Admin"], addAdmin: ["Admin"], removeAdmin: ["Admin"], getAllAdmins: ["Admin"], }, ERC1155TOKEN: { getAllTokens: ["Admin"], get: ["Admin", TOKEN_OWNER], getAllTokensByUser: ["Admin", "AccountOwner"], totalSupply: ["Admin"], totalNetSupply: ["Admin"], getTokensByName: ["Admin"], getDecimals: ["Admin"], addRoleMember: ["Admin"], removeRoleMember: ["Admin"], isInRole: ["Admin", "AccountOwner"], save: ["Admin"], update: ["Admin"], }, ERC1155ACCOUNT: { createAccount: ["Admin"], createUserAccount: ["Admin"], createTokenAccount: ["Admin"], associateFungibleTokenToAccount: ["Admin", "AccountOwner"], getAccountsByUser: ["Admin", "AccountOwner"], getAccount: ["Admin", "AccountOwner"], history: ["Admin", "AccountOwner"], getAllAccounts: ["Admin"], balanceOfBatch: ["Admin"], getAccountTransactionHistory: ["Admin", "AccountOwner"], getAccountTransactionHistoryWithFilters: ["Admin", "AccountOwner"], exchangeToken: ["AccountOwner"], getAccountDetailsByUser: ["Admin", "AccountOwner"], }, ERC1155ROLE: { getAccountsByRole: ["Admin"], getUsersByRole: ["Admin"], },
-
isUserTokenAdmin
- This method returns the Boolean value
true
if the specified user is aToken Admin
, andfalse
otherwise. The method can be called only by aToken Admin
of the token chaincode. -
addAdmin
- This method adds a user as a
Token Admin
of the token chaincode. The method can be called only by aToken Admin
of the token chaincode. -
removeAdmin
- This method removes a user as a
Token Admin
of the token chaincode. The method can be called only by aToken Admin
of the token chaincode. You cannot remove yourself as aToken Admin
. -
getAllAdmins
- This method returns a list of all
Token Admin
users.
Methods for Token Configuration Management
-
save
- This method creates tokens. Every token that is defined has its own create method. For non-fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method to create an NFT. If not, any user can use this method to create (mint) NFTs. The user who calls this method becomes the owner of the NFT (whole or fractional).
-
update
- This method updates tokens. You cannot update token metadata or the token URI of non-fungible tokens.
-
history (Token)
- This method returns the history for a specified token ID.
-
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. -
get (Token)
- This method returns a token object if the token is present in
the state database. This method can be called only by a
Token Admin
of the chaincode or the token owner. -
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.
-
ownerOf
- This method returns the account ID, organization ID, and user ID of the owner of the specified token ID.
-
tokenURI
- This method returns the URI of a specified token. Anyone can call this method.
-
name
- This method returns the name of the token class. Anyone can call this method.
-
totalSupply
- This method returns the total number of minted tokens. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
-
totalNetSupply
- This method returns the total number of minted tokens minus the number of burned tokens. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
-
getTokensByName
- This method returns all of the token assets for a specified token name. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
-
getDecimals
- This method returns the number of decimal places for a specified token. If the divisible behavior is not specified for the token, then the default value of zero decimal places is returned.
Methods for Account Management
-
createAccount
- This method creates an account for a specified user and
associated token accounts for fungible or non-fungible tokens. An account
must be created for any user who will have tokens at any point. The user
account tracks the NFT account and the fungible token accounts that a user
has. Users must have accounts in the network to complete token-related
operations. This method can be called only by a
Token Admin
of the chaincode.A user account has a unique ID, which is formed by an SHA-256 hash of the
orgId
parameter and theuserId
parameter.A user can have multiple fungible token accounts with unique account IDs. Fungible token account IDs are formed by an SHA-256 hash of the
orgId
parameter, theuserId
parameter, the constant stringft
separated by the tilde symbol (~
), and a counter number that signifies the index of the fungible account that is being created separated by the tilde symbol (~
).A user can have only one non-fungible token account. Non-fungible token account IDs are unique and are formed by an SHA-256 hash of the
orgId
parameter, theuserId
parameter, and the constant stringnft
separated by the tilde symbol (~
). All non-fungible tokens that a user owns, whether whole or fractional, are linked to this single non-fungible token account. -
createUserAccount
- This method creates an account for a specified user. An account
must be created for any user who will have tokens at any point. The user
account tracks the NFT account and the fungible token accounts that a user
has. Users must have accounts in the network to complete token-related
operations.
An account ID is an SHA-256 hash of the
orgId
parameter and theuserId
parameter. This method can be called only by aToken Admin
of the chaincode. -
createTokenAccount
- This method creates a fungible or non-fungible token account to
associate with a user account.
A user can have multiple fungible token accounts with unique account IDs. Fungible token account IDs are formed by an SHA-256 hash of the
orgId
parameter, theuserId
parameter, the constant stringft
separated by the tilde symbol (~
), and a counter number that signifies the index of the fungible account that is being created separated by the tilde symbol (~
).A user can have only one non-fungible token account. Non-fungible token account IDs are unique and are formed by an SHA-256 hash of the
orgId
parameter, theuserId
parameter, and the constant stringnft
separated by the tilde symbol (~
). All non-fungible tokens that a user owns, whether whole or fractional, are linked to this single non-fungible token account.This method can be called only by a
Token Admin
of the chaincode. -
associateTokenToToken
- This method associates a user's fungible token account to a particular fungible token.
-
getAccountHistory
- This method returns history for a specified token account.
-
getAccountWithStatus
- This method returns token account details, including account
status, for a specified user. This method can be called only by a
Token Admin
of the chaincode or theAccount Owner
of the account. -
getAccount
- This method returns token account details for a specified user.
This method can be called only by a
Token Admin
of the chaincode or theAccount Owner
of the account. -
getAllAccounts
- This method returns details of all user accounts.
-
getAccountDetailsByUser
- This method returns an account summary for a specified user and details of fungible and non-fungible tokens that are associated with the user..
-
getUserByAccountId
- This method returns the user details of a specified account ID.
Methods for Role Management
-
AddRoleMember
- This method adds a role to a specified user and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
-
isInRole
- This method returns a Boolean value to indicate if a user has a specified role. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
-
removeRoleMember
- This method removes a role from a specified user and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
-
getAccountsByRole
- This method returns a list of all account IDs for a specified role and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
-
getUsersByRole
- This method returns a list of all users for a specified role and token. Fungible tokens are specified by the token ID. Non-fungible tokens are specified by the token name.
Methods for Transaction History Management
-
getAccountTransactionHistory
- This method returns account transaction history. This method can
be called only by a
Token Admin
of the chaincode or by the account owner. For non-fungible tokens, this method can only be called when connected to the remote Oracle Blockchain Platform network. -
getTransactionById
- This method returns the transaction details for a specified transaction ID.
-
deleteTransactions
- This method deletes transactions before a specified time stamp from the state database.
Methods for Token Behavior Management - Mintable Behavior
-
mintBatch
- This method creates (mints) multiple tokens in a batch
operation. This method creates only fungible tokens or fractional
non-fungible tokens.
For fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method. If not, any user can use this method to mint tokens. You cannot mint more than the
max_mint_quantity
property of the token, if that property was specified when the token was created or updated.For non-fungible tokens, if the minter role is defined in the specification file, then any user with the minter role can call this method. If not, any user can use this method to mint tokens. Additionally, the caller must also be the creator of the token. There is no upper limit to the quantity of fractional non-fungible tokens that can be minted.
You cannot use this method to mint a whole non-fungible token.
Methods for Token Behavior Management - Transferable Behavior
-
batchTransferFrom
- This method completes a batch operation that transfers tokens
specified in a list of token IDs from one user to another user.
For NFTs, because the method transfers ownership of the NFT, the sender of the NFT must own the token.
For fractional NFTs, if a user (including the creator of the token) transfers all of the shares that they own, then they lose ownership of the token. If any share of a token is transferred to a user, that user automatically becomes one of the owners of the fractional NFT.
This method does not validate that the caller of the method is the specified sender.
-
safeBatchtransferFrom
- This method completes a batch operation that transfers tokens
specified in a list of token IDs from one user to another user.
For NFTs, because the method transfers ownership of the NFT, the sender of the NFT must own the token.
For fractional NFTs, if a user (including the creator of the token) transfers all of the shares that they own, then they lose ownership of the token. If any share of a token is transferred to a user, that user automatically becomes one of the owners of the fractional NFT.
The caller of the method must be the specified sender.
-
balanceOfBatch
- This method completes a batch operation that gets the balance
of token accounts. The account details are specified in three separate lists
of organization IDs, user IDs, and token IDs. This method can be called only
by a
Token Admin
of the chaincode or by account owners. Account owners can see balance details only for accounts that they own. -
exchangeToken
- This method exchanges tokens between specified accounts. This method only supports exchanging between an NFT (whole or fractional) and a fungible token or a fungible token and an NFT (whole or fractional). This method can be called only by the account owner.
Methods for Token Behavior Management - Burnable Behavior