Klaytn Provider
Kaikas injects a global API into websites visited by its users at window.klaytn
. This API allows websites to request user login, load data from blockchains, and create transactions. You can use this API to detect whether the user uses Kaikas.
Properties
These properties can be used to check the current state of the connected user, which can be important things to verify before sending a transaction.
klaytn.networkVersion
Returns a numeric string representing the current blockchain's network ID.
Baobab
and Cypress
are names for Klaytn test network and main network respectively.
klaytn.selectedAddress
Returns a hex-prefixed string representing the current user's selected address, ex: "0xfdea65c8e26263f6d9a1b5de9555d2931a33b825"
.
klaytn.isKaikas
Returns true
or false
, depending on whether the user has Kaikas installed.
Methods
klaytn.enable()
Send connection request to Kaikas user. Returns a promise of an array of hex-prefixed Klaytn address strings. If the user accepts the request, BApp is granted access to user's account information.
klaytn.sendAsync(options, callback)
Sends a message to the Kaikas browser. Message format maps to the format of Klaytn JSON-RPC API.
Here's an example of klay_sendTransaction
wallet_watchAsset
wallet_watchAsset
is a special method for registering tokens. For detailed information, please refer to registering your token
wallet_switchKlaytnChain
"wallet_switchEthereumChain" method is also supported.
wallet_switchKlaytnChain
is a method for requesting to switch the chain of the wallet.
wallet_addKlaytnChain
"wallet_addEthereumChain" method is also supported.
wallet_addKlaytnChain
is a method for adding a chain to the wallet. When the chain is added (or already exists), Kaikas will show a pop up to switch the chain.
klaytn.request(options)
This method is the same as klaytn.sendAsync(). The difference is that request() is based on a Promise. See the klaytn.sendAsync() section for details on the options.
Sends a message to the Kaikas browser.
klaytn.autoRefreshOnNetworkChange
When the network is changed, Kaikas will reload any pages that have made requests to the provider.
To disable auto-refresh on a network change you can do:
This can be toggled on or off at any time. (Default value is true
)
klaytn.on(eventName, callback)
The provider supports listening for some events:
accountsChanged
, returns updated account array.networkChanged
, returns network ID string.disconnected
, returns nothing.
klaytn._kaikas
For developers' convenience, Kaikas provides 3 useful methods under _kaikas
namespace.
klaytn._kaikas.isEnabled()
This method returns a Boolean
indicating if the current domain has access to user accounts. This is useful for determining whether the user has approved account access for the current session.
klaytn._kaikas.isApproved()
This method returns a Promise
that resolves to a Boolean
indicating if the current domain has a cached approval. This is useful for determining if an approval popup will show when klaytn.enable()
is called, since it indicates if a past approval exists
klaytn._kaikas.isUnlocked()
This method returns a Promise
that resolves to a Boolean
indicating whether Kaikas is unlocked. Note that this does not indicate whether the user has approved account exposure.
Last updated