caver.klay.KIP17
A caver-js object used to interact with a smart contract for KIP17.
Last updated
A caver-js object used to interact with a smart contract for KIP17.
Last updated
caver.klay.KIP17
helps you easily handle a smart contract that implements KIP-17 as a JavaScript object on the Klaytn blockchain.
The caver.klay.KIP17
inherits caver.klay.Contract to implement the KIP-17 token contract. The caver.klay.KIP17
holds the same properties of caver.klay.Contract
whereas there are additional methods to implement extra features. This section only introduces the newly added bound methods of the caver.klay.KIP17
.
The code that implements KIP-17 for caver-js is available on the Klaytn Contracts Github Repo.
For more information about KIP-17, see Klaytn Improvement Proposals.
NOTE caver.klay.KIP17
is supported since caver-js v1.4.1.
Deploys the KIP-17 token contract to the Klaytn blockchain. A contract deployed using caver.klay.KIP17.deploy is a non-fungible token that follows the KIP-17 standard.
After successful deployment, the promise will be resolved with a new KIP17 instance.
Parameters
Name | Type | Description |
---|---|---|
The tokenInfo object must contain the following:
Name | Type | Description |
---|---|---|
Return Value
PromiEvent
: A promise combined event emitter, which is resolved with a new KIP17 instance. Additionally, the following events can occur:
Example
Creates a new KIP17 instance with its bound methods and events.
Parameters
Return Value
Example
Clones the current KIP17 instance.
Parameters
Return Value
Example
Returns true
if this contract implements the interface defined by interfaceId
.
Parameters
Return Value
Promise
returns Boolean
: true
if this contract implements the interface defined by interfaceId
.
Example
Returns the name of the token.
Parameters
None
Return Value
Promise
returns String
: The name of the token.
Example
Returns the symbol of the token.
Parameters
None
Return Value
Promise
returns String
: The symbol of the token.
Example
Returns the total number of tokens minted by the contract.
Parameters
None
Return Value
Promise
returns BigNumber
: The total number of tokens.
Example
Returns the URI for a given token id.
Parameters
NOTE The tokenId
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
Return Value
Promise
returns String
: The URI of the given token.
Example
Searches the owner
's token list for the given index, and returns the token id of a token positioned at the matched index in the list if there is a match.
Parameters
NOTE The index
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
Return Value
Promise
returns BigNumber
: The id of the token.
Example
Searches the list of all tokens in this contract for the given index, and returns the token id of a token positioned at the matched index in the list if there is a match. It reverts if the index is greater or equal to the total number of tokens.
Parameters
NOTE The index
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
Return Value
Promise
returns BigNumber
: The id of the token.
Example
Returns the balance of the given account address. The balance of an account in KIP-17 is the total number of NFTs (Non-Fungible Tokens) owned by the account.
Parameters
Return Value
Promise
returns BigNumber
: The account balance.
Example
Returns the address of the owner of the specified token id.
Parameters
NOTE The tokenId
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
Return Value
Promise
returns String
: The address of the account that owns the given token.
Example
Returns the address who was permitted to transfer this token, or 'zero' address, if no address was approved. It reverts if the given token id does not exist.
Parameters
NOTE The tokenId
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
Return Value
Promise
returns String
: The address of the account that has the right to transfer the given token.
Example
Returns true
if an operator
is approved to transfer all tokens that belong to the owner
.
Parameters
Return Value
Promise
returns Boolean
: true
if an operator
is approved to send all tokens that belong to the owner
.
Example
Returns true
if the given account is a minter who can issue new tokens in the current contract conforming to KIP-17.
Parameters
Return Value
Promise
returns Boolean
: true
if the account is a minter.
Example
Returns true
if the contract is paused, and false
otherwise.
Parameters
None
Return Value
Promise
returns Boolean
: true
if the contract is paused.
Example
Returns true
if the given account is a pauser who can suspend transferring tokens.
Parameters
Return Value
Promise
returns Boolean
: true
if the account is a pauser.
Example
Approves another address to transfer a token of the given token id. The zero address indicates there is no approved address. There can only be one approved address per token. This method is allowed to call only by the token owner or an approved operator.
Note that this method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
NOTE The tokenId
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
The sendParam object can contain the following:
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Approves the given operator to
, or disallow the given operator, to transfer all tokens of the owner.
Note that the setApprovalForAll method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Transfers the token of the given token id tokenId
from the token owner's balance to another address. The address who was approved to send the token owner's token (the operator) or the token owner itself is expected to execute this token transferring transaction. Thus, the approved one or the token owner should be the sender of this transaction whose address must be given at sendParam.from
or kip7Instance.options.from
. Without sendParam.from
nor kip7Instance.options.from
being provided, an error would occur. It is recommended to use safeTransferFrom whenever possible instead of this method.
Note that sending this transaction will charge the transaction fee to the transaction sender.
Parameters
NOTE The tokenId
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Safely transfers the token of the given token id tokenId
from the token owner's balance to another address. The address who was approved to send the token owner's token (the operator) or the token owner itself is expected to execute this token transferring transaction. Thus, the approved one or the token owner should be the sender of this transaction whose address must be given at sendParam.from
or kip7Instance.options.from
. Without sendParam.from
nor kip7Instance.options.from
being provided, an error would occur.
If the to
is a contract address, it must implement IKIP17Receiver.onKIP17Received. otherwise, the transfer is reverted.
Note that sending this transaction will charge the transaction fee to the transaction sender.
Parameters
NOTE The tokenId
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Adds an account as a minter, who are permitted to mint tokens.
Note that the addMinter method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
NOTE If sendParam.from
or KIP17Instance.options.from
were given, it should be a minter.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Renounces the right to mint tokens. Only a minter address can renounce the minting right.
Note that the renounceMinter method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
If sendParam.from
or KIP17Instance.options.from
were given, it should be a minter with MinterRole.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Creates a token with the given uri and assigns them to the given account. This method increases the total supply of this token.
Note that the mintWithTokenURI method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
NOTE The tokenId
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
NOTE If sendParam.from
or KIP17Instance.options.from
were given, it should be a minter with MinterRole.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Destroys the token of the given token id. Without sendParam.from
nor KIP17Instance.options.from
being provided, an error would occur.
Note that the burn method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
NOTE The tokenId
parameter accepts Number
type but if the fed value were out of the range capped by Number.MAX_SAFE_INTEGER, it might cause an unexpected result or error. In this case, it is recommended to use the BigNumber
type, especially for a uint256
sized numeric input value.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Suspends functions related to sending tokens.
Note that the pause method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
NOTE If sendParam.from
or KIP17Instance.options.from
were given, it should be a pauser with PauserRole.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Resumes the paused contract.
Note that the unpause method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
NOTE If sendParam.from
or KIP17Instance.options.from
were given, it should be a pauser with PauserRole.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Adds an account as a pauser that has the right to suspend the contract.
Note that the addPauser method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
NOTE If sendParam.from
or KIP17Instance.options.from
were given, it should be a pauser with PauserRole.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Renounces the right to pause the contract. Only a pauser address can renounce its own pausing right.
Note that the renouncePauser method will submit a transaction to the Klaytn network, which will charge the transaction fee to the sender.
Parameters
NOTE If sendParam.from
or KIP17Instance.options.from
were given, it should be a pauser with PauserRole.
Return Value
Promise
returns Object
- The receipt containing the result of the transaction execution. If you want to know about the properties inside the receipt object, see the description of getTransactionReceipt. Receipts from KIP-17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
tokenInfo
Object
The information needed to deploy KIP-17 token contract on the Klaytn blockchain. See the below table for the details.
deployer
String
The address of the account to deploy the KIP-17 token contract. This account must have enough KLAY to deploy.
name
String
The name of the token.
symbol
String
The symbol of the token.
transactionHash
String
Fired right after the transaction is sent and a transaction hash is available.
receipt
Object
Fired when the transaction receipt is available. If you want to know about the properties inside the receipt object, see getTransactionReceipt. Receipts from KIP17 instances have an 'events' attribute parsed via abi instead of a 'logs' attribute.
error
Error
Fired if an error occurs during sending.
tokenAddress
String
(optional) The address of the KIP-17 token contract, which can be assigned later through kip17Instance.options.address = '0x1234..'
Object
The KIP17 instance with its bound methods and events.
tokenAddress
String
(optional) The address of the smart contract that deployed another KIP-17 token. If omitted, it will be set to the contract address in the original instance.
Object
The clone of the original KIP17 instance.
interfaceId
String
The interfaceId to be checked.
tokenId
BigNumber | String | Number
The id of the token.
owner
String
The address of the account who owns tokens.
index
BigNumber | String | Number
The index of a token in owner's token list.
index
BigNumber | String | Number
The index of a token to be queried.
address
String
The address of the account to be checked for its balance.
tokenId
BigNumber | String | Number
The id of the token.
tokenId
BigNumber | String | Number
The id of the token.
owner
String
The address of an account that owns tokens and has allowed the operator to send all its tokens.
operator
String
The address of the account approved to send owner's all tokens in place of the owner.
address
String
The address of the account to be checked for having the minting right.
address
String
The address of the account to be checked for having the right to suspend transferring tokens.
to
String
The address of the account who spends tokens in place of the owner.
tokenId
BigNumber | String | Number
The id of the token the spender is allowed to use.
sendParam
Object
(optional) An object with defined parameters for sending a transaction.
from
String
(optional) The address from which the transaction should be sent. If omitted, it will be set by this.options.from
. If neither of from
in sendParam
object nor this.options.from
were not provided, an error would occur.
gas
Number | String
(optional) The maximum gas provided for this transaction (gas limit). If omitted, it will be set by caver-js via calling this.methods.approve(spender, tokenId).estimateGas({from})
.
gasPrice
Number | String
(optional) The gas price in peb to use for this transaction. If omitted, it will be set by caver-js via calling caver.klay.getGasPrice
.
value
Number | String | BN | BigNumber
(optional) The value to be transferred in peb.
to
String
The address of an account to be approved/prohibited to transfer the owner's all tokens.
approved
Boolean
This operator will be approved if true
. The operator will be disallowed if false
.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
from
String
The address of the owner or the approved operator of the given token.
to
String
The address of the account to receive the token.
tokenId
BigNumber | String | Number
The id of the token you want to transfer.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
from
String
The address of the owner or the approved operator of the given token.
to
String
The address of the account to receive the token.
tokenId
BigNumber | String | Number
The id of the token you want to transfer.
data
Buffer | String | Number
(optional) The optional data to send along with the call.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
account
String
The address of the account to be added as a minter.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
to
String
The address of the account to which the minted token will be issued.
tokenId
BigNumber | String | Number
The id of the token to be minted.
tokenURI
String
The uri string of the token to be minted.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
tokenId
BigNumber | String | Number
The id of the token to be destroyed.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
account
String
The address of the account to be a new pauser.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.
sendParam
Object
(optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve.