Klaytn network
How to integrate with D'CENT wallet for dapps on Klaytn network.
D'CENT mobile app's in-app browser injects window.klaytn & window.caver as providers. If your dapp is based on Klaytn network, you can interact with D'CENT wallet through window.klaytn & window.caver providers.

If your dapp is already integrated with Kaikas

D'CENT wallet's provider uses the same provider interface with Kaikas. It means if your dapp is already integrated with Kaikas, it's very easy to integrate with D'CENT wallet.
For your reference, you can also find the Kaikas' developer guide in the below link.

How to detect in-app browser

In order to check if your dapp running on Klaytn is supported dapp-browser, you need to check whether window.klaytn is defined.
1
if (typeof window.klaytn !== 'undefined') {
2
console.log("It's in-app browser");
3
}
Copied!

How to check D'CENT provider

You can check whether the dapp browser is D'CENT wallet's in-app browser with the following code.
1
if (window.klaytn.isDcentWallet === true) {
2
console.log("It's D'CENT wallet's in-app browser")
3
}
Copied!

Connect to Wallet

You can use the following code in order to connect to D'CENT wallet's account.
1
klaytn.enable()
Copied!

Wallet Connection UI

If the connection to wallet is requested, you can see the popup like below.

Get the current network

To get the current network ID, you can use the following code.
1
klaytn.networkVersion
Copied!
By checking the network ID, you can know which network is currently connected to.
Network ID
Network Name
8217
Klaytn Mainnet
1001
Klaytn Testnet Baobab

Get the current account's address

To get the address of the current account, you can use the following code.
1
klaytn.selectedAddress
Copied!

Send Transaction

By using ethereum.sendAsync method to call klay_sendTransaction, you can send the transaction. The following is the example code to show how to send the transaction. (This example is copied from Kaikas docs)
1
const transactionParameters = {
2
gas: '0x2710',
3
to: '0x0000000000000000000000000000000000000000',
4
from: klaytn.selectedAddress,
5
value: '0xff'
6
}
7
8
klaytn.sendAsync(
9
{
10
method: 'klay_sendTransaction',
11
params: [transactionParameters],
12
from: klaytn.selectedAddress
13
},
14
callback
15
)
Copied!
You can also see more examples on the Kaikas Developer Guide.