caver.kct.kip37
The caver.kct.kip37
helps you easily handle a smart contract that implements KIP-37 as a JavaScript object on the kaia blockchain platform (kaia).
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 Kaia Contracts Github Repo. KIP-37 for caver-js supports Ownable interface. Using this, you can designate a contract owner when deploying a contract
For more information about KIP-37, see Kaia Improvement Proposals.
NOTE caver.kct.kip37
is supported since caver-js v1.5.7.
caver.kct.kip37.deploy
caver.kct.kip37.deploy(tokenInfo, deployer)
Deploys the KIP-37 token contract to the kaia 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 kaia blockchain. See the below table for the details. |
deployer | string \ | The address in the keyring instance to deploy the KIP-37 token contract. This address must have enough KAIA to deploy. See Keyring for more details. If you want to define your own fields to use when sending transactions, you can pass the object type as a parameter. Also, if you want to use Fee Delegation when deploying KIP-37 contracts, you can define fields related to fee delegation in the object. For fields that can be defined in the object, refer to the parameter description of create. |
The tokenInfo object must contain the following:
Name | Type | Description |
---|---|---|
uri | string | The URI for all token types, by relying on the token type ID substitution mechanism. |
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 | Fired when the transaction receipt is available. If you want to know about the properties inside the receipt object, see getTransactionReceipt. Receipts from KIP37 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: KIP37 Contracts Github Link.
-
-
ABI-encoded Value: kip37JsonInterface at dev · kaiachain/caver-js · GitHub
Example
// using the promise> caver.kct.kip37.deploy({ uri: 'https://caver.example/{id}.json',}, '0x{address in hex}').then(console.log)KIP37 { ... _address: '0x7314B733723AA4a91879b15a6FEdd8962F413CB2', _jsonInterface: [ ... { anonymous: false, inputs: [{ indexed: false, name: 'value', type: 'string' }, { indexed: true, name: 'id', type: 'uint256' }], name: 'URI', type: 'event', signature: '0x6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b', } ] }// Send object as second parameter> caver.kct.kip37.deploy({ uri: 'https://caver.example/{id}.json', }, { from: '0x{address in hex}', feeDelegation: true, feePayer: '0x{address in hex}', }).then(console.log)// using event emitter and promise> caver.kct.kip37.deploy({ uri: 'https://caver.example/{id}.json',}, '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(newKIP37Instance) { console.log(newKIP37Instance.options.address) // instance with the new token contract address})
caver.kct.kip37.detectInterface
caver.kct.kip37.detectInterface(contractAddress)
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.detectInterface('0x{address in hex}').then(console.log){ IKIP37: true, IKIP37Metadata: true, IKIP37Mintable: true, IKIP37Burnable: true, IKIP37Pausable: true,}
caver.kct.kip37.create
caver.kct.kip37.create([tokenAddress])
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
// Create a KIP37 instance without a parameter> const kip37 = caver.kct.kip37.create()// Create a KIP37 instance with a token address> const kip37 = caver.kct.kip37.create('0x{address in hex}')
new KIP37
new caver.kct.kip37([tokenAddress])
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
// Create a KIP37 instance without a parameter> const kip37 = new caver.kct.kip37()// Create a KIP37 instance with a token address> const kip37 = new caver.kct.kip37('0x{address in hex}')
kip37.clone
kip37.clone([tokenAddress])
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
> const kip37 = new caver.kct.kip37(address)// Clone without a parameter> const cloned = kip37.clone()// Clone with the address of the new token contract> const cloned = kip37.clone('0x{address in hex}')
kip37.detectInterface
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.detectInterface().then(console.log){ IKIP37: true, IKIP37Metadata: true, IKIP37Mintable: true, IKIP37Burnable: true, IKIP37Pausable: true,}
kip37.supportsInterface
kip37.supportsInterface(interfaceId)
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.supportsInterface('0x6433ca1f').then(console.log)true> kip37.supportsInterface('0x3a2820fe').then(console.log)false
kip37.uri
kip37.uri(id)
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 \ | 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.uri('0x0').then(console.log)'https://caver.example/0000000000000000000000000000000000000000000000000000000000000000.json'
kip37.totalSupply
kip37.totalSupply(id)
Returns the total token supply of the specific token.
Parameters
Name | Type | Description |
---|---|---|
id | BigNumber \ | 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.totalSupply(0).then(console.log)10000000000
kip37.balanceOf
kip37.balanceOf(account, id)
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 \ | 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.balanceOf('0x{address in hex}', 0).then(console.log)20
kip37.balanceOfBatch
kip37.balanceOfBatch(accounts, ids)
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.balanceOfBatch(['0x{address in hex}', '0x{address in hex}'], [0, 1]).then(console.log)[ 20, 30 ]