Skip to main content

๐Ÿ‘ค Account

Let's create the claimer and the attester account.

In KILT, there is an account which is an object that interacts with the blockchain.

An accounts contains multiple properties.
One of them is the address : it's the entity's unique and public on-chain identifier.

KILT Account

A KILT account is a set of cryptographic elements:

  • The address, which is generated from the public key
  • A signing keypair write transactions on-chain

All we need to create an account is a mnemonic.

mnemonic

In cryptography, a mnemonic usually consists of 12 or 24 random series of words. For example, gold upset segment cake universe is a mnemonic. It's used to generate signing keypairs. What's great about a mnemonic is that it's human-readable. A person can memorize it, and use it later to re-generate their keypairs and address.

Create a file

Create a new file account.js. All of the code for this step needs to go into this file.

Code

To generate an account, one method from the KILT SDK is needed and one method from the polkadot crypto utility:

  • mnemonicGenerate() // Generates a mnemonic
  • buildFromMnemonic(mnemonic) // takes a mnemonic as an input, and outputs an Account instance.

Open account.js and paste the following code:

import * as Kilt from '@kiltprotocol/sdk-js'

import { mnemonicGenerate } from '@polkadot/util-crypto'

export function main() {
const mnemonic = mnemonicGenerate()
console.log('mnemonic:', mnemonic)

const keyring = new Kilt.Utils.Keyring({
ss58Format: 38,
type: 'ed25519',
})
const account = keyring.addFromMnemonic(mnemonic)
console.log('address:', account.address)
}

You're now ready to generate an account.

Run

To generate an account, run this command in your terminal, still within your kilt-rocks directory:

node account.js

Your output should look like this (but it won't be identical since the mnemonic is randomly generated):

Mnemonic: gold upset segment cake universe carry demand comfort dawn invite element capital
Address: 5CUoo2vAegeaZHPNdxZyuMesR3RWYBKHj4jfVyj4FXzpXPuR

You want to run this command twice, in order to generate 2 accounts: the attester's and the claimer's. Hence, replace the content of account.js with the following code:

import * as Kilt from '@kiltprotocol/sdk-js'

import { mnemonicGenerate } from '@polkadot/util-crypto'

export function main() {
const keyring = new Kilt.Utils.Keyring({
ss58Format: 38,
type: 'ed25519',
})
const claimerMnemonic = mnemonicGenerate()
console.log('claimer mnemonic:', claimerMnemonic)
const claimer = keyring.addFromMnemonic(claimerMnemonic)
console.log('claimer address:', claimer.address)

const attesterMnemonic = mnemonicGenerate()
console.log('attester mnemonic:', attesterMnemonic)
const attester = keyring.addFromMnemonic(attesterMnemonic)
console.log('attester address:', attester.address)
return { claimer, attester, attesterMnemonic }
}

Copy and paste the two mnemonics and addresses somewhere, you'll need them soon.

In the next steps, we'll refer to the so-generated accounts as follows:

  • <claimerMnemonic> is the mnemonic for the claimer and <claimerAddress> the claimer's associated address;
  • <attesterMnemonic> is the mnemonic for the attester and <attesterAddress> the attester's associated address.

That's it - You've successfully generated two new on-chain accounts and their associated addresses!