Access Key

To use KAS API, you have to create a default account and set authorization. Create your account on KAS Console, or use KAS SDKs Caver-js-ext-kas or Caver-java-ext-kas. On this page, we will show your how to use KAS SDK.

First set "chain id" and "Access Key". You can initialize them as shown below. Pass chainId, accessKeyId and secretAccessKey to the constructor and it will call the caver.initKASAPI function. This function will initialize the access keys used for Klaytn Node API, Wallet API, Token History API, Anchor API, KIP-17 API, KIP-7 API, and KIP-37 API all at once.

  • Set access key with constructor
    JavaScriptJava
    Copy
    Copied
    // Set authorization through constructor
    const caver = new CaverExtKAS(chainId, accessKeyId, secretAccessKey);
    Copy
    Copied
    // Set authorization through constructor
    CaverExtKAS caver = new CaverExtKAS(chain, accessKeyId, secretAccessKey);
  • Set access key with caver.initKASAPI
    JavaScriptJava
    Copy
    Copied
    // Set an authorization through 'caver.initKASAPI' function
    const caver = new CaverExtKAS();
    caver.initKASAPI(chainId, accessKeyId, secretAccessKey);
    Copy
    Copied
    // Set an authorization through 'caver.initKASAPI' function
    CaverExtKAS caver = new CaverExtKAS();
    caver.initKASAPI(chainId, accessKeyId, secretAccessKey);

Below you see the initialization processes for KAS API Service. You can optionally pass the endpoint URL in the pass parameter. Otherwise, it will be set to KAS Production URL as default.

KAS Production URL

JavaScriptJava
Copy
Copied
// Node API initial configuration
caver.initNodeAPI(chainId, accessKeyId, secretAccessKey [, useHttp] [, url])

// Wallet API initial configuration
caver.initWalletAPI(chainId, accessKeyId, secretAccessKey [, url])

// TokenHistory API initial configuration
caver.initTokenHistoryAPI(chainId, accessKeyId, secretAccessKey [, url])

// Anchor API initial configuration
caver.initAnchorAPI(chainId, accessKeyId, secretAccessKey [, url])

// KIP-17 API initial configuration
caver.initKIP17API(chainId, accessKeyId, secretAccessKey [, url])

// KIP-7 API initial configuration
caver.initKIP7API(chainId, accessKeyId, secretAccessKey [, url])

// KIP-37 API initial configuration
caver.initKIP37API(chainId, accessKeyId, secretAccessKey [, url])
Copy
Copied
// Node API initial configuration
caver.initNodeAPI(chainId, accessKeyId, secretAccessKey [, url])

// Wallet API initial configuration
caver.initWalletAPI(chainId, accessKeyId, secretAccessKey [, url])

// TokenHistory API initial configuration
caver.initTokenHistoryAPI(chainId, accessKeyId, secretAccessKey [, url])

// Anchor API initial configuration
caver.initAnchorAPI(chainId, accessKeyId, secretAccessKey [, url])

// KIP-17 API initial configuration
caver.initKIP17API(chainId, accessKeyId, secretAccessKey [, url])

// KIP-7 API initial configuration
caver.initKIP7API(chainId, accessKeyId, secretAccessKey [, url])

// KIP-37 API initial configuration
caver.initKIP37API(chainId, accessKeyId, secretAccessKey [, url])

Create and Get Account

You can create an account using KAS Wallet API as shown below:

JavaScriptJava
Copy
Copied
const CaverExtKAS = require("caver-js-ext-kas");
const caver = new CaverExtKAS(chainId, accessKeyId, secretAccessKey);

const account = await caver.kas.wallet.createAccount();
console.log(account);
Copy
Copied
import xyz.groundx.caver_ext_kas.CaverExtKAS;
import xyz.groundx.caver_ext_kas.rest_client.io.swagger.client.ApiException;
import xyz.groundx.caver_ext_kas.rest_client.io.swagger.client.api.wallet.model.Account;

public class HelloKAS {
    public static void createAccount() throws ApiException {
        CaverExtKAS caver = new CaverExtKAS();
        caver.initKASAPI(chainId, accessKeyId, secretAccessKey);

        Account account = caver.kas.wallet.createAccount();
        System.out.println(account);
    }

    public static void main(String[] args) throws ApiException {
        createAccount();
    }
}

Running the above code returns the following account information:

JavaScriptJava
Copy
Copied
Account {
  address: '0x4d6de1Fe6a281306C54AD81b79a0c137b13872DC',
  chainId: 1001,
  createdAt: 1602124416,
  keyId: 'krn:1001:wallet:9c42dff5-d317-4abd-a7ab-576aad12ea07:account-pool:default:0x975fa77efbde347b0c471f0f29ba73c1281521f69485d650c8c10125e37b57fc',
  krn: 'krn:1001:wallet:9c42dff5-d317-4abd-a7ab-576aad12ea07:account-pool:default',
  publicKey: '0x0433f1b15d33e821155988408e949d21d5bd0d053d9f2ed90f3df57e96f0ce7a766ba36617f43f2ad1e0f3caca5bdb431a88c51c1bdaab8dc781589b1658e646f1',
  updatedAt: 1602124416
}
Copy
Copied
class Account {
    address: 0x0BA67C887F922AF3d0D781dD940c6d0C80D395DE
    chainId: 1001
    createdAt: 1602550121
    keyId: krn:1001:wallet:d5c346f5-bb80-4f45-9093-57e25205cdc8:account-pool:pool:0xbedefad10db4df3488aaf1669b9164549c1aebe7c326f4b19ba6c6ce0f330fa5
    krn: krn:1001:wallet:d5c346f5-bb80-4f45-9093-57e25205cdc8:account-pool:pool
    publicKey: 0x041d56cbe46915854600c9d3c4ef614906f27473abe948cf587d990dcbce030d5989f4458bc470e44b2916d75194729102bb60e1e6a27c01030de84208a13232c2
    updatedAt: 1602550121
    multiSigKeys: null
    threshold: null
}

If you have any inquiries on this document or KAS in general, please visit KAS Developers Forum.