FCTs

Active Module

This module defines functions for handling active services in an FCT application. It provides an API for interacting with active fcts, such as publishing, removing, and adding signatures to them. This document contains code examples to help you understand how to use the functions defined in the module.

Importing Dependencies

First, you need to import the required dependencies from the appropriate packages:

import KiroboService from '@kiroboio/fct-sdk';

Publish a New FCT

To publish a new active service, use the publish.execute function. It takes an object with data, serial, autoSign, and autoClear properties.

const data = {
  // Data for the new active service
};

fct.active.publish.execute({
  data,
  serial: true,
  autoSign: true,
  autoClear: 2000,
})
  .then(() => {
    console.log('Active service published successfully');
  })
  .catch((error) => {
    console.error('Error publishing active service:', error);
  });

Remove an Active Service

To remove an active service, use the remove.execute function. It takes an object with the id of the active service you want to remove.

id = 'fct-id'; // Replace with the actual ID

fct.active.remove.execute({ id })
  .then(() => {
    console.log('Active service removed successfully');
  })
  .catch((error) => {
    console.error('Error removing active service:', error);
  });

Add Signature to an Active Service

To add a signature to an active service, use the addSignature.execute function. It takes an object with the id of the active service and the signature you want to add.

const id = 'fct-id'; // Replace with the actual ID
const signature = 'signature'; // Replace with the actual signature

fct.active.addSignature.execute({ id, signature })
  .then(() => {
    console.log('Signature added to active service successfully');
  })
  .catch((error) => {
    console.error('Error adding signature to active service:', error);
  });

Update Active Services List

To update the list of active services, use the updateActiveList function. It will fetch the updated list of active services and rebuild the raw and formatted active lists.

updateActiveList()
  .then(() => {
    console.log('Active services list updated successfully');
  })
  .catch((error) => {
    console.error('Error updating active services list:', error);
  });

By following these examples, you can interact with active services using the functions provided in the module.

History

Fuel Module

The fuel module is responsible for interacting with the Kirobo Service to manage funds and fuel usage for the Kirobo network.

Imports

import KiroboService from '@kiroboio/fct-sdk';

Constants and Variables

  • SERVICE: A constant for the fuel service name.

  • ENDPOINT: A constant for the fuel endpoint.

  • _callId: A variable to track the call ID.

  • INIT_FUEL: An initial fuel object with default values.

  • watchedNetworkName: A variable to store the currently watched network name.

Functions

formatFuelValue

Formats the fuel value for the given name.

Parameters:

  • value: string: The value to be formatted.

  • name: string: The name of the fuel (e.g., 'kiro', 'eth').

Returns: The formatted fuel value.

formatFuel

Formats a fuel object, calling formatFuelValue for each value in the object.

Parameters:

  • res: IFunds: The fuel object to be formatted.

Returns: The formatted fuel object.

fuel

An object containing two signals, raw and formatted, representing the raw and formatted fuel data, respectively.

networkName

A computed value representing the current network name.

unwatchFuel

An async function that removes all event listeners for the current network endpoint and resets the fuel data.

updateFuel

Updates the fuel object with the new data.

Parameters:

  • res: IFunds: The new fuel data.

watchFuel

An async function that watches for changes in the network name, and updates the fuel data accordingly. It also listens for updates to the fuel data from the Kirobo Service.

Usage Example

To watch for fuel updates and get the formatted fuel data, you can use the following example:

import { fuel, watchFuel } from './fuel';

// Start watching for fuel updates
await watchFuel();

// Access the formatted fuel data
console.log(fuel.formatted.value);

To stop watching for fuel updates, you can use the unwatchFuel function:

import { unwatchFuel } from './fuel';

// Stop watching for fuel updates
await unwatchFuel();

Last updated