Quick Start
Welcome to the Kirobo FCT-SDK documentation! This SDK is designed to simplify interactions with Kirobo services and blockchain resources.
- 1.
- 2.
- 3.
- 4.
- 5.
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.
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
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 });
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.
service.tokens.wallet
: Provides access to wallet token data.service.tokens.vault
: Provides access to vault token data.
service.nfts.wallet
: Provides access to wallet NFT data.service.nfts.vault
: Provides access to vault NFT data.
service.fct.fuel
: Contains fuel information, both raw and formatted.service.fct.active
: Contains the active list of FCT resources.
Below are some examples to help you get started with the SDK:
- 1.Log network information:
effect(() => console.log('tip', service.network.value));
- 2.Log wallet and vault addresses:
effect(() => console.log('wallet', service.session.wallet.value));
effect(() => console.log('vault', service.session.vault.value));
- 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)
)
);
- 4.Log wallet and vault NFTs:
effect(() => console.log('[email protected]', service.nfts
- 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)));
- 6.Log the active list of FCT resources:
effect(() => console.log('active list', service.fct.active.raw.list.value));
- 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));
- 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.
service.start(config)
: Start the service with the given configuration. The configuration object should include thekey
andsecret
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 thesigner
and optionally anautoLogin
boolean.options
: Object with the following properties:signer
: ethers.Wallet instance, the signer for the wallet.autoLogin
: Boolean (optional), set totrue
to automatically log in upon configuration. Default isfalse
.
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.
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.
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.
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.
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.
To help you better understand how to use the SDK, here are some additional examples:
- 9.Update a signal value:
const mySignal = signal(0);
effect(() => console.log('Signal value', mySignal.value));
// Update the signal value
mySignal.value = 42;
- 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 } };
- 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));
- 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);
- 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