Scaffolded Go Token Project for ERC-1155
Blockchain App Builder takes the input from your token specification file and generates a fully-functional scaffolded chaincode project.
The project automatically generates token lifecycle classes and functions, including CRUD and non-CRUD methods. Validation of arguments, marshalling/unmarshalling, and transparent persistence capability are all supported automatically.
For information on the scaffolded project and methods that are not directly related to tokens, see Scaffolded Go Chaincode Project.
Model
Transparent Persistence Capability, or simplified ORM,
is captured in the OchainModel
class. The following model shows a
whole non-fungible
token.
package model
type ArtCollection struct {
AssetType string `json:"AssetType" final:"otoken"`
TokenId string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
TokenName string `json:"TokenName" final:"artcollection"`
TokenDesc string `json:"TokenDesc" validate:"max=256"`
TokenStandard string `json:"TokenStandard" final:"erc1155+"`
TokenType string `json:"TokenType" final:"nonfungible" validate:"regexp=^nonfungible$"`
TokenUnit string `json:"TokenUnit" final:"whole" validate:"regexp=^whole$"`
Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":20000}"`
Behaviors []string `json:"Behaviors" final:"[\"indivisible\",\"singleton\",\"mintable\",\"transferable\",\"burnable\",\"roles\"]"`
Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`
Owner string `json:"Owner,omitempty" validate:"string"`
CreatedBy string `json:"CreatedBy,omitempty" validate:"string"`
TransferredBy string `json:"TransferredBy,omitempty" validate:"string"`
CreationDate string `json:"CreationDate,omitempty" validate:"string"`
TransferredDate string `json:"TransferredDate,omitempty" validate:"string"`
IsBurned bool `json:"IsBurned" validate:"bool"`
BurnedBy string `json:"BurnedBy,omitempty" validate:"string"`
BurnedDate string `json:"BurnedDate,omitempty" validate:"string"`
TokenUri string `json:"TokenUri" mandatory:"true" validate:"string,max=2000"`
TokenMetadata ArtCollectionMetadata `json:"TokenMetadata"`
Price int `json:"Price" validate:"int"`
On_sale_flag bool `json:"On_sale_flag" validate:"bool"`
}
type ArtCollectionMetadata struct {
Painting_name string `json:"Painting_name" validate:"string"`
Description string `json:"Description" validate:"string"`
Image string `json:"Image" validate:"string"`
Painter_name string `json:"Painter_name" validate:"string"`
}
type Loyalty struct {
AssetType string `json:"AssetType" final:"otoken"`
TokenId string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
TokenName string `json:"TokenName" final:"loyalty"`
TokenDesc string `json:"TokenDesc" validate:"max=256"`
TokenStandard string `json:"TokenStandard" final:"erc1155+"`
TokenType string `json:"TokenType" final:"fungible" validate:"regexp=^fungible$"`
TokenUnit string `json:"TokenUnit" final:"fractional" validate:"regexp=^fractional$"`
Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":10000}"`
Divisible map[string]interface{} `json:"Divisible" final:"{\"Decimal\":2}"`
Behaviors []string `json:"Behaviors" final:"[\"divisible\",\"mintable\",\"transferable\",\"burnable\",\"roles\"]"`
Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`
Currency_name string `json:"Currency_name" validate:"string"`
Token_to_currency_ratio int `json:"Token_to_currency_ratio" validate:"int"`
Metadata interface{} `json:"Metadata,omitempty"`
}
The
following model shows a fractional non-fungible
token.type RealEstateProperty struct {
AssetType string `json:"AssetType" final:"otoken"`
TokenId string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
TokenName string `json:"TokenName" final:"realestateproperty"`
TokenDesc string `json:"TokenDesc" validate:"max=256"`
TokenStandard string `json:"TokenStandard" final:"erc1155+"`
TokenType string `json:"TokenType" final:"nonfungible" validate:"regexp=^nonfungible$"`
TokenUnit string `json:"TokenUnit" final:"fractional" validate:"regexp=^fractional$"`
Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":0}"`
Behaviors []string `json:"Behaviors" final:"[\"divisible\",\"mintable\",\"transferable\",\"roles\"]"`
Divisible map[string]interface{} `json:"Divisible" final:"{\"Decimal\":0}"`
Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`
CreatedBy string `json:"CreatedBy,omitempty" validate:"string"`
CreationDate string `json:"CreationDate,omitempty" validate:"string"`
IsBurned bool `json:"IsBurned" validate:"bool"`
TokenUri string `json:"TokenUri" mandatory:"true" validate:"string,max=2000"`
Quantity float64 `json:"Quantity,omitempty"`
TokenMetadata RealEstatePropertyMetadata `json:"TokenMetadata"`
PropertySellingPrice int `json:"PropertySellingPrice" validate:"int"`
PropertyRentingPrice int `json:"PropertyRentingPrice" validate:"int"`
}
type RealEstatePropertyMetadata struct {
PropertyType string `json:"PropertyType" validate:"string"`
PropertyName string `json:"PropertyName" validate:"string"`
PropertyAddress string `json:"PropertyAddress" validate:"string"`
PropertyImage string `json:"PropertyImage" validate:"string"`
}
Controller
There is only one main controller.
type Controller struct {
Ctx trxcontext.TrxContext
}
You can create any number of classes, functions, or files, but only those methods that are defined within the main controller class are invokable. The other methods are hidden.
You can use the token SDK methods to write custom methods for your business application.
Automatically Generated Token Methods
Blockchain App Builder automatically generates methods to support tokens and token life cycles. You can use these methods to initialize tokens, manage roles and accounts, and complete other token lifecycle tasks without any additional coding. Controller methods must be public to be invokable. Public method names begin with an upper case character. Method names that begin with a lower case character are private.
- 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 theToken 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 theToken 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
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 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 the
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 the
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
the
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 the
Token Admin
of the chaincode. The specified user must have a token account that is associated with the fungible token, or a non-fungible token account for NFT roles. The specified role must exist in the specification file for the token. -
GetAccountsByRole
- This method returns a list of all account IDs for a specified
role and token. Fungible tokens are specified by the token ID. Non-fungible
tokens are specified by the token name. This method can be called only by
the
Token Admin
of the chaincode. -
GetUsersByRole
- This method returns a list of all users for a specified role and
token. Fungible tokens are specified by the token ID. Non-fungible tokens
are specified by the token name. This method can be called only by the
Token Admin
of the chaincode.
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. This method can be called only by the account owner.
Methods for Token Behavior Management - Burnable Behavior
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. Most automatically generated methods
include access control. Certain token methods can be run only by the
ERC721Admin
orAccount Owner
of the token or by aMultipleAccountOwner
for users with multiple accounts. TheCheckAuthorization
method is part of theerc721Auth
class, which you access via theCtx
object. The access control mapping is described in theoChainUtil.go
file, as shown in the following text. You can modify access control by editing theoChainUtil.go
file.var t TokenAccess var r RoleAccess var a AccountAccess var as AccountStatusAccess var h HoldAccess var ad AdminAccess var trx TransactionAccess var tc TokenConversionAccess var auth AuthAccess var erc721ad ERC721AdminAccess var erc721t ERC721TokenAccess var erc721r ERC721RoleAccess var erc721a ERC721AccountAccess var erc721as ERC721AccountStatusAccess var erc721trx ERC721TransactionAccess var erc1155ad ERC1155AdminAccess var erc1155t ERC1155TokenAccess var erc1155a ERC1155AccountAccess var erc1155as ERC1155AccountStatusAccess var erc1155trx ERC1155TransactionAccess var erc1155role ERC1155RoleAccess trx.DeleteHistoricalTransactions = []string{"Admin"} ad.AddAdmin = []string{"Admin"} ad.RemoveAdmin = []string{"Admin"} ad.GetAllAdmins = []string{"Admin", "OrgAdmin"} ad.AddOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"} ad.RemoveOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"} ad.GetOrgAdmins = []string{"Admin", "OrgAdmin"} ad.IsTokenAdmin = []string{"Admin", "MultipleAccountOwner", "OrgAdmin"} t.Save = []string{"Admin"} t.GetAllTokens = []string{"Admin", "OrgAdmin"} t.Update = []string{"Admin"} t.GetTokenDecimals = []string{"Admin", "OrgAdmin"} t.GetTokensByName = []string{"Admin", "OrgAdmin"} t.AddRoleMember = []string{"Admin", "OrgAdminRoleCheck"} t.RemoveRoleMember = []string{"Admin", "OrgAdminRoleCheck"} t.IsInRole = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} t.GetTotalMintedTokens = []string{"Admin", "OrgAdmin"} t.GetNetTokens = []string{"Admin", "OrgAdmin"} t.Get = []string{"Admin", "OrgAdmin"} t.GetTokenHistory = []string{"Admin", "OrgAdmin"} a.CreateAccount = []string{"Admin", "OrgAdminOrgIdCheck"} a.AssociateToken = []string{"Admin", "OrgAdminAccountIdCheck"} a.GetAllAccounts = []string{"Admin"} a.GetAllOrgAccounts = []string{"Admin", "OrgAdminOrgIdCheck"} a.GetAccount = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.History = []string{"Admin", "AccountOwner"} a.GetAccountTransactionHistory = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetSubTransactionsById = []string{"Admin", "TransactionInvoker"} a.GetSubTransactionsByIdWithFilters = []string{"Admin", "TransactionInvoker"} a.GetAccountBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetAccountOnHoldBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetOnHoldIds = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetAccountsByUser = []string{"Admin", "OrgAdminOrgIdCheck", "MultipleAccountOwner"} as.Get = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} as.ActivateAccount = []string{"Admin", "OrgAdminOrgIdCheck"} as.SuspendAccount = []string{"Admin", "OrgAdminOrgIdCheck"} as.DeleteAccount = []string{"Admin", "OrgAdminOrgIdCheck"} r.GetAccountsByRole = []string{"Admin"} r.GetUsersByRole = []string{"Admin"} r.GetOrgAccountsByRole = []string{"Admin", "OrgAdminOrgIdCheck"} r.GetOrgUsersByRole = []string{"Admin", "OrgAdminOrgIdCheck"} tc.InitializeExchangePoolUser = []string{"Admin"} tc.AddConversionRate = []string{"Admin"} tc.UpdateConversionRate = []string{"Admin"} tc.GetConversionRate = []string{"Admin", "OrgAdmin", "AnyAccountOwner"} tc.GetConversionRateHistory = []string{"Admin", "OrgAdmin", "AnyAccountOwner"} tc.TokenConversion = []string{"Admin", "AnyAccountOwner"} tc.GetExchangePoolUser = []string{"Admin"} erc721ad.AddAdmin = []string{"Admin"} erc721ad.GetAllAdmins = []string{"Admin"} erc721ad.IsTokenAdmin = []string{"Admin"} erc721ad.RemoveAdmin = []string{"Admin"} erc721trx.DeleteHistoricalTransactions = []string{"Admin"} erc721t.Save = []string{"Admin"} erc721t.GetAllTokens = []string{"Admin"} erc721t.Update = []string{"Admin"} erc721t.GetTokensByName = []string{"Admin"} erc721t.AddRoleMember = []string{"Admin"} erc721t.RemoveRoleMember = []string{"Admin"} erc721t.IsInRole = []string{"Admin", "AccountOwner"} erc721t.Get = []string{"Admin", "TokenOwner"} erc721t.GetAllTokensByUser = []string{"Admin", "AccountOwner"} erc721t.TotalSupply = []string{"Admin"} erc721t.TotalNetSupply = []string{"Admin"} erc721t.History = []string{"Admin"} erc721a.CreateAccount = []string{"Admin"} erc721a.CreateUserAccount = []string{"Admin"} erc721a.CreateTokenAccount = []string{"Admin"} erc721a.AssociateFungibleTokenToAccount = []string{"Admin", "AccountOwner"} erc721a.GetAllAccounts = []string{"Admin"} erc721a.History = []string{"Admin", "AccountOwner"} erc721a.GetAccountTransactionHistory = []string{"Admin", "AccountOwner"} erc721a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "AccountOwner"} erc721a.GetAccountByUser = []string{"Admin", "MultipleAccountOwner"} erc721a.BalanceOf = []string{"Admin", "MultipleAccountOwner"} erc721as.Get = []string{"Admin", "AccountOwner"} erc721as.ActivateAccount = []string{"Admin"} erc721as.SuspendAccount = []string{"Admin"} erc721as.DeleteAccount = []string{"Admin"} erc721r.GetAccountsByRole = []string{"Admin"} erc721r.GetUsersByRole = []string{"Admin"} erc1155ad.AddAdmin = []string{"Admin"} erc1155ad.GetAllAdmins = []string{"Admin"} erc1155ad.IsUserTokenAdmin = []string{"Admin"} erc1155ad.RemoveAdmin = []string{"Admin"} erc1155t.AddRoleMember = []string{"Admin"} erc1155t.IsInRole = []string{"Admin"} erc1155t.GetAllTokens = []string{"Admin"} erc1155t.GetAllTokensByUser = []string{"Admin", "AccountOwner"} erc1155t.Get = []string{"Admin", "TokenOwner"} erc1155t.RemoveRoleMember = []string{"Admin"} erc1155t.TotalNetSupply = []string{"Admin"} erc1155t.TotalSupply = []string{"Admin"} erc1155t.GetTokenDecimal = []string{"Admin"} erc1155t.GetTokensByName = []string{"Admin"} erc1155t.GetTotalMintedTokens = []string{"Admin"} erc1155t.GetNetTokens = []string{"Admin"} erc1155t.Save = []string{"Admin"} erc1155t.Update = []string{"Admin"} erc1155trx.DeleteHistoricalTransactions = []string{"Admin"} erc1155role.GetAccountsByRole = []string{"Admin"} erc1155role.GetUsersByRole = []string{"Admin"} erc1155a.AssociateFungibleTokenToAccount = []string{"Admin", "AccountOwner"} erc1155a.BalanceOfBatch = []string{"Admin"} erc1155a.CreateAccount = []string{"Admin"} erc1155a.CreateTokenAccount = []string{"Admin"} erc1155a.CreateUserAccount = []string{"Admin"} erc1155a.GetAccountTransactionHistory = []string{"Admin", "AccountOwner"} erc1155a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "AccountOwner"} erc1155a.GetAccountsByUser = []string{"Admin", "AccountOwner"} erc1155a.GetAccount = []string{"Admin", "AccountOwner"} erc1155a.History = []string{"Admin", "AccountOwner"} erc1155a.GetAllAccounts = []string{"Admin"} erc1155a.ExchangeToken = []string{"AccountOwner"} erc1155a.GetAccountDetailsByUser = []string{"Admin", "AccountOwner"} erc1155as.Get = []string{"Admin", "AccountOwner"} erc1155as.ActivateAccount = []string{"Admin"} erc1155as.SuspendAccount = []string{"Admin"} erc1155as.DeleteAccount = []string{"Admin"} var accessMap TokenAccessControl accessMap.Token = t accessMap.Account = a accessMap.AccountStatus = as accessMap.Hold = h accessMap.Role = r accessMap.Admin = ad accessMap.Auth = auth accessMap.TokenConversion = tc accessMap.ERC721ADMIN = erc721ad accessMap.ERC721TOKEN = erc721t accessMap.ERC721ACCOUNT = erc721a accessMap.ERC721AccountStatus = erc721as accessMap.ERC721ROLE = erc721r accessMap.ERC721TRANSACTION = erc721trx accessMap.ERC1155Account = erc1155a accessMap.ERC1155AccountStatus = erc1155as accessMap.ERC1155Admin = erc1155ad accessMap.ERC1155Token = erc1155t accessMap.ERC1155Transaction = erc1155trx accessMap.ERC1155Role = erc1155role
-
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
. -
GetAllAdminUsers
- 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. For fractional NFTs, the list of owners is also returned. -
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 for a specified user,
including account status. 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.
-
DeleteHistoricalTransactions
- 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