Scaffolded TypeScript Project for Token Taxonomy Framework
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 Token
class,
which in turn extends the OchainModel
class. The
Token
class is imported from ../lib/token
.
Transparent Persistence Capability, or simplified ORM, is captured in the
OchainModel
class.
import * as yup from 'yup';
import { Id, Mandatory, Validate, ReadOnly } from '../lib/decorators';
import { Token } from '../lib/token';
@Id('token_id')
export class Digicur extends Token<Digicur> {
public readonly assetType = 'otoken';
@Mandatory()
@Validate(yup.string().required().matches(/^[A-Za-z0-9][A-Za-z0-9_-]*$/).max(16))
public token_id: string;
@ReadOnly('digicur')
public token_name: string;
@Validate(yup.string().trim().max(256))
public token_desc: string;
@ReadOnly('fungible')
public token_type: string;
@ReadOnly(["divisible","mintable","transferable","burnable","holdable","roles"])
public behaviors: string[];
@ReadOnly({minter_role_name: "minter", burner_role_name: "burner", notary_role_name: "notary"})
public roles: object;
@ReadOnly({max_mint_quantity: 20000})
public mintable: object;
@ReadOnly({decimal: 1})
public divisible: object;
@Validate(yup.number())
public token_to_currency_ratio: number;
@Validate(yup.string())
public currency_representation: string;
}
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
-
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. -
isTokenAdmin
- This method returns the Boolean value
true
if the caller of the function is aToken Admin
, otherwise it returnsfalse
. AToken Admin
orOrg Admin
can call this function on any other user in the blockchain network. Other users can call this method only on their own accounts. -
getAllTokenAdmins
- This method returns a list of all users who are a
Token Admin
of the chaincode. This method can be called only by theToken Admin
or anyOrg Admin
of the chaincode. -
addOrgAdmin
- This method adds a user as an
Org Admin
of the organization. This method can be called only by aToken Admin
of the chaincode or anOrg Admin
of the specified organization. -
removeOrgAdmin
- This method removes a user as an
Org Admin
of the organization. This method can be called only by aToken Admin
of the chaincode or by anOrg Admin
of the specified organization. -
getOrgAdmins
- This method returns a list of all users who are an
Org Admin
of an organization. This method can be called only by aToken Admin
of the chaincode or by anOrg Admin
of any organization.
Methods for Token Configuration Management
-
init
- This method is called when the chaincode is deployed or
upgraded. Every
Token Admin
is identified by theuser_id
andorg_id
information in the mandatoryadminList
parameter. Theuser_id
is the user name or email ID of the instance owner or the user who is logged in to the instance. Theorg_id
is the membership service provider (MSP) ID of the user in the current network organization. -
initialize<Token Name>Token
- This method creates a token and initializes the token
properties. The asset and its properties are saved in the state database.
This method can be invoked only by a
Token Admin
of the chaincode. -
update<Token Name>Token
- This method updates token properties. After a token asset is
created, only the
token_desc
property and custom properties can be updated. This method can be called only by aToken Admin
of the chaincode. -
getTokenDecimals
- This method returns the number of decimal places that were
configured for a fractional token. If the
divisible
behavior was not specified for the token, then the default value is 0. This method can be called only by aToken Admin
orOrg Admin
of the chaincode. -
getTokenById
- This method returns a token object if it is present in the state
database. This method can be called only by a
Token Admin
or anOrg Admin
of the chaincode. -
getTokenHistory
- This method returns the token history for a specified token ID. Any user can call this method.
-
getAllTokens
- This method returns all tokens that are stored in the state
database. This method can be called only by a
Token Admin
or anOrg 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. -
getTokensByName
- This method returns all token objects with a specified name.
This method can be called only by a
Token Admin
orOrg 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.
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 balances, on-hold balances, and transaction history. An
account ID is an alphanumeric set of characters, prefixed with
oaccount~<token asset name>~
and followed by a hash of the user name or email ID (user_id
) of the instance owner or the user who is logged in to the instance, the membership service provider ID (org_id
) of the user in the current network organization. This method can be called only by aToken Admin
of the chaincode or by anOrg Admin
of the specified organization. -
associateTokenToAccount
- This method associates a fungible token with an account. This
method can be called only by a
Token Admin
of the chaincode or by anOrg Admin
of the relevant organization. -
getAccount
- This method returns account details for a specified user and
token. This method can be called only by a
Token Admin
of the chaincode, anOrg Admin
of the specified organization, or theAccountOwner
of the account. -
getAccountHistory
- This method returns account history details for a specified user
and token. This method can be called only by a
Token Admin
of the chaincode or theAccountOwner
of the account. -
getAccountOnHoldBalance
- This method returns the current on-hold balance for a specified
account and token. This method can be called only by a
Token Admin
of the chaincode, anOrg Admin
of the specified organization, or theAccountOwner
of the account. -
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. -
getUserByAccountId
- This method returns user details (
org_id
anduser_id
) for a specified account. This method can be called by any user of the chaincode. -
getAccountBalance
- This method returns the current balance for a specified account
and token. This method can be called only by a
Token Admin
of the chaincode, anOrg Admin
of the specified organization, or theAccountOwner
of the account. -
getAllOrgAccounts
- This method returns a list of all token accounts that belong to
a specified organization. This method can be called only by a
Token Admin
of the chaincode or by anOrg Admin
of the specified organization.
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 or by anOrg Admin
of the specified organization who also holds the specified role. -
removeRole
- This method removes a role from a specified user and token. This
method can be called only by a
Token Admin
of the chaincode or by anOrg Admin
of the specified organization who also holds the specified role. -
getAccountsByRole
- This method returns a list of all account IDs for a specified
role and token. This method can be called only by a
Token Admin
of the chaincode. -
getAccountsByUser
- This method returns a list of all account IDs for a specified
organization ID and user ID. This method can be called only by the
Token Admin
of the chaincode, by theOrg Admin
of the specified organization, or by theAccount Owner
specified in the parameters. -
getUsersByRole
- This method returns a list of all users for a specified role and
token. This method can be called only by a
Token Admin
of the chaincode. -
isInRole
- This method returns a Boolean value to indicate if a user and
token has a specified role. This method can be called only by a
Token Admin
of the chaincode, theAccountOwner
of the account, or anOrg Admin
of the specified organization. -
getOrgAccountsByRole
- This method returns information about all accounts that have a
specified role in a specified organization. This method can be called only
by a
Token Admin
of the chaincode or by anOrg Admin
of the specified organization. -
getOrgUsersByRole
- This method returns information about all users that have a
specified role in a specified organization. This method can be called only
by a
Token Admin
of the chaincode or by anOrg Admin
of the specified organization.
Methods for Transaction History Management
-
getAccountTransactionHistory
- This method returns an array of account transaction history
details for a specified user and token. This method can be called only by
the
Token Admin
of the chaincode, anOrg Admin
of the specified organization, or theAccountOwner
of the account. -
getAccountTransactionHistoryWithFilters
- This method returns an array of account transaction history
details for a specified user and token. This method can be called only by
the
Token Admin
of the chaincode, anOrg Admin
of the specified organization, or theAccountOwner
of the account. This method can only be called when connected to the remote Oracle Blockchain Platform network. -
getSubTransactionById
- This method returns an array of account transaction history
details for a specified user and token. This method can be called only by
the
Token Admin
of the chaincode or theAccountOwner
of the account. -
getSubTransactionsByIdWithFilters
- This method returns an array of account subtransaction history details for a specified transaction.
-
getTransactionById
- This method returns the history of a
Transaction
asset. -
deleteHistoricalTransactions
- This method deletes older transactions from the state database.
Methods for Token Behavior Management - Mintable Behavior
-
issueTokens
- This method mints tokens, which are then owned by the caller of
the method. The caller must have an account and the minter role. The number
of tokens that can be minted is limited by the
max_mint_quantity
property ofmintable
behavior in the specification file. If themax_mint_quantity
property is not specified, an unlimited number of tokens can be minted. The quantity must be within the decimal values specified by thedecimal
parameter of thedivisible
behavior in the specification file. This method can be called only by theAccountOwner
of the account with the minter role. -
getTotalMintedTokens
- This method returns the total number of minted tokens for a
specified token. This method can be called only by a
Token Admin
or anyOrg Admin
of the chaincode. -
getNetTokens
- This method returns the total net number of tokens available in
the system for a specified token. The net token total is the amount of
tokens remaining after tokens are burned. In equation form: net tokens =
total minted tokens - total burned tokens. If no tokens are burned, then the
number of net tokens is equal to the total minted tokens. This method can be
called only by a
Token Admin
or anyOrg Admin
of the chaincode.
Methods for Token Behavior Management - Transferable Behavior
-
transferTokens
- This method transfers tokens from the caller to a specified
account. The caller of the method must have an account. The quantity must be
within the decimal values specified by the
decimal
parameter of thedivisible
behavior in the specification file. This method can be called only by theAccountOwner
of the account. -
bulkTransferTokens
- This method is used to perform bulk transfer of tokens from the
caller account to the accounts that are specified in the
flow
object. The quantities must be within the decimal values specified by thedecimal
parameter of thedivisible
behavior in the specification file.The caller of this method must have an account already created. This method can be called only by theAccountOwner
of the account.
Methods for Token Behavior Management - Holdable Behavior
-
holdTokens
- This method creates a hold on behalf of the owner of the tokens
with the
to_account_id
account. A notary account is specified, which is responsible to either complete or release the hold. When the hold is created, the specified token balance from the payer is put on hold. A held balance cannot be transferred until the hold is either completed or released. The caller of this method must have an account already created. This method can be called only by theAccountOwner
of the account. -
executeHoldTokens
- This method completes a hold on a token. A quantity of tokens
previously held by a token owner is transferred to a receiver. If the
quantity
value is less than the actual hold value, then the remaining amount is available again to the original owner of the tokens. This method can be called only by theAccountOwner
ID with thenotary
role for the specified operation ID. The hold can only be completed by the notary. -
releaseHoldTokens
- This method releases a hold on tokens. The transfer is not
completed and all held tokens are available again to the original owner.
This method can be called by the
AccountOwner
ID with thenotary
role within the specified time limit or by the payer, payee, or notary after the specified time limit. -
getOnHoldIds
- This method returns a list of all of the holding IDs for a
specified account. This method can be called by a
Token Admin
of the chaincode, anOrg Admin
of the specified organization, or theAccountOwner
of the account. -
getOnHoldDetailsWithOperationId
- This method returns the on-hold transaction details for a specified operation ID and token. This method can be invoked by anyone.
-
getOnHoldBalanceWithOperationId
- This method returns the on-hold balance for a specified operation ID and token. This method can be invoked by anyone.
Methods for Token Behavior Management - Burnable Behavior
-
burnTokens
- This method deactivates, or burns, tokens from the transaction
caller's account. The caller of this method must have an account and the
burner role. The quantity must be within the decimal values specified by the
decimal
parameter of thedivisible
behavior in the specification file. This method can be called by theAccountOwner
of the account with the burner role.
Custom Methods
You can use the token SDK methods to write custom methods for your business application.
To avoid double-spending, do not combine multiple async functions that
operate on the same key-value pairs in the state database. Instead, use the
bulkTransferTokens
method to make multiple transfers in one
method.
The following example shows how to use token SDK methods in custom
methods. When the buyTicket
method is called, it transfers 20
tokens from the caller's account to the seller's account, and returns the
transaction message of the transfer.
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string())
public async buyTicket(token_id: string, seller_org_id: string, seller_user_id: string) {
const token = await this.getTokenObject(token_id);
/**
* The following method this.Ctx.Account.generateAccountId(token_id, seller_org_id, seller_user_id) generates account id of the seller.
*/
const seller_account_id = await this.Ctx.Account.generateAccountId(token_id, seller_org_id, seller_user_id);
/**
* The following method this.Ctx.Token.transfer(seller_account_id, 20, token) transfers the quantity 20 from caller's
* account & to seller's account.
*/
const transaction = await this.Ctx.Token.transfer(seller_account_id, 20, token);
return transaction;
}
If you use more than one token SDK method in a custom method, do not use methods that will affect the same key-value pairs in the state database. The following example shows the incorrect way to make multiple transfers:
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string())
public async sendTokens(token_id: string, user1_org_id: string, user1_user_id: string, user2_org_id: string, user2_user_id: string) {
const token = await this.getTokenObject(token_id);
const user1_account_id = await Account.generateAccountId(token_id, user1_org_id, user1_user_id);
const user2_account_id = await Account.generateAccountId(token_id, user2_org_id, user2_user_id);
await token.transfer(user1_account_id, 20);
await token.transfer(user2_account_id, 30);
}
Instead, use the bulkTransferTokens
method to transfer
to multiple accounts from the caller's account, as shown in the following code
snippet.
bulkTransferTokens(token_id: string, flow: object[])
Note:
If you use more than one token SDK method in a custom method that might affect the same key-value pairs in the state database, enable the MVCC optimization for token chaincodes. For more information, see MVCC Optimization.Token SDK Methods
- Access Control Management
- Token Configuration Management
- Account Management
- Role Management
- Transaction History Management
- Token Behavior Management
Methods for Access Control Management
Token Admin
, Org Admin
, or
AccountOwner
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 { Authorization } from '../lib/auth';
-
addAdmin
- This method adds a user as a
Token Admin
of the token chaincode. -
removeAdmin
- This method removes a user as a
Token Admin
of the token chaincode. -
getAllAdmins
- This method returns a list of all users who are a
Token Admin
of the token chaincode. -
checkAuthorization
- Use this method to add an access control check to an operation.
Certain token methods can be run only by a
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.export const TOKENACCESS = { ADMIN: { isUserTokenAdmin: ["Admin", "OrgAdmin"], addTokenAdmin: ["Admin"], removeTokenAdmin: ["Admin"], getAllAdmins: ["Admin", "OrgAdmin"], addOrgAdmin: ["Admin", "OrgAdminForOrgId"], removeOrgAdmin: ["Admin", "OrgAdminForOrgId"], getOrgAdmins: ["Admin", "OrgAdmin"], }, TOKEN: { save: ["Admin"], getAllTokens: ["Admin", "OrgAdmin"], get: ["Admin", "OrgAdmin"], update: ["Admin"], getDecimals: ["Admin", "OrgAdmin"], getTokensByName: ["Admin", "OrgAdmin"], addRoleMember: ["Admin", "OrgAdminRoleCheck"], removeRoleMember: ["Admin", "OrgAdminRoleCheck"], isInRole: ["Admin", "OrgAdminForAccountId", "AccountOwner"], getTotalMintedTokens: ["Admin", "OrgAdmin"], getNetTokens: ["Admin", "OrgAdmin"], getTokenHistory: ["Admin", "OrgAdmin"], }, ROLE: { getAccountsByRole: ["Admin"], getOrgAccountsByRole: ["Admin", "OrgAdminForOrgId"], getUsersByRole: ["Admin"], getOrgUsersByRole: ["Admin", "OrgAdminForOrgId"], }, TRANSACTION: { deleteTransactions: ["Admin"], },ACCOUNT: { createAccount: ["Admin", "OrgAdminForOrgId"], associateToken: ["Admin", "OrgAdminForAccountId"], getAllAccounts: ["Admin"], getAllOrgAccounts: ["Admin", "OrgAdminForOrgId"], getAccountsByUser: ["Admin", "OrgAdminForOrgId", "MultipleAccountOwner"], getAccount: ["Admin", "OrgAdminForAccountId", "AccountOwner"], history: ["Admin", "AccountOwner"], getAccountTransactionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"], getAccountTransactionHistoryWithFilters: ["Admin", "OrgAdminForAccountId", "AccountOwner"], getSubTransactionsById: ["Admin", "TransactionInvoker"], getSubTransactionsByIdWithFilters: ["Admin", "TransactionInvoker"], getAccountBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"], getAccountOnHoldBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"], getOnHoldIds: ["Admin", "OrgAdminForAccountId", "AccountOwner"], getConversionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"], }, ACCOUNT_STATUS: { get: ["Admin", "OrgAdminForAccountId", "AccountOwner"], history: ["Admin", "OrgAdminForAccountId", "AccountOwner"], activateAccount: ["Admin", "OrgAdminForOrgId"], suspendAccount: ["Admin", "OrgAdminForOrgId"], deleteAccount: ["Admin", "OrgAdminForOrgId"], }, TOKEN_CONVERSION: { initializeExchangePoolUser: ["Admin"], addConversionRate: ["Admin"], updateConversionRate: ["Admin"], getConversionRate: ["Admin", "OrgAdmin", "AnyAccountOwner"], getConversionRateHistory: ["Admin", "OrgAdmin", "AnyAccountOwner"], tokenConversion: ["Admin", "AnyAccountOwner"], getExchangePoolUser: ["Admin"], }, }
-
isUserTokenAdmin
- This method returns the Boolean value
true
if the caller of the function is aToken Admin
. Otherwise the method returnsfalse
. -
addOrgAdmin
- This method adds a user as an
Org Admin
of the organization. -
removeOrgAdmin
- This method removes a user as an
Org Admin
of the organization. -
getOrgAdmins
- This method returns a list of all users who are an
Org Admin
of an organization.
Methods for Token Configuration Management
-
getTokenDecimals
- This method returns the number of decimal places available for a
fractional token. If the
divisible
behavior is not specified, then the default value is 0. -
getAllTokens
- This method returns all the token assets 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.
-
getTokensByName
- This method returns all the token assets with the specified name. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
-
get
- This method returns a token object if it is present in the state database.
-
isTokenType
- This method indicates whether a token asset exists with the specified ID.
-
save
- This method creates a token and saves its properties in the state database.
-
update
- This method updates token properties. After a token asset is
created, you update only the
token_desc
value and its custom properties. -
getByRange
- This method calls the fabric
getStateByRange
method internally. Even though any asset with the given ID is returned from the ledger, this method casts the asset into the caller Asset type. -
history
- This method returns history for the specified token.
Methods for Account Management
-
getCallerAccountId
- This method returns the account ID of the caller.
-
generateAccountId
- This method returns an account ID, which is an alphanumeric set
of characters, prefixed with
oaccount~<token asset name>~
and followed by a hash of the user name or email ID (user_id
) of the instance owner or the user who is logged in to the instance, the membership service provider ID (org_id
) of the user in the current network organization and the unique token ID (token_id
). -
createAccount
- This method creates an account for a specified user and token.
Every user who has tokens at any point must have an account. Accounts track
a user's balance, on-hold balance, and transaction history. An account ID is
an alphanumeric set of characters, prefixed with
oaccount~<token asset name>~
and followed by a hash of the user name or email ID (user_id
) of the instance owner or the user who is logged in to the instance, the membership service provider ID (org_id
) of the user in the current network organization. This method can be called only by theToken Admin
of the chaincode or by anOrg Admin
of the specified organization. -
associateTokenToAccount
- This method associates a fungible token with an account. This
method can be called only by a
Token Admin
of the chaincode or by anOrg Admin
of the relevant organization. -
getAccountWithStatus
- This method returns account details for a specified account, including account status.
-
getAccount
- This method returns account details for a specified account.
-
history
- This method returns an array of the account history details for a specified account.
-
getAccountOnHoldBalance
- This method returns the on-hold balance for a specified account.
-
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.
-
getUserByAccountId
- This method returns the user details for a specified account.
-
getAccountBalance
- This method returns the account balance for a specified account.
-
getAllOrgAccounts
- This method returns a list of all token accounts that belong to a specified organization.
Methods for Role Management
-
addRoleMember
- This method adds a role to a specified user and token.
-
removeRoleMember
- This method removes a role from a specified user and token.
-
getAccountsByRole
- This method returns a list of all accounts for a specified role and token.
-
getAccountsByUser
- This method returns a list of all account IDs for a specified user.
-
getUsersByRole
- This method returns a list of all users for a specified role and token.
-
isInRole
- This method indicates whether a user and token has a specified role.
-
roleCheck
- This method checks if the provided account ID is a member of any role.
-
getOrgUsersByRole
- This method returns information about all users that have a specified role in a specified organization.
-
getOrgAccountsByRole
- This method returns information about all accounts that have a specified role in a specified organization.
Methods for Transaction History Management
-
getTransactionById
- This method returns the history of a
Transaction
asset. -
deleteHistoricalTransactions
- This method returns an array of the transaction history details for a specified account.
-
getAccountTransactionHistory
- This method returns an array of the transaction history details for a specified account.
-
getAccountTransactionHistoryWithFilters
- This method returns an array of the transaction history details for a specified account. This method can only be called when connected to the remote Oracle Blockchain Platform network.
-
getSubTransactionHistory
- This method returns an array of the transaction history details for a specified transaction.
-
getSubTransactionHistoryWithFilters
- This method returns an array of the subtransaction history details for a specified transaction.
Token Behavior Management
Token
class from the ../lib/token
module.
import { Token } from '../lib/token';
Methods for Token Behavior Management - Mintable Behavior
-
mint
- This method mints a quantity of tokens, which are then owned by
the caller of the method. The caller must have an account and the minter
role. The quantity must be within the decimal values specified by the
decimal
parameter of thedivisible
behavior in the specification file. -
getTotalMintedTokens
- This method returns the total number of tokens minted.
-
getNetTokens
- This method returns the net quantity of tokens that are available in the system. The net tokens are the amount of tokens remaining after tokens are burned. In equation form: net tokens = total minted tokens - total burned tokens. If no tokens are burned, then the number of net tokens is equal to the total minted tokens.
-
getMaxMintQuantity
- This method returns the maximum mintable quantity for a token.
If the
max_mint_quantity
behavior is not specified, then the default value is 0, which allows any number of tokens to be minted.
Methods for Token Behavior Management - Transferable Behavior
-
transfer
- This method transfers tokens from the transaction caller to the
to_account_id
account. The caller of this method must have an account and the quantity must be within the decimal values specified by thedecimal
parameter of thedivisible
behavior in the specification file. -
bulkTransfer
- This method is used to perform bulk transfer of tokens from the
caller account to the accounts that are specified in the
flow
object. The caller of this method must have an account already created.
Methods for Token Behavior Management - Holdable Behavior
-
hold
- This method creates a hold on behalf of the owner of the tokens
with the
to_account_id
account. A notary account is specified, which is responsible to either complete or release the hold. When the hold is created, the specified token balance from the payer is put on hold. A held balance cannot be transferred until the hold is either completed or released. The caller of this method must have an account already created. -
executeHold
- This method completes a hold on tokens, transferring the
specified quantity of tokens previously on hold to the receiver. If the
quantity
value is less than the actual hold value, then the remaining amount is available again to the original owner of the tokens. This method can be called only by theAccountOwner
ID with thenotary
role for the specified operation ID. The hold can only be completed by the notary. -
releaseHold
- This method releases a hold on tokens. The transfer is not
completed and all held tokens are available again to the original owner.
This method can be called by the
AccountOwner
ID with thenotary
role within the specified time limit or by the payer, payee, or notary after the specified time limit. -
getOnHoldIds
- This method returns a list of all of the holding IDs for a specified account.
-
getOnHoldDetailsWithOperationId
- This method returns the on-hold transaction details for a specified operation ID and token.
-
getOnHoldBalanceWithOperationId
- This method returns the on-hold balance for a specified operation ID and token. This method can be invoked by anyone.
Methods for Token Behavior Management - Burnable Behavior