OKExChain DApps Integration
Welcome to Coin98 Extension Wallet Developer Guide. This documentation contains guides for developers to get started developing on Coin98 Extension Wallet.‌

To detect Coin98 Extension with OKExChain

To detect whether your browser is running Coin98 Extension, please use:
1
if(window.coin98 || window.ethereum || window.ethereum?.isCoin98){
2
console.log('Coin98 Extension is installed!');
3
}
Copied!
Notice: Coin98 Extension Testnet is under development and not available now. The Coin98 Extension on Ethereum JavaScript provider API is specified by EIP-1193. Support window.ethereum only and removal window.web3

To connect Coin98 Extension Wallet

To connect Coin98 Extension means to access the user's [blockchain - like Ethereum] account(s).
1
// Connect & get accounts
2
window.ethereum.request({method: 'eth_accounts'});
3
// Alias for connection
4
window.ethereum.request({method: 'eth_requestAccounts'});
5
//Check if dapp connected
6
window.ethereum.isConnected();
7
//Check if the caller's current permissions
8
window.ethereum.request({method: 'wallet_getPermissions'});
9
//Check if request the given permissions
10
window.ethereum.request({method: 'wallet_requestPermissions'});
Copied!

To disconnect Coin98 Extension Wallet

To disconnect Coin98 Extension, please use:
1
window.ethereum.disconnect()
Copied!

To experience functions

Once your account is connected, let's start experiencing more functions.‌

Get Current Account

return Promise<Array[String]>
  • If wallet can not be found, return [] instead of throw Error
1
window.ethereum.request({ method: 'eth_accounts' }).then(accounts => {
2
if (accounts[0]) {
3
// Do something with accounts
4
} else {
5
// Wallet not found
6
}
7
})
Copied!

Check wallet whether exists or not

return Promise<{data: Boolean}>
1
window.ethereum.request({ method: 'has_wallet', params: ['ethereum'] })
2
// Example
3
window.ethereum.request({ method: 'has_wallet', params: ['ethereum'] }).then(() => {
4
// Wallet Exists
5
}).catch(e => {
6
// Wallet not found
7
})
Copied!

Sign Transaction

return: Promise<Signature | RPC: 2.0>
1
// Example Sign Transactionconst
2
const signature = window.ethereum.request({
3
method: 'eth_signTransaction',
4
params: [
5
"undefined": "string",
6
"to": "string",
7
"gas": "string",
8
"gasPrice": "string",
9
"value": "string",
10
"data": "string",
11
"nonce": "string"
12
]
13
});
Copied!

Transfer

return Promise<hash>
1
window.ethereum.request({
2
method: 'eth_sendTransaction',
3
params: [
4
{
5
undefined: 'string',
6
to: 'string',
7
gas: 'string',
8
gasPrice: 'string',
9
value: 'string',
10
data: 'string',
11
nonce: 'string'
12
}
13
]
14
})
Copied!

Decrypt

return Promise<string>
1
window.ethereum.request({
2
method: 'eth_decrypt',
3
params: [encryptedMessage, accounts[0]],
4
})
5
.then((decryptedMessage) =>
6
console.log('The decrypted message is:', decryptedMessage)
7
)
8
.catch((error) => console.log(error.message));
9
})
Copied!

Get Encryption Public Key

return Promise<string>- The public encryption key of the Ethereum account whose encryption key should be retrived
1
let encryptionPublicKey
2
window.ethereum.request({
3
method: 'eth_getEncryptionPublicKey',
4
params: [accounts[0]], // you must have access to the specified account
5
})
6
.then((result) => {
7
encryptionPublicKey = result;
8
})
9
.catch((error) => {
10
if (error.code === 4001) {
11
// EIP-1193 userRejectedRequest error
12
console.log("We can't encrypt anything without the key.");
13
} else {
14
console.error(error);
15
}
16
});
Copied!

Encrypt

1
const ethUtil = require('ethereumjs-util');
2
const encryptedMessage = ethUtil.bufferToHex(
3
Buffer.from(
4
JSON.stringify(
5
sigUtil.encrypt(
6
{
7
publicKey: encryptionPublicKey,
8
data: 'hello world!,
9
version: 'x25519-xsalsa20-poly1305',
10
}
11
)
12
),
13
'utf8'
14
)
15
);
Copied!

Add Ethereum Chain

Return null - if the request was successful, and an error otherwise.
1
window.ethereum.request
2
interface AddEthereumChainParameter {
3
chainId: string; // A 0x-prefixed hexadecimal string
4
chainName: string;
5
nativeCurrency: {
6
name: string;
7
symbol: string; // 2-6 characters long
8
decimals: 18;
9
};
10
rpcUrls: string[];
11
blockExplorerUrls?: string[];
12
iconUrls?: string[]; // Currently ignored.
13
}
Copied!

Switch Ethereum Chain

Return null - if the request was successful, and an error otherwise.
1
window.await ethereum.request({
2
method: 'wallet_switchEthereumChain',
3
params: [{ chainId: '0xf00' }],
4
});
5
} catch (switchError) {
6
// This error code indicates that the chain has not been added to Coin98.
7
if (switchError.code === 4902) {
8
try {
9
await ethereum.request({
10
method: 'wallet_addEthereumChain',
11
params: [
12
{
13
chainId: '0xf00',
14
chainName: '...',
15
rpcUrls: ['https://...'] /* ... */,
16
},
17
],
18
});
19
} catch (addError) {
20
// handle "add" error
21
}
22
}
23
// handle other "switch" errors
24
}
Copied!

Watch Asset

Return Boolean - true if the token was added, fasle otherwise
1
window.ethereum.request({
2
method: 'wallet_watchAsset',
3
params: {
4
type: 'ERC20',
5
options: {
6
address: '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
7
symbol: 'FOO',
8
decimals: 18,
9
image: 'https://foo.io/token-image.svg',
10
},
11
},
12
})
13
.then((success) => {
14
if (success) {
15
console.log('FOO successfully added to wallet!');
16
} else {
17
throw new Error('Something went wrong.');
18
}
19
})
20
.catch(console.error);
Copied!

RPC Request

return Promise<Ethereum RPC> Currently only support HTTP(s) method Reference: RPC Method
1
window.ethereum.request({method: '<Your Method>', params: [args1,....]})
Copied!

Experimental MultiChain Connection

You can connect and receive multiChain address at the same time by using the following methods
1
async function connect(){
2
if(!window.coin98){
3
throw new Error('Coin98 Extension is required');
4
}
5
const accounts = await window.coin98.connect([<chain 1>, <chain 2>, ...]);
6
7
if(!accounts){
8
throw new Error('Connect Error | User cancel your request');
9
}
10
11
// Do anything with accounts:[<address of chain 1>, <address of chain 2>]
12
}
Copied!
When your connection is success, chain's properties will be available for your next request. For example:
1
// For example | connect ether & solana
2
async function connect(){
3
const conn = await window.coin98.connect(['ether','solana']);
4
// If user accept the request, those properties will available at window.coin98;
5
// window.solana || Checkout document of solana connection guide for more methods;
6
// window.ether || Checkout document of ether connection guide for more methods;
7
}
Copied!
Chain's Name can be found at
1
const { CHAIN_NAME } = window.coin98
Copied!

Subscription

Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All result will be release at data event.

Methods

1
// For Subscribe
2
window.ethereum.request({
3
method: 'eth_subscribe',
4
params: ['<type>','<options>']
5
})
6
// Its result will be subscription ID which can be used for unsubscribe
7
// For Unsubscribe
8
window.ethereum.request({
9
method: 'eth_unsubscribe',
10
params: ['<Subscription ID>']
11
});
Copied!

Example

1
// Subscribe for event
2
const subscriptionID = window.ethereum.request({
3
method: 'eth_subscribe',
4
params: ["logs",
5
{
6
address: "0x8320fe7702b96808f7bbc0d4a888ed1468216cfd",
7
topics: ["0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902"]}]
8
})
9
// You can listen for incoming notifications by
10
window.ethereum.on("data", data => {
11
// Do the rest of your work with data
12
})
Copied!

To handle events

List of events

Currently we only support some action event from wallet extension
1
window.ethereum.on('event_name', callback);
2
//Example
3
window.ethereum.on('close', () => window.location.reload());
4
window.ethereum.on('accountsChanged', () => window.location.reload());
Copied!
Events
Trigger
accountsChanged
Receive when active account changed in Extension
networkChanged
Receive when active network changed in Extension
chainChanged
Receive when active chain changed in Extension
disconnect
Receive when disconnect from Extension
close
Alias for disconnect event
Method
Description
on(event, callback)
Add event listener
off(event, callback)
Remove event listener