caver.kct.kip37
The caver.kct.kip37
helps you easily handle a smart contract that implements KIP-37 as a JavaScript object on the Klaytn blockchain platform (Klaytn).
The caver.kct.kip37
inherits caver.contract to implement the KIP-37 token contract. The caver.kct.kip37
holds the same properties of caver.contract
whereas additional methods are implemented for extra features. This section only introduces the newly added methods of the caver.kct.kip37
.
The code that implements KIP-37 for caver-js is available on the Klaytn Contracts Github Repo.
For more information about KIP-37, see Klaytn Improvement Proposals.
NOTE caver.kct.kip37
is supported since caver-js v1.5.7.
caver.kct.kip37.deploy
Deploys the KIP-37 token contract to the Klaytn blockchain. A contract deployed using caver.kct.kip37.deploy is a multi token that follows the KIP-37 standard.
After successful deployment, the promise will be resolved with a new KIP37 instance.
Parameters
Name
Type
Description
tokenInfo
object
The information needed to deploy a KIP-37 token contract on the Klaytn blockchain. See the below table for the details.
deployer
string | object
The tokenInfo object must contain the following:
Name
Type
Description
uri
string
Return Value
PromiEvent
: A promise combined event emitter, which is resolved with a new KIP37 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
error
Error
Fired if an error occurs during sending.
Example
caver.kct.kip37.detectInterface
Returns the information of the interface implemented by the token contract. This static function will use kip37.detectInterface.
Parameters
Name
Type
Description
contractAddress
string
The address of the KIP-37 token contract
Return Value
Promise
returns an object
containing the result with boolean values whether each KIP-37 interface is implemented.
Example
caver.kct.kip37.create
Creates a new KIP37 instance with its bound methods and events. This function works the same as new KIP37.
NOTE caver.kct.kip37.create
is supported since caver-js v1.6.1.
Parameters
See the new KIP37.
Return Value
See the new KIP37.
Example
new KIP37
Creates a new KIP37 instance with its bound methods and events.
Parameters
Name
Type
Description
tokenAddress
string
(optional) The address of the KIP-37 token contract, which can be assigned later through kip37.options.address = '0x1234..'
Return Value
Type
Description
object
The KIP37 instance with its bound methods and events.
Example
kip37.clone
Clones the current KIP37 instance.
Parameters
Name
Type
Description
tokenAddress
string
(optional) The address of the smart contract that deployed another KIP37 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 KIP37 instance.
Example
kip37.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-37 interface is implemented.
Example
kip37.supportsInterface
Return 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
kip37.uri
Returns distinct Uniform Resource Identifier (URI) of the given token.
If the string "{id}" exists in any URI, this function will replace this with the actual token ID in hexadecimal form. Please refer to KIP-34 Metadata.
Parameters
Name
Type
Description
id
BigNumber | string | number
The token id to get uri.
NOTE The id
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 token.
Example
kip37.totalSupply
Returns the total token supply of the specific token.
Parameters
Name
Type
Description
id
BigNumber | string | number
The token id to see the total supply.
NOTE The id
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 total number of tokens.
Example
kip37.balanceOf
Returns the amount of tokens of token type id
owned by account
.
Parameters
Name
Type
Description
account
string
The address of the account for which you want to see balance.
id
BigNumber | string | number
The token id to see balance.
NOTE The id
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 amount of token that account has.
Example
kip37.balanceOfBatch
Returns the balance of multiple account/token pairs. balanceOfBatch
is a batch operation of balanceOf, and the length of arrays with accounts
and ids
must be the same.
Parameters
Name
Type
Description
accounts
Array
The address of the account for which you want to see balance.
ids
Array
An array of the token ids to see balance.
Return Value
Promise
returns Array
: The balance of multiple account/token pairs.
Example
kip37.isMinter
Returns true
if the given account is a minter who can issue new KIP37 tokens.
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
kip37.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
kip37.paused
Returns whether or not the token contract's transaction (or specific token) is paused.
If id parameter is not defined, return whether the token contract's transaction is paused. If id parameter is defined, return whether the specific token is paused.
Parameters
Name
Type
Description
id
BigNumber | string | number
(optional) The token id to check wether paused or not. If this parameter is omitted, the paused
function return whether the contract is in paused state.
NOTE The id
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 boolean
: true
if the contract (or specific token) is paused.
Example
kip37.isApprovedForAll
Queries the approval status of an operator for a given owner. Returns true
if an operator is approved by a given owner.
Parameters
Name
Type
Description
owner
string
The address of the owner.
operator
string
The address of the operator.
Return Value
Promise
returns boolean
: True if the operator is approved, false if not
Example
kip37.create
Creates a new token type and assigns initialSupply
to the minter.
Note that this method will submit a transaction to the Klaytn network, which will charge the transaction fee to the transaction sender.
Parameters
Name
Type
Description
id
BigNumber | string | number
The token id to create.
initialSupply
BigNumber | string | number
The amount of tokens being minted.
uri
string
(optional) The token URI of the created token.
sendParam
object
(optional) An object holding parameters that are required for sending a transaction.
NOTE The id
, initialSupply
parameters accept 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 contains the following:
Name
Type
Description
from
string
(optional) The address from which the transaction should be sent. If omitted, it will be set by kip37.options.from
. If neither of from
in the sendParam
object nor kip37.options.from
were not provided, an error would occur.
gas
number | string
(optional) The maximum number of gas provided for this transaction (gas limit). If omitted, it will be set by caver-js via calling kip37.methods.approve(spender, amount).estimateGas({from})
.
gasPrice
number | string
(optional) The gas price in peb 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.
feeDelegation
boolean
(optional, default false
) Whether to use fee delegation transaction. If omitted, kip37.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, kip37.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, kip37.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 KIP37 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
kip37.setApprovalForAll
Approves the given operator, or disallow the given operator, to transfer all tokens of the owner.
Note that this method will submit a transaction to the Klaytn network, which will charge the transaction fee to the transaction sender.
Parameters
Name
Type
Description
operator
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
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 KIP37 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
kip37.safeTransferFrom
Safely transfers the given amount
tokens of specific token type id
from from
to the recipient
.
The address that was authorized to send the 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 kip37.options.from
. Unless both sendParam.from
and kip37.options.from
are provided, an error would occur.
If the recipient was a contract address, it should implement IKIP37Receiver.onKIP37Received. Otherwise, the transfer is reverted.
Note that this method will submit a transaction to the Klaytn network, which will charge the transaction fee to the transaction sender.
Parameters
Name
Type
Description
from
string
The address of the account that owns the token to be sent with allowance mechanism.
recipient
string
The address of the account to receive the token.
id
BigNumber | string | number
The token id to transfer.
amount
BigNumber | string | number
The amount of token you want to transfer.
data
Buffer | string | number
(optional) The optional data to send along with the call.
sendParam
object
NOTE The id
and amount
parameters accept 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 KIP37 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
kip37.safeBatchTransferFrom
Safely batch transfers of multiple token ids and values from from
to the recipient
.
The address that was approved to send the owner's token (the operator) or the token owner him/herself is expected to execute this token transfer transaction. Thus, an approved address or the token owner should be the sender of this transaction whose address must be given at sendParam.from
or kip37.options.from
. Unless both sendParam.from
and kip37.options.from
are provided, an error would occur.
If the recipient was a contract address, it should implement IKIP37Receiver.onKIP37Received. Otherwise, the transfer is reverted.
Note that this method will submit a transaction to the Klaytn network, which will charge the transaction fee to the transaction sender.
Parameters
Name
Type
Description
from
string
The address of the account that owns the token to be sent with allowance mechanism.
recipient
string
The address of the account to receive the token.
ids
Array
An array of the token ids to transfer.
amounts
Array
An array of the token amounts you want to transfer.
data
Buffer | string | number
(optional) The optional The data to send along with the call.
sendParam
object
NOTE The ids
and amounts
array parameters accept number
type as an element in array, 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 KIP37 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
kip37.mint
Mints the token of the specific token type id
and assigns the tokens according to the variables to
and value
. The mint function allows you to mint specific token to multiple accounts at once by passing arrays to to
and value
as parameters.
Note that this method will submit a transaction to the Klaytn network, which will charge the transaction fee to the transaction sender.
Parameters
Name
Type
Description
to
string | Array
An address of the account or an array of addresses to which the minted token will be issued.
id
BigNumber | string | number
The token id to mint.
value
BigNumber | string | number | Array
The amount of token to be minted. If an array containing multiple addresses is delivered to to
parameter, the value must be delivered in the form of an array.
sendParam
object
NOTE The id
and value
parameters accept 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 kip37.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 KIP37 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example