caver.kct.kip17
caver.kct.kip17
helps you easily handle a smart contract that implements KIP-17 as a JavaScript object on the Klaytn blockchain.
The caver.kct.kip17
inherits caver.contract to implement the KIP-17 token contract. The caver.kct.kip17
holds the same properties of caver.contract
whereas there are additional methods to implement extra features. This section only introduces the newly added bound methods of the caver.kct.kip17
.
The code that implements KIP-17 for caver-js is available on the Klaytn Contracts Github Repo. KIP-17 for caver-js supports Ownable interface. Using this, you can designate a contract owner when deploying a contract
For more information about KIP-17, see Klaytn Improvement Proposals.
caver.kct.kip17.deploy
Deploys the KIP-17 token contract to the Klaytn blockchain. A contract deployed using caver.kct.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 |
---|---|---|
tokenInfo | object | The information needed to deploy KIP-17 token contract on the Klaytn blockchain. See the below table for the details. |
deployer | string | object | The address in the keyring instance to deploy the KIP-17 token contract. This address must have enough KLAY to deploy. See Keyring for more details. If you want to define your fields to use when sending transactions, you can pass the object type as a parameter. If you want to use Fee Delegation when deploying KIP-17 contracts, you can define the fields related to fee delegation in the object. For the use of these fields, refer to the parameter description of approve. |
The tokenInfo object must contain the following:
Name | Type | Description |
---|---|---|
name | string | The name of the token. |
symbol | string | The symbol of the token. |
Return Value
PromiEvent
: A promise combined event emitter, which is resolved with a new KIP17 instance. Additionally, the following events can occur:
Name | Type | Description |
---|---|---|
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. |
Token Enrollment
To enroll a token on a block explorer, the contract creator must fill out a submission request form. Make note of the specified information required on the form.
Smart Contract Environment
Compiler Type: Solidity
Compiler version: v0.8.4+commit.c7e474f2
Open Source License Type: MIT
Smart Contract Detail
Optimization: --optimize-run 200
Source code: KIP17 Contracts Github Link.
ABI-encoded Value: kip17JsonInterface at dev · klaytn/caver-js · GitHub
Example
caver.kct.kip17.detectInterface
Returns the information of the interface implemented by the token contract. This static function will use kip17.detectInterface.
Parameters
Name | Type | Description |
---|---|---|
contractAddress | string | The address of the KIP-7 token contract |
Return Value
Promise
returns an object
containing the result with boolean values whether each KIP-17 interface is implemented.
Example
caver.kct.kip17.create
Creates a new KIP17 instance with its bound methods and events. This function works the same as new KIP17.
NOTE caver.kct.kip17.create
is supported since caver-js v1.6.1.
Parameters
See the new KIP17.
Return Value
See the new KIP17.
Example
new KIP17
Creates a new KIP17 instance with its bound methods and events.
Parameters
Name | Type | Description |
---|---|---|
tokenAddress | string | (optional) The address of the KIP-17 token contract, which can be assigned later through |
Return Value
Type | Description |
---|---|
object | The KIP17 instance with its bound methods and events. |
Example
kip17.clone
Clones the current KIP17 instance.
Parameters
Name | Type | Description |
---|---|---|
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. |
Return Value
Type | Description |
---|---|
object | The clone of the original KIP17 instance. |
Example
kip17.detectInterface
Returns the information of the interface implemented by the token contract.
Parameters
None
Return Value
Promise
returns an object
containing the result with boolean values whether each KIP-17 interface is implemented.
Example
kip17.supportsInterface
Returns true
if this contract implements the interface defined by interfaceId
.
Parameters
Name | Type | Description |
---|---|---|
interfaceId | string | The interfaceId to be checked. |
Return Value
Promise
returns boolean
: true
if this contract implements the interface defined by interfaceId
.
Example
kip17.name
Returns the name of the token.
Parameters
None
Return Value
Promise
returns string
: The name of the token.
Example
kip17.symbol
Returns the symbol of the token.
Parameters
None
Return Value
Promise
returns string
: The symbol of the token.
Example
kip17.totalSupply
Returns the total number of tokens minted by the contract.
Parameters
None
Return Value
Promise
returns BigNumber
: The total number of tokens.
Example
kip17.tokenURI
Returns the URI for a given token id.
Parameters
Name | Type | Description |
---|---|---|
tokenId | BigNumber | string | number | The id of the token. |
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
kip17.tokenOfOwnerByIndex
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
Name | Type | Description |
---|---|---|
owner | string | The address of the account who owns tokens. |
index | BigNumber | string | number | The index of a token in owner's token list. |
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
kip17.tokenByIndex
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
Name | Type | Description |
---|---|---|
index | BigNumber | string | number | The index of a token to be queried. |
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
kip17.balanceOf
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
Name | Type | Description |
---|---|---|
address | string | The address of the account to be checked for its balance. |
Return Value
Promise
returns BigNumber
: The account balance.
Example
kip17.ownerOf
Returns the address of the owner of the specified token id.
Parameters
Name | Type | Description |
---|---|---|
tokenId | BigNumber | string | number | The id of the token. |
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
kip17.getApproved
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
Name | Type | Description |
---|---|---|
tokenId | BigNumber | string | number | The id of the token. |
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
kip17.isApprovedForAll
Returns true
if an operator
is approved to transfer all tokens that belong to the owner
.
Parameters
Name | Type | Description |
---|---|---|
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. |
Return Value
Promise
returns boolean
: true
if an operator
is approved to send all tokens that belong to the owner
.
Example
kip17.isMinter
Returns true
if the given account is a minter who can issue new tokens in the current contract conforming to KIP-17.
Parameters
Name | Type | Description |
---|---|---|
address | string | The address of the account to be checked for having the minting right. |
Return Value
Promise
returns boolean
: true
if the account is a minter.
Example
kip17.paused
Returns true
if the contract is paused, and false
otherwise.
Parameters
None
Return Value
Promise
returns boolean
: true
if the contract is paused.
Example
kip17.isPauser
Returns true
if the given account is a pauser who can suspend transferring tokens.
Parameters
Name | Type | Description |
---|---|---|
address | string | The address of the account to be checked for having the right to suspend transferring tokens. |
Return Value
Promise
returns boolean
: true
if the account is a pauser.
Example
kip17.approve
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
Name | Type | Description |
---|---|---|
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. |
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:
Name | Type | Description |
---|---|---|
from | string | (optional) The address from which the transaction should be sent. If omitted, it will be set by |
gas | number | string | (optional) The maximum gas provided for this transaction (gas limit). If omitted, it will be set by caver-js via calling |
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 |
value | number | string | BN | BigNumber | (optional) The value to be transferred in peb. |
feeDelegation | boolean | (optional, default |
feePayer | string | (optional) The address of the fee payer paying the transaction fee. When |
feeRatio | string | (optional) The ratio of the transaction fee the fee payer will be burdened with. If |
NOTE feeDelegation
, feePayer
and feeRatio
are supported since caver-js v1.6.1.
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
kip17.setApprovalForAll
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
Name | Type | Description |
---|---|---|
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 |
sendParam | object | (optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve. |
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
kip17.transferFrom
Transfers the token of the given token id, tokenId
from the token owner's balance to another address. The address that was authorized to send the token owner's token (the operator) or the token owner him/herself is expected to execute this token transfer transaction. Thus, an authorized account or the token owner should be the sender of this transaction whose address must be given at sendParam.from
or kip17Instance.options.from
. Unless both sendParam.from
and kip17Instance.options.from
are 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
Name | Type | Description |
---|---|---|
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. |
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
kip17.safeTransferFrom
Safely transfers the token of the given token id tokenId
from the token owner's balance to another address. The address that was authorized to send the token owner's token (the operator) or the token owner him/herself is expected to execute this token transfer transaction. Thus, an authorized address or the token owner should be the sender of this transaction whose address must be given at sendParam.from
or kip17Instance.options.from
. Unless both sendParam.from
and kip17Instance.options.from
are 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
Name | Type | Description |
---|---|---|
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. |
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
kip17.addMinter
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
Name | Type | Description |
---|---|---|
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. |
NOTE If sendParam.from
or kip17.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
kip17.renounceMinter
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
Name | Type | Description |
---|---|---|
sendParam | object | (optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve. |
If sendParam.from
or kip17.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
kip17.mintWithTokenURI
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
Name | Type | Description |
---|---|---|
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 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. |
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 kip17.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
kip17.burn
Destroys the token of the given token id. Without sendParam.from
nor kip17.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
Name | Type | Description |
---|---|---|
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. |
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
kip17.pause
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
Name | Type | Description |
---|---|---|
sendParam | object | (optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve. |
NOTE If sendParam.from
or kip17.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
kip17.unpause
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
Name | Type | Description |
---|---|---|
sendParam | object | (optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve. |
NOTE If sendParam.from
or kip17.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
kip17.addPauser
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
Name | Type | Description |
---|---|---|
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. |
NOTE If sendParam.from
or kip17.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
kip17.renouncePauser
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
Name | Type | Description |
---|---|---|
sendParam | object | (optional) An object with defined parameters for sending a transaction. For more information about sendParam, refer to the parameter description of approve. |
NOTE If sendParam.from
or kip17.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
Last updated