Kinetic TypeScript SDK
Learn how to use the Kinetic TypeScript SDK
Installation
yarn add @kin-kinetic/sdk @kin-kinetic/keypair @kin-kinetic/solana
Initialize SDK
Initialise the SDK so that you have access to all of Kinetic's methods.
import { KineticSdk, KineticSdkConfig } from '@kin-kinetic/sdk'
// Note - this example is using a demo app on the Kinetic Sandbox provided by the Kin Foundation.
const config: KineticSdkConfig = {
endpoint: 'https://sandbox.kinetic.host',
environment: 'devnet',
index: 1
}
// Note - Setting up the Kinetic SDK is an async action
const sdk: KineticSdk = await KineticSdk.setup(config)
If you're self-hosting Kinetic, you can include an optional endpoint value pointing at your server.
Here's the config Type for reference:
export interface KineticSdkConfig {
index: number;
endpoint: string;
environment: KineticSdkEnvironment;
headers?: Record<string, string>;
logger?: KineticSdkLogger;
solanaRpcEndpoint?: string;
}
Generate a Keypair
A Keypair contains a 'secretKey' that you can use to sign transactions and a 'publicKey' that you can use as an address for paying towards or checking a balance, etc.
Using Keypair.random()
will also return a mnemonic that you can use to recreate you wallet in other applications / wallets should you choose to do so.
import { Keypair } from '@kin-kinetic/keypair'
const keypair = Keypair.random()
const { mnemonic, secretKey, publicKey } = keypair;
Create a Kin Account
Use your keypair to create your account on the Solana blockchain.
const account = await sdk.createAccount({ owner: keypair })
Generate your keypair from your mnemonic for an existing account:
const keypair = Keypair.fromMnemonic(mnemonic);
Use the SDK with the Keypair
Get the balance
Use a publicKey to check your Kin balance.
const balance = await sdk.getBalance({ account: keypair.publicKey })
Request an Airdrop
Send Kin to a publicKey on the Solana devnet.
Airdrops take some time to complete as we make sure the transaction has been confirmed on the blockchain before returning a response.
const signature = await sdk.requestAirdrop({ account: keypair.publicKey, amount: '1000' })
Make a Transfer
Send Kin from a Keypair (as you need the privateKey) to a publicKey on the blockchain.
You can optionally set the commitment level before returning ('Confirmed', 'Finalized' or Processed), the transaction type, or add a referenceId / referenceType.
const result = await sdk.makeTransfer({
amount: "42",
destination: "ALisrzsaVqciCxy8r6g7MUrPoRo3CpGxPhwBbZzqZ9bA",
owner: keypair,
})
Here's the makeTransfer Type for reference:
export interface TransferDestination {
amount: string
destination: PublicKeyString
}
export interface MakeTransferOptions extends TransferDestination {
commitment?: Commitment;
mint?: string;
owner: Keypair;
referenceId?: string;
referenceType?: string;
senderCreate?: boolean;
type?: TransactionType;
}