caver.kct.kip7
The caver.kct.kip7
helps you easily handle a smart contract that implements KIP-7 as a JavaScript object on the Klaytn blockchain platform (Klaytn).
The caver.kct.kip7
inherits caver.contract to implement the KIP-7 token contract. The caver.kct.kip7
holds the same properties of caver.contract
whereas additional methods to implement extra features. This section only introduces the newly added bound methods of the caver.kct.kip7
.
The abi and bytecode used in the caver.kct.kip7 were implemented using the example of openzeppelin.
The code that implements KIP-7 for caver-js is available on the Klaytn Contracts Github Repo.
For more information about KIP-7, see Klaytn Improvement Proposals.
caver.kct.kip7.deploy
Deploys the KIP-7 token contract to the Klaytn blockchain. A contract deployed using caver.kct.kip7.deploy is a fungible token that follows the KIP-7 standard.
After successful deployment, the promise will be resolved with a new KIP7 instance.
Parameters
Name
Type
Description
tokenInfo
object
The information needed to deploy KIP-7 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
name
string
The name of the token.
symbol
string
The symbol of the token.
decimals
number
The number of decimal places the token uses.
initialSupply
BigNumber | string | number
The total amount of token to be supplied initially.
NOTE The initialSupply
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
PromiEvent
: A promise combined event emitter, which is resolved with a new KIP7 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.kip7.detectInterface
Returns the information of the interface implemented by the token contract. This static function will use kip7.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-7 interface is implemented.
Example
caver.kct.kip7.create
Creates a new KIP7 instance with its bound methods and events. This function works the same as new KIP7.
NOTE caver.kct.kip7.create
is supported since caver-js v1.6.1.
Parameters
See the new KIP7.
Return Value
See the new KIP7.
Example
new KIP7
Creates a new KIP7 instance with its bound methods and events.
Parameters
Name
Type
Description
tokenAddress
string
(optional) The address of the KIP-7 token contract, which can be assigned later through kip7.options.address = '0x1234..'
Return Value
Type
Description
object
The KIP7 instance with its bound methods and events.
Example
kip7.clone
Clones the current KIP7 instance.
Parameters
Name
Type
Description
tokenAddress
string
(optional) The address of the smart contract that deployed another KIP7 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 KIP7 instance.
Example
kip7.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-7 interface is implemented.
Example
kip7.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
kip7.name
Return the name of the token.
Parameters
None
Return Value
Promise
returns string
: The name of the token.
Example
kip7.symbol
Return the symbol of the token.
Parameters
None
Return Value
Promise
returns string
: The symbol of the token.
Example
kip7.decimals
Return the number of decimal places the token uses.
Parameters
None
Return Value
Promise
returns number
: The number of decimal places the token uses.
Example
kip7.totalSupply
Return the total token supply.
Parameters
None
Return Value
Promise
returns BigNumber
: The total number of tokens.
Example
kip7.balanceOf
Return the balance of the given account address.
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
kip7.allowance
Return the amount of token that spender
is allowed to withdraw from owner
.
Parameters
Name
Type
Description
owner
string
The address of the token owner's account.
spender
string
The address of the account that spends tokens in place of the owner.
Return Value
Promise
returns BigNumber
: The remaining number of tokens that spender is allowed to spend in place of the owner.
Example
kip7.isMinter
Return true
if the given account is a minter who can issue new KIP7 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
kip7.isPauser
Return 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
kip7.paused
Return true
if the contract is paused, and false
otherwise.
Parameters
None
Return Value
Promise
returns Boolean
: true
if the contract is paused.
Example
kip7.approve
Set the amount
of the tokens of the token owner to be spent by the spender
.
Note that this method will submit a transaction from the owner to the Klaytn network, which will charge the transaction fee to the owner.
Parameters
Name
Type
Description
spender
string
The address of the account who spends tokens in place of the owner.
amount
BigNumber | string | number
The amount of token the spender is allowed to use.
sendParam
object
(optional) An object holding parameters that are required for sending a transaction.
NOTE The amount
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 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 kip7.options.from
. If neither of from
in the sendParam
object nor kip7.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 kip7.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, kip7.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, kip7.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, kip7.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 KIP7 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
kip7.transfer
Transfers the given amount
of the token from the token owner's balance to the recipient
. The token owner should execute this token transfer with its own hands. Thus, the token owner should be the sender of this transaction whose address must be given at sendParam.from
or kip7.options.from
. Without sendParam.from
nor kip7.options.from
being provided, an error would occur.
Note that sending this transaction will charge the transaction fee to the transaction sender.
Parameters
Name
Type
Description
recipient
string
The address of the account to receive the token.
amount
BigNumber | string | number
The amount of token to be transferred.
sendParam
object
NOTE The amount
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 KIP7 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
kip7.safeTransfer
Safely transfers the given amount
of the token from the token owner's balance to the recipient
. The token owner should execute this token transfer with its own hands. Thus, the token owner should be the sender of this transaction whose address must be given at sendParam.from
or kip7.options.from
. Without sendParam.from
nor kip7.options.from
being provided, an error would occur.
If the recipient was a contract address, it should implement IKIP7Receiver.onKIP7Received. Otherwise, the transfer is reverted.
Note that sending this transaction will charge the transaction fee to the transaction sender.
Parameters
Name
Type
Description
recipient
string
The address of the account to receive the token.
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 amount
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 KIP17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
kip7.transferFrom
Transfers the given amount
of the token from the token owner's balance to the recipient
. The address who was approved to send the token owner's tokens is expected to execute this token transferring transaction. Thus, the approved one should be the sender of this transaction whose address must be given at sendParam.from
or kip7.options.from
. Without sendParam.from
nor kip7.options.from
being provided, an error would occur.
Note that sending this transaction will charge the transaction fee to the transaction sender.
Parameters
Name
Type
Description
sender
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.
amount
BigNumber | string | number
The amount of token you want to transfer.
sendParam
object
NOTE The amount
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 KIP7 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
kip7.safeTransferFrom
Safely transfers the given amount
of the token from the token owner's balance to the recipient
. The address who was approved to send the token owner's tokens is expected to execute this token transferring transaction. Thus, the approved one should be the sender of this transaction whose address must be given at sendParam.from
or kip7.options.from
. Without sendParam.from
nor kip7.options.from
being provided, an error would occur.
If the recipient was a contract address, it should implement IKIP7Receiver.onKIP7Received. Otherwise, the transfer is reverted.
Note that sending this transaction will charge the transaction fee to the transaction sender.
Parameters
Name
Type
Description
sender
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.
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 amount
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 KIP17 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example
kip7.mint
Creates the amount
of token and issues it to the account
, increasing the total supply of token.
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
account
string
The address of the account to which the minted token will be issued.
amount
BigNumber | string | number
The amount of token to be minted.
sendParam
object
NOTE The amount
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 kip7.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 KIP7 instances have an 'events' attribute parsed via ABI instead of a 'logs' attribute.
Example