Scaffolded Go NFT Project for ERC-721
Blockchain App Builder takes the input from your NFT specification file and generates a fully-functional scaffolded chaincode project.
The project automatically generates NFT lifecycle classes and functions, including CRUD and non-CRUD methods. Validation of arguments, marshalling/unmarshalling, and transparent persistence capability are all supported automatically.
For information on the scaffolded project and methods that are not directly related to NFTs, see Scaffolded Go Chaincode Project.
Model
Transparent Persistence Capability, or simplified ORM, is captured in the
OchainModel
class.
package model
type ArtCollection struct {
AssetType string `json:"AssetType" final:"otoken"`
TokenId string `json:"TokenId" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
TokenName string `json:"TokenName" final:"artcollection"`
TokenDesc string `json:"TokenDesc" validate:"max=256"`
Symbol string `json:"Symbol" final:"ART"`
TokenStandard string `json:"TokenStandard" final:"erc721+"`
TokenType string `json:"TokenType" final:"nonfungible" validate:"regexp=^nonfungible$"`
TokenUnit string `json:"TokenUnit" final:"whole" validate:"regexp=^whole$"`
Behavior []string `json:"Behavior" final:"[\"indivisible\",\"singleton\",\"mintable\",\"transferable\",\"burnable\",\"roles\"]"`
Roles map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\"}"`
Mintable map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":20000}"`
Owner string `json:"Owner,omitempty" validate:"string"`
CreatedBy string `json:"CreatedBy,omitempty" validate:"string"`
TransferredBy string `json:"TransferredBy,omitempty" validate:"string"`
CreationDate string `json:"CreationDate,omitempty" validate:"string"`
TransferredDate string `json:"TransferredDate,omitempty" validate:"string"`
IsBurned bool `json:"IsBurned" validate:"bool"`
BurnedBy string `json:"BurnedBy,omitempty" validate:"string"`
BurnedDate string `json:"BurnedDate,omitempty" validate:"string"`
TokenUri string `json:"TokenUri" validate:"string,max=2000"`
TokenMetadata ArtCollectionMetadata `json:"TokenMetadata"`
Price int `json:"Price" validate:"int"`
On_sale_flag bool `json:"On_sale_flag" validate:"bool"`
}
type ArtCollectionMetadata struct {
Painting_name string `json:"Painting_name" validate:"string"`
Description string `json:"Description" validate:"string"`
Image string `json:"Image" validate:"string"`
Painter_name string `json:"Painter_name" validate:"string"`
}
Controller
There is only one main controller.
type Controller struct {
Ctx trxcontext.TrxContext
}
You can create any number of classes, functions, or files, but only those methods that are defined within the main controller class are invokable. The other methods are hidden.
You can use the token SDK methods to write custom methods for your business application.
Automatically Generated NFT Methods
Blockchain App Builder automatically generates methods to support NFTs and NFT life cycles. You can use these methods to initialize NFTs, manage roles and accounts, and complete other NFT lifecycle tasks without any additional coding.
Blockchain App Builder automatically generates methods to support NFTs and NFT life cycles. You can use these methods to initialize NFTs, manage roles and accounts, and complete other NFT lifecycle tasks without any additional coding. Controller methods must be public to be invokable. Public method names begin with an upper case character. Method names that begin with a lower case character are private.
- 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. You cannot use this method to remove yourself as aToken Admin
. -
IsTokenAdmin
- This method returns the Boolean value
true
if the caller of the function is aToken Admin
, otherwise it returnsfalse
. AToken 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
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 ([]
). Any other information in theadminList
parameter is ignored during upgrades. -
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. -
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. -
GetTokenById
- This method returns a token object if the token is present in
the state database. This method can be called only by a
Token Admin
of the chaincode or the token owner. -
GetTokenHistory
- This method returns the history for a specified token ID. This method can only be called when connected to the remote Oracle Blockchain Platform network. Anyone can call this method.
-
getTokenObject
- This is a utility method that returns an instance of the token
for a specified token ID. This method is used by many of the automatically
generated methods to fetch token objects. You can call this method as needed
from your custom methods. When you create a tokenized asset or class, update
the switch case with the corresponding
Token
class to return the correct token object. Theochain sync
command in Blockchain App Builder automatically creates a switch case when a tokenized asset is created in the specification file. Because this method is private, it is not directly invokable and can only be called from other methods. -
OwnerOf
- This method returns the account ID of the owner of the specified token ID. Anyone can call this method.
-
Name
- This method returns the name of the token class. Anyone can call this method.
-
Symbol
- This method returns the symbol of the token class. Anyone can call this method.
-
TokenURI
- This method returns the URI of a specified token. Anyone can call this method.
-
TotalSupply
- This method returns the total number of minted tokens. 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. 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 token.
An account must be created for any user who will have tokens at any point.
Accounts track the number of NFTs a user has. Users must have accounts in
the network to complete token-related operations. You can create only one
NFT account per user.
An account ID is an alphanumeric set of characters, prefixed with
oaccount~
and followed by an SHA-256 hash of the membership service provider ID (OrgId
) of the user in the current network organization, the user name or email ID (UserId
) of the instance owner or the user who is logged in to the instance, and the constant stringnft
. This method can be called only by theToken Admin
of the chaincode. -
BalanceOf
- This method returns the total number of NFTs that a specified
user holds. This method can be called only by a
Token Admin
of the chaincode or by the account owner. -
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. -
GetAccountByUser
- This method returns 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. -
GetUserByAccountId
- This method returns the user details of a specified account. This method can be called by any user.
-
GetAccountHistory
- This method returns account history for a specified user. This
method can be called only by a
Token Admin
of the chaincode or by the account owner.
Methods for Role Management
-
AddRole
- This method adds a role to a specified user. This method can be
called only by a
Token Admin
of the chaincode. -
RemoveRole
- This method removes a role from a specified user. This method
can be called only by a
Token Admin
of the chaincode. -
GetAccountsByRole
- This method returns a list of all account IDs for a specified
role. This method can be called only by a
Token Admin
of the chaincode. -
GetUsersByRole
- This method returns a list of all users for a specified role.
This method can be called only by a
Token Admin
of the chaincode. -
IsInRole
- This method returns a Boolean value to indicate if a user has a
specified role. This method can be called only by a
Token Admin
of the chaincode or theAccount Owner
of the account.
Methods for Transaction History Management
-
GetAccountTransactionHistory
- This method returns account transaction history for a specified
user. This method can be called by the
Token Admin
of the chaincode or the owner of the account. -
GetAccountTransactionHistoryWithFilters
- This method returns account transaction history for a specified
user, filtered by
PageSize
,Bookmark
,StartTime
andEndTime
. This method can only be called when connected to the remote Oracle Blockchain Platform network. This method can be called only by aToken Admin
of the chaincode or by the account owner. -
GetTransactionById
- This method returns transaction history for a specified
transaction ID. This method can be called only by a
Token Admin
of the chaincode or by the account owner. -
DeleteHistoricalTransactions
- This method deletes transactions older than a specified time
stamp in the state database. This method can be called only by the
Token Admin
of the chaincode.
Methods for Token Behavior Management - Mintable Behavior
-
Create<Token Name>Token
- This method creates (mints) an NFT. The asset and associated
properties are saved in the state database. The caller of this transaction
must have a token account. The caller of this transaction becomes the owner
of the NFT. If the token specification file includes the
roles
section forbehaviors
and theminter_role_name
property forroles
, then the caller of the transaction must have the minter role. Otherwise, any caller can mint NFTs. -
Update<Token Name>Token
- This method updates token properties. This method can be called
only by the user who is the owner or creator of the token. After a token
asset is created, only the token owner can update the token custom
properties.
If
the user is both token owner and creator of a token, they can also update
the
TokenDesc
property. Token metadata cannot be updated. You must pass all token properties to this method, even if you want to update only certain properties.
Methods for Token Behavior Management - Transferable Behavior
-
SafeTransferFrom
- This method transfers ownership of the specified NFT from the
caller to another account. This method includes the following
validations:
- The token exists and is not burned.
- The sender account and receiver account exist and are not the same account.
- The sender account owns the token.
- The caller of the function is the sender.
-
TransferFrom
- This method transfers ownership of the specified NFT from a
sender account to a receiver account. It is the responsibility of the
caller to pass the correct parameters. This method can be called by any
user, not only the token owner. This method includes the following
validations:
- The token exists and is not burned.
- The sender account and receiver account exist and are not the same account.
- The sender account owns the token.
Methods for Token Behavior Management - Burnable Behavior
-
Burn
- This method deactivates, or burns, the specified NFT from the
caller's account. The caller of this method must have an account. A token
cannot be burned unless the token specification file includes the
burnable
behavior. If noburner_role_name
property is specified in theroles
section of the specification file, then the owner of the token can burn the token. If aburner_role_name
property is specified in theroles
section, then the user assigned the burner role who is also the minter (creator) of the token can burn the token. -
BurnNFT
- This method deactivates, or burns, the specified NFT from the
caller's account, and returns a token object and token history. The caller
of this method must have an account. A token cannot be burned unless the
token specification file includes the
burnable
behavior. If noburner_role_name
property is specified in theroles
section of the specification file, then the owner of the token can burn the token. If aburner_role_name
property is specified in theroles
section, then the user assigned the burner role who is also the minter (creator) or owner of the token can burn the token.
Custom Methods
You can use the token SDK methods to write custom methods for your business application.
The following example shows how to use token SDK methods in custom
methods. When the Sell
method is called, it posts a token for sale
for a specified price.
func (t *Controller) Sell(tokenId string, sellingPrice int) (interface{}, error) {
var tokenAsset ArtCollection
_, err := t.Ctx.ERC721Token.Get(tokenId, &tokenAsset)
if err != nil {
return nil, err
}
/** * price is a custom asset
attribute to set the price of a non-fungible token in the
marketplace */
tokenAsset.Price = sellingPrice
/** * on_sale_flag is a
custom asset attribute that maintains non-fungible token selling status in the
marketplace */
tokenAsset.On_sale_flag = true
_, err = t.Ctx.ERC721Token.UpdateToken(tokenAsset)
if err != nil {
return nil, err
}
msg := fmt.Sprintf("Token ID : %s has been posted for selling in the marketplace", tokenId)
return msg, nil
}
NFT SDK Methods
- Access Control Management
- Token Configuration Management
- Account Management
- Role Management
- Transaction History Management
- Token Behavior Management
Methods for Access Control Management
Token Admin
or Account Owner
of
the token. You can use this feature to ensure that operations are carried out only
by the intended users. Any unauthorized access results in an error. To use the
access control function, import the Authorization
class from the
../lib/auth
module.import { ERC721Authorization } from '../lib/erc721-auth';
-
CheckAuthorization
- Use this method to add an access control check to an operation.
Most automatically generated methods include access control. Certain token
methods can be run only by an
ERC721Admin
or theAccount Owner
of the token or by theMultipleAccountOwner
for users with multiple accounts. TheCheckAuthorization
method is part of theerc721Auth
package, which you access via theCtx
struct (receiver). 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. To use your own access control or to disable access control, remove the access control code from the automatically generated controller methods and custom methods.var t TokenAccess var r RoleAccess var a AccountAccess var as AccountStatusAccess var h HoldAccess var ad AdminAccess var trx TransactionAccess var tc TokenConversionAccess var auth AuthAccess var erc721ad ERC721AdminAccess var erc721t ERC721TokenAccess var erc721r ERC721RoleAccess var erc721a ERC721AccountAccess var erc721as ERC721AccountStatusAccess var erc721trx ERC721TransactionAccess auth.IsTokenAdmin = []string{"Admin", "MultipleAccountOwner"} trx.DeleteHistoricalTransactions = []string{"Admin"} ad.AddAdmin = []string{"Admin"} ad.RemoveAdmin = []string{"Admin"} ad.GetAllAdmins = []string{"Admin", "OrgAdmin"} ad.AddOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"} ad.RemoveOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"} ad.GetOrgAdmins = []string{"Admin", "OrgAdmin"} ad.IsTokenAdmin = []string{"Admin", "MultipleAccountOwner", "OrgAdmin"} t.Save = []string{"Admin"} t.GetAllTokens = []string{"Admin", "OrgAdmin"} t.Update = []string{"Admin"} t.GetTokenDecimals = []string{"Admin", "OrgAdmin"} t.GetTokensByName = []string{"Admin", "OrgAdmin"} t.AddRoleMember = []string{"Admin", "OrgAdminRoleCheck"} t.RemoveRoleMember = []string{"Admin", "OrgAdminRoleCheck"} t.IsInRole = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} t.GetTotalMintedTokens = []string{"Admin", "OrgAdmin"} t.GetNetTokens = []string{"Admin", "OrgAdmin"} t.Get = []string{"Admin", "OrgAdmin"} t.GetTokenHistory = []string{"Admin", "OrgAdmin"} a.CreateAccount = []string{"Admin", "OrgAdminOrgIdCheck"} a.AssociateToken = []string{"Admin", "OrgAdminAccountIdCheck"} a.GetAllAccounts = []string{"Admin"} a.GetAllOrgAccounts = []string{"Admin", "OrgAdminOrgIdCheck"} a.GetAccount = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.History = []string{"Admin", "AccountOwner"} a.GetAccountTransactionHistory = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetSubTransactionsById = []string{"Admin", "TransactionInvoker"} a.GetSubTransactionsByIdWithFilters = []string{"Admin", "TransactionInvoker"} a.GetAccountBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetAccountOnHoldBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetOnHoldIds = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} a.GetAccountsByUser = []string{"Admin", "OrgAdminOrgIdCheck", "MultipleAccountOwner"} as.Get = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"} as.ActivateAccount = []string{"Admin", "OrgAdminOrgIdCheck"} as.SuspendAccount = []string{"Admin", "OrgAdminOrgIdCheck"} as.DeleteAccount = []string{"Admin", "OrgAdminOrgIdCheck"} r.GetAccountsByRole = []string{"Admin"} r.GetUsersByRole = []string{"Admin"} r.GetOrgAccountsByRole = []string{"Admin", "OrgAdminOrgIdCheck"} r.GetOrgUsersByRole = []string{"Admin", "OrgAdminOrgIdCheck"} tc.InitializeExchangePoolUser = []string{"Admin"} tc.AddConversionRate = []string{"Admin"} tc.UpdateConversionRate = []string{"Admin"} tc.GetConversionRate = []string{"Admin", "OrgAdmin", "AnyAccountOwner"} tc.GetConversionRateHistory = []string{"Admin", "OrgAdmin", "AnyAccountOwner"} tc.TokenConversion = []string{"Admin", "AnyAccountOwner"} tc.GetExchangePoolUser = []string{"Admin"} erc721ad.AddAdmin = []string{"Admin"} erc721ad.GetAllAdmins = []string{"Admin"} erc721ad.IsTokenAdmin = []string{"Admin"} erc721ad.RemoveAdmin = []string{"Admin"} erc721trx.DeleteHistoricalTransactions = []string{"Admin"} erc721t.Save = []string{"Admin"} erc721t.GetAllTokens = []string{"Admin"} erc721t.Update = []string{"Admin"} erc721t.GetTokensByName = []string{"Admin"} erc721t.AddRoleMember = []string{"Admin"} erc721t.RemoveRoleMember = []string{"Admin"} erc721t.IsInRole = []string{"Admin", "AccountOwner"} erc721t.Get = []string{"Admin", "TokenOwner"} erc721t.GetAllTokensByUser = []string{"Admin", "AccountOwner"} erc721t.TotalSupply = []string{"Admin"} erc721t.TotalNetSupply = []string{"Admin"} erc721t.History = []string{"Admin"} erc721a.CreateAccount = []string{"Admin"} erc721a.CreateUserAccount = []string{"Admin"} erc721a.CreateTokenAccount = []string{"Admin"} erc721a.AssociateFungibleTokenToAccount = []string{"Admin", "AccountOwner"} erc721a.GetAllAccounts = []string{"Admin"} erc721a.History = []string{"Admin", "AccountOwner"} erc721a.GetAccountTransactionHistory = []string{"Admin", "AccountOwner"} erc721a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "AccountOwner"} erc721a.GetAccountByUser = []string{"Admin", "MultipleAccountOwner"} erc721a.BalanceOf = []string{"Admin", "MultipleAccountOwner"} erc721as.Get = []string{"Admin", "AccountOwner"} erc721as.ActivateAccount = []string{"Admin"} erc721as.SuspendAccount = []string{"Admin"} erc721as.DeleteAccount = []string{"Admin"} erc721r.GetAccountsByRole = []string{"Admin"} erc721r.GetUsersByRole = []string{"Admin"} var accessMap TokenAccessControl accessMap.Token = t accessMap.Account = a accessMap.AccountStatus = as accessMap.Hold = h accessMap.Role = r accessMap.Admin = ad accessMap.Auth = auth accessMap.TokenConversion = tc accessMap.ERC721ADMIN = erc721ad accessMap.ERC721TOKEN = erc721t accessMap.ERC721ACCOUNT = erc721a accessMap.ERC721AccountStatus = erc721as accessMap.ERC721ROLE = erc721r accessMap.ERC721TRANSACTION = erc721trx
-
IsUserTokenAdmin
- This method returns a map with the Boolean value
true
if the caller of the function is aToken Admin
. Otherwise the method returnsfalse
. -
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
Token Admin
users. -
GetAllAdminUsers
- This method returns a list of all
Token Admin
users.
Methods for Token Configuration Management
-
CreateToken
- This method creates a token and saves its properties in the state database. This method can be called only by users with the minter role.
-
GetTokenUri
- This method returns the token URI for a specified token.
-
TokenUri
- This method returns the token URI for a specified token.
-
Symbol
- This method returns the symbol of the token class.
-
Name
- This method returns the name of the token class.
-
OwnerOf
- This method returns the account ID of the owner of a specified token.
-
TotalSupply
- This method returns the total number of minted NFTs.
-
GetAllTokens
- This method returns all of the token assets that are saved in the state database. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
-
GetAllTokensByUser
- This method returns all tokens that are owned by a specified account ID. This method uses Berkeley DB SQL rich queries and can only be called when connected to the remote Oracle Blockchain Platform network.
-
Get
- This method returns the specified token object if it is present in the state database.
-
UpdateToken
- This method updates token properties. This method can be called
only by the owner or creator of the token. After a token asset is created,
only the token owner can update the token custom properties. If the user is
both token owner and creator of a token, they can also update the
TokenDesc
property. Token metadata cannot be updated. You must pass all token properties to this method, even if you want to update only certain properties. -
History
- This method returns history for the specified token.
-
GetNewCtx
- This method returns a new
TrxContext
object. Thetrxcontext
struct holds references to all of the SDK libraries. Access the sdk methods by using only this object. Thetrxcontext
object maintains the mutual exclusivity of transaction stubs in SDK libraries when concurrent transactions are running.
Methods for Account Management
-
GenerateAccountId
- This method returns an account ID, which is formed by
concatenating the membership service provider ID (
orgId
) and the user name or email ID (userId
) and then creating a SHA-256 hash. -
CreateAccount
- This method creates an account for a specified user. An account
must be created for any user who will have tokens at any point. Accounts
track the number of NFTs a user has. Users must have accounts in the network
to complete token-related operations. You can create only one NFT account
per user.
An account ID is an alphanumeric set of characters, prefixed with
oaccount~
and followed by an SHA-256 hash of the membership service provider ID (org_id
) of the user in the current network organization, the user name or email ID (userId
) of the instance owner or the user who is logged in to the instance, and the constant stringnft
. -
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.
-
History
- This method returns an array of the account history details for a specified account.
-
GetUserByAccountId
- This method returns the user details for a specified account.
-
GetAccountWithStatusByUser
- This method returns account details for a specified user,
including account status. This method can be called only by a
Token Admin
of the chaincode or theAccount Owner
of the account. -
GetAccountByUser
- This method returns 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. -
BalanceOf
- This method returns the total number of NFTs the specified user holds.
Methods for Role Management
-
AddRoleMember
- This method adds a role to a specified user.
-
RemoveRoleMember
- This method removes a role from a specified user and token. An
account ID is formed by creating an SHA-256 hash of the concatenated
membership service provider ID (
orgId
) and the user name or email ID (userId
). -
IsInRole
- This method returns a Boolean value to indicate if a user and
token has a specified role. An account ID is formed by creating an SHA-256
hash of the concatenated membership service provider ID
(
orgId
) and the user name or email ID (userId
). -
GetAccountsByRole
- This method returns a list of all account IDs for a specified role.
-
GetUsersByRole
- This method returns a list of all users for a specified role.
Methods for Transaction History Management
-
GetAccountTransactionHistory
- This method returns an array of the transaction history details for a specified account.
-
GetAccountTransactionHistoryWithFilters
- This method returns account transaction history for a specified
user, filtered by
PageSize
,Bookmark
,startTime
andendTime
. This method can only be called when connected to the remote Oracle Blockchain Platform network. -
GetTransactionById
- This method returns the history of a
Transaction
asset. -
DeleteHistoricalTransactions
- This method deletes transactions that are older than a specified date from the state database.
Token Behavior Management - Mintable Behavior
-
GetMaxMintQuantity
- This method returns the maximum mintable quantity of a token. If
the
max_mint_quantity
behavior is not configured in the specification file, then the default value is 0 and an infinite number of tokens can be minted. -
GetTotalMintedTokens
- This method returns the total net number of tokens available in the system for the specified token. The net number of tokens available is the total number of minted tokens minus the number of burned tokens.
Token Behavior Management - Transferable Behavior
-
SafeTransferFrom
- This method transfers ownership of the specified NFT from the
caller to another account. This method includes the following
validations:
- The token exists and is not burned.
- The sender account and receiver account exist and are not the same account.
- The sender account owns the token.
- The caller of the function is the sender.
-
TransferFrom
- This method transfers ownership of the specified NFT from a
sender account to a receiver account. It is the responsibility of the caller
to pass the correct parameters. This method can be called by any user, not
only the token owner. This method includes the following validations:
- The token exists and is not burned.
- The sender account and receiver account exist and are not the same account.
- The sender account owns the token.
Token Behavior Management - Burnable Behavior
-
Burn
- This method deactivates, or burns, the specified NFT from the
caller's account. The caller of this method must have an account. A token
cannot be burned unless the token specification file includes the
burnable
behavior. If noburner_role_name
property is specified in theroles
section of the specification file, then the owner of the token can burn the token. If aburner_role_name
property is specified in theroles
section, then the user assigned the burner role who is also the minter (creator) of the token can burn the token. Theburn
method is part of theERC721Token
package, which you access via the receiver of theCtx
struct.