caver.kct.kip17
caver.kct.kip17
helps you easily handle a smart contract that implements KIP-17 as a JavaScript object on the kaia 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 Kaia 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 Kaia Improvement Proposals.
caver.kct.kip17.deploy
caver.kct.kip17.deploy(tokenInfo, deployer)
Deploys the KIP-17 token contract to the kaia 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 kaia blockchain. See the below table for the details. |
deployer | string \ | The address in the keyring instance to deploy the KIP-17 token contract. This address must have enough KAIA 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 · kaiachain/caver-js · GitHub
Example
// using the promise> caver.kct.kip17.deploy({ name: 'Jasmine', symbol: 'JAS',}, '0x{address in hex}').then(console.log)KIP17 { ... _address: '0xfA7D967f414468083aDAd85257a2cBD6019693C2', _jsonInterface: [ ... { anonymous: false, inputs: [ { indexed: true, name: 'owner', type: 'address' }, { indexed: true, name: 'operator', type: 'address' }, { indexed: false, name: 'approved', type: 'bool' } ], name: 'ApprovalForAll', type: 'event', signature: '0x17307...' } ] }// Send object as second parameter> caver.kct.kip17.deploy({ name: 'Jasmine', symbol: 'JAS', }, { from: '0x{address in hex}', feeDelegation: true, feePayer: '0x{address in hex}', }).then(console.log)// using event emitter and promise> caver.kct.kip17.deploy({ name: 'Jasmine', symbol: 'JAS',}, '0x{address in hex}').on('error', function(error) { ... }).on('transactionHash', function(transactionHash) { ... }).on('receipt', function(receipt) { console.log(receipt.contractAddress) // contains the new token contract address}).then(function(newKIP17Instance) { console.log(newKIP17Instance.options.address) // instance with the new token contract address})
caver.kct.kip17.detectInterface
caver.kct.kip17.detectInterface(contractAddress)
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.detectInterface('0x{address in hex}').then(console.log){ IKIP17: true, IKIP17Metadata: true, IKIP17Enumerable: true, IKIP17Mintable: true, IKIP17MetadataMintable: true, IKIP17Burnable: true, IKIP17Pausable: true,}
caver.kct.kip17.create
caver.kct.kip17.create([tokenAddress])
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
// Create a KIP17 instance without a parameter> const kip17 = caver.kct.kip17.create()// Create a KIP17 instance with a token address> const kip17 = caver.kct.kip17.create('0x{address in hex}')
new KIP17
new caver.kct.kip17([tokenAddress])
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 kip17.options.address = '0x1234..' |
Return Value
Type | Description |
---|---|
object | The KIP17 instance with its bound methods and events. |
Example
// Create a KIP17 instance without a parameter> const kip17 = new caver.kct.kip17()// Create a KIP17 instance with a token address> const kip17 = new caver.kct.kip17('0x{address in hex}')
kip17.clone
kip17.clone([tokenAddress])
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
> const kip17 = new caver.kct.kip17(address)// Clone without a parameter> const cloned = kip17.clone()// Clone with the address of the new token contract> const cloned = kip17.clone('0x{address in hex}')
kip17.detectInterface
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.detectInterface().then(console.log){ IKIP17: true, IKIP17Metadata: true, IKIP17Enumerable: true, IKIP17Mintable: true, IKIP17MetadataMintable: true, IKIP17Burnable: true, IKIP17Pausable: true,}
kip17.supportsInterface
kip17.supportsInterface(interfaceId)
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.supportsInterface('0x80ac58cd').then(console.log)true> kip17.supportsInterface('0xa22cb465').then(console.log)false
kip17.name
kip17.name()
Returns the name of the token.
Parameters
None
Return Value
Promise
returns string
: The name of the token.
Example
> kip17.name().then(console.log)Jasmine
kip17.symbol
kip17.symbol()
Returns the symbol of the token.
Parameters
None
Return Value
Promise
returns string
: The symbol of the token.
Example
> kip17.symbol().then(console.log)JAS
kip17.totalSupply
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.totalSupply().then(console.log)10
kip17.tokenURI
kip17.tokenURI(tokenId)
Returns the URI for a given token id.
Parameters
Name | Type | Description |
---|---|---|
tokenId | BigNumber \ | 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.tokenURI(0).then(console.log)https://kip17.example/uri-ex-caver.json
kip17.tokenOfOwnerByIndex
kip17.tokenOfOwnerByIndex(owner, index)
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 \ | 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.tokenOfOwnerByIndex('0x{address in hex}', 5).then(console.log)5
kip17.tokenByIndex
kip17.tokenByIndex(index)
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 \ | 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.tokenByIndex(1).then(console.log)1
kip17.balanceOf
kip17.balanceOf(address)
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.balanceOf('0x{address in hex}').then(console.log)9
kip17.ownerOf
kip17.ownerOf(tokenId)
Returns the address of the owner of the specified token id.
Parameters
Name | Type | Description |
---|---|---|
tokenId | BigNumber \ | 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.ownerOf(8).then(console.log)0x0e0E95426343d97CC7BB913C7D7DBea065A31814
kip17.getApproved
kip17.getApproved(tokenId)
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 \ | 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
// If an approved address exists> kip17.getApproved(10).then(console.log)0x23D8E9cae17b22d3DAC65b4F7D2C737C6A7b865d// If no approved address exists> kip17.getApproved(3).then(console.log)0x0000000000000000000000000000000000000000
kip17.isApprovedForAll
kip17.isApprovedForAll(owner, operator)
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.isApprovedForAll('0x{address in hex}', '0x{address in hex}').then(console.log)false> kip17.isApprovedForAll('0x{address in hex}', '0x{address in hex}').then(console.log)true
kip17.isMinter
kip17.isMinter(address)
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.isMinter('0x{address in hex}').then(console.log)true> kip17.isMinter('0x{address in hex}').then(console.log)false
kip17.paused
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.paused().then(console.log)true> kip17.paused().then(console.log)false
kip17.isPauser
kip17.isPauser(address)
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.isPauser('0x{address in hex}').then(console.log)true> kip17.isPauser('0x{address in hex}').then(console.log)false
kip17.approve
kip17.approve(to, tokenId [, sendParam])
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 kaia 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 \ | 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 kip17.options.from . If neither of from in sendParam object nor kip17.options.from were not provided, an error would occur. |
gas | number \ | (optional) The maximum gas provided for this transaction (gas limit). If omitted, it will be set by caver-js via calling kip17.methods.approve(spender, tokenId).estimateGas({from}) . |
gasPrice | number \ | (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 \ | (optional) The value to be transferred in peb. |
feeDelegation | boolean | (optional, default false ) Whether to use fee delegation transaction. If omitted, kip17.options.feeDelegation will be used. If both omitted, fee delegation is not used. |
feePayer | string | (optional) The address of the fee payer paying the transaction fee. When feeDelegation is true , the value is set to the feePayer field in the transaction. If omitted, kip17.options.feePayer will be used. If both omitted, throws an error. |
feeRatio | string | (optional) The ratio of the transaction fee the fee payer will be burdened with. If feeDelegation is true and feeRatio is set to a valid value, a partial fee delegation transaction is used. The valid range of this is between 1 and 99. The ratio of 0, or 100 and above are not allowed. If omitted, kip17.options.feeRatio will be used. |
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
// Send via a sendParam object with the from field given > kip17.approve('0x{address in hex}', 10, { from: '0x{address in hex}' }).then(console.log){ blockHash: '0x3875c3f3120c1773c3adeb97260808c8a385bf8427bc203d10cbc5d262f67dbc', blockNumber: 2650, contractAddress: null, from: '0x1147c04b90d1546d76983e19937ad2cdae8b8afd', ... status: true, to: '0x5e0e6f1f0bdf9a263e1b1bb6e9759ba182982377', ... events: { Approval: { address: '0x5E0e6F1F0bDf9A263e1B1bB6e9759Ba182982377', blockNumber: 2650, transactionHash: '0x0ae92570560d64fa103c8be1861c8625d34ac560066398d9ad0d389ad5f7e441', transactionIndex: 0, blockHash: '0x3875c3f3120c1773c3adeb97260808c8a385bf8427bc203d10cbc5d262f67dbc', logIndex: 0, id: 'log_55296c9d', returnValues: { '0': '0x1147c04b90D1546d76983e19937aD2cDAE8b8afD', '1': '0x58746F9D739bC81713E5F5512529876F508a6166', '2': '2', owner: '0x1147c04b90D1546d76983e19937aD2cDAE8b8afD', approved: '0x58746F9D739bC81713E5F5512529876F508a6166', tokenId: '2', }, event: 'Approval', signature: '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925', raw: { data: '0x', topics: [ '0x8c5be...', '0x00...afd', '0x00...166', '0x00...002' ], }, }, },}// Using FD transaction to execute the smart contract> kip17.approve('0x{address in hex}', 10, { from: '0x{address in hex}' feeDelegation: true, feePayer: '0x{address in hex}'}).then(console.log)// Using kip17.options.from// If the value of kip17.options.from is set, this value is used as the default value // unless you specify `from` in the sendParam object when sending a transaction with a kip17 instance.> kip17.options.from = '0x{address in hex}'> kip17.approve('0x{address in hex}', 10).then(console.log)