Quick Start

Kirobo FCT-SDK Documentation

Welcome to the Kirobo FCT-SDK documentation! This SDK is designed to simplify interactions with Kirobo services and blockchain resources.

Table of Contents

  1. 1.
  2. 2.
  3. 4.
  4. 5.
    Examples

Introduction

The Kirobo FCT-SDK is a powerful tool for developers to interact with Kirobo.io services and blockchain resources. The SDK provides an easy-to-use interface for managing FCTs, wallets, tokens, NFTs, and more.

Installation

To install the SDK, run the following command in your project directory:
npm i @kiroboio/ki-fct-sdk
or
yarn add @kiroboio/ki-fct-sdk

Getting Started

First, import the SDK and create a new ethers.Wallet instance with the private key and provider:
const ethers = require('ethers');
const { service } = require('@kiroboio/ki-fct-sdk');
const PRIVATE_KEY = '<your-private-key>';
const signer = new ethers.Wallet(
PRIVATE_KEY,
ethers.getDefaultProvider({ chainId: 5, name: 'goerli' })
);
Then, configure the SDK by providing the key, secret, and signer:
service.start({
key: 'kirobo',
secret: 'kirobodev',
});
service.config({ signer, autoLogin: true });

API Reference

Service

  • service.start(config): Start the service with the given configuration.
  • service.config(options): Configure the service with the given options.
  • service.session: Contains session information, such as wallet and vault.
  • service.network: Contains network information, such as height, gas price, and KIRO price.

Tokens

  • service.tokens.wallet: Provides access to wallet token data.
  • service.tokens.vault: Provides access to vault token data.

NFTs

  • service.nfts.wallet: Provides access to wallet NFT data.
  • service.nfts.vault: Provides access to vault NFT data.

FCT

  • service.fct.fuel: Contains fuel information, both raw and formatted.
  • service.fct.active: Contains the active list of FCT resources.

Examples

Below are some examples to help you get started with the SDK:
  1. 1.
    Log network information:
effect(() => console.log('tip', service.network.value));
  1. 2.
    Log wallet and vault addresses:
effect(() => console.log('wallet', service.session.wallet.value));
effect(() => console.log('vault', service.session.vault.value));
  1. 3.
    Log wallet and vault token balances:
effect(() =>
console.log(
JSON.stringify(service.tokens.wallet.raw.list.value, null, 2),
JSON.stringify(service.tokens.wallet.formatted.list.value, null, 2)
)
);
effect(() =>
console.log(
JSON.stringify(service.tokens.vault.raw.list.value, null, 2),
JSON.stringify(service.tokens.vault.formatted.list.value, null, 2)
)
);
  1. 4.
    Log wallet and vault NFTs:
effect(() => console.log('[email protected]', service.nfts
  1. 5.
    Log fuel information:
effect(() => console.log('fuel raw', JSON.stringify(service.fct.fuel.raw.value, null, 2)));
effect(() => console.log('fuel formatted', JSON.stringify(service.fct.fuel.formatted.value, null, 2)));
  1. 6.
    Log the active list of FCT resources:
effect(() => console.log('active list', service.fct.active.raw.list.value));
  1. 7.
    Log values using signals and computed properties:
const x = signal({ value: 0, nested: { value: 0 } });
effect(() => console.log('asd x', x.value));
const value = computed(() => x.value.value);
const nested = computed(() => x.value.nested.value);
effect(() => console.log('asd value', value.value));
effect(() => console.log('asd nested', nested.value));
  1. 8.
    Log session status:
effect(() => console.log('asd session status', service.session.status));
These examples demonstrate various ways to interact with the KiroboIO KI-FCT-SDK. You can use them as a starting point for building your own applications and services with the SDK.

API Reference

Service

  • service.start(config): Start the service with the given configuration. The configuration object should include the key and secret for the KiroboIO API.
    • config: Object with the following properties:
      • key: String, the KiroboIO API key.
      • secret: String, the KiroboIO API secret.
  • service.config(options): Configure the service with the given options. The options object should include the signer and optionally an autoLogin boolean.
    • options: Object with the following properties:
      • signer: ethers.Wallet instance, the signer for the wallet.
      • autoLogin: Boolean (optional), set to true to automatically log in upon configuration. Default is false.
  • service.session: Contains session information, such as wallet and vault.
    • wallet: Wallet address associated with the signer.
    • vault: Vault address associated with the signer.
    • status: Session status, representing the connection state.
  • service.network: Contains network information, such as height, gas price, and KIRO price.
    • height: Number, the current block height of the network.
    • gasPrice: Number, the current gas price in the network.
    • kiroPrice: Number, the current price of KIRO token in the network.

Tokens

  • service.tokens.wallet: Provides access to wallet token data.
    • raw.list: Array, a list of raw token data in the wallet.
    • formatted.list: Array, a list of formatted token data in the wallet.
  • service.tokens.vault: Provides access to vault token data.
    • raw.list: Array, a list of raw token data in the vault.
    • formatted.list: Array, a list of formatted token data in the vault.

NFTs

  • service.nfts.wallet: Provides access to wallet NFT data.
    • raw.list: Array, a list of raw NFT data in the wallet.
  • service.nfts.vault: Provides access to vault NFT data.
    • raw.list: Array, a list of raw NFT data in the vault.

FCT

  • service.fct.fuel: Contains fuel information, both raw and formatted.
    • raw: Object, raw fuel data.
    • formatted: Object, formatted fuel data.
  • service.fct.active: Contains the active list of FCT resources.
    • raw.list: Array, a list of raw active FCT resources.

Utility Functions

  • computed(fn): Creates a computed property based on the provided function. The function should return a value based on the SDK's reactive properties.
    • fn: Function, a function that returns a value based on the SDK's reactive properties.
  • effect(fn): Executes the provided function when the reactive properties used within it change.
    • fn: Function, a function that uses the SDK's reactive properties.
  • signal(initialValue): Creates a reactive signal with the provided initial value. The signal can be used in computed properties and effects.
    • initialValue: Any, the initial value of the signal.

Examples

To help you better understand how to use the SDK, here are some additional examples:
  1. 9.
    Update a signal value:
const mySignal = signal(0);
effect(() => console.log('Signal value', mySignal.value));
// Update the signal value
mySignal.value = 42;
  1. 10.
    Update a signal value with a nested object:
const myNestedSignal = signal({ value: 0, nested: { value: 0 } });
effect(() => console.log('Nested signal value', myNestedSignal.value));
// Update the signal value
myNestedSignal.value = { value: 42, nested: { value: 24 } };
  1. 11.
    Listen to changes in a specific token balance:
const kiroBalance = computed(
() => service.tokens.wallet.formatted.list.value.find((t) => t.symbol === 'KIRO').balance
);
effect(() => console.log('KIRO balance', kiroBalance.value));
  1. 12.
    Transfer tokens from wallet to vault:
const transferTokens = async (tokenAddress, amount) => {
try {
const result = await service.tokens.wallet.transfer({
recipient: service.session.vault.value,
token: tokenAddress,
amount: amount,
});
console.log('Transfer successful', result);
} catch (error) {
console.error('Transfer failed', error);
}
};
// Replace with the token address and amount you want to transfer
const tokenAddress = '<token-address>';
const amount = '<amount>';
transferTokens(tokenAddress, amount);
  1. 13.
    Transfer NFTs from wallet to vault:
const transferNFT = async (nftAddress, tokenId) => {
try {
const result = await service.nfts.wallet.transfer({
recipient: service.session.vault.value,
nft: nftAddress,
tokenId: tokenId,
});
console.log('Transfer successful', result);
} catch (error) {
console.error('Transfer failed', error);
}
};
// Replace with the NFT address and token ID you want to transfer
const nftAddress = '<nft-address>';
const tokenId = '<token-id>';
transferNFT(nftAddress, tokenId);
These examples demonstrate various ways to interact with the KiroboIO KI-FCT-SDK. You can use them as a starting point for building your own applications and services with the SDK.
Last modified 25d ago