0.4.1 • Published 16 days ago

@doiim/tikua v0.4.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
16 days ago

Tikua

A Isomorphic JS Cartesi package to use with any visual library on Browser or Terminal. The SDK will support any provider or network. All configurable and allowing defining an app with multiple chains supported. The SDK should adapt accordingly to the configurations and raise warnings in cases of non-supported provider chains.

Installation

npm install -s @doiim/tikua

Usage

You can jump directly to our Examples folder and check how to implement Tikua on multiple platforms or check here the description of Tikua Class and its functions.

CartesiSDK

The Tikua class is the main entry point for this SDK. It is instantiated with the following parameters:

  • abi: The ABI of your dapp. Human Readable ABI definition
  • provider (optional): The EIP1193 provider to use. Needed for Input calls.
  • appAddress (optional): The address of your application deployed. Needed for Input calls.
  • appEndpoint (optional): The endpoint of your dapp. Needed for Inspect and Notices

  • waitBlocks: The amount of blocks to wait before considering an input sent. Defaults to 1.

  • signerAddress (optional): The account to sign transactions. Defaults to the first account returned from getAddresses() on the provider.
const abi = [
  "function attackDragon(uint256 dragonId, string weapon)",
  "function dragonStatus(uint256 dragonId) returns (uint256)",
];
const tikua = new Tikua({
  appAddress: "0x0123123",
  appEndpoint: "https://host.backend/",
  provider,
  abi,
});

sendInput(fn: string, args: any[])

Send a function input to the Cartesi contract.

  • fn: string: The name of the function to call.
  • args: any[]: An array of arguments to pass to the function.

Returns a promise that resolves to the transaction hash of the sent input.

const txHash = await tikua.sendInput("attackDragon", [1, "sword"]);

fetchInspect(id: string)

Fetch the inspect data for a transaction ID.

  • id: string: The ID of the transaction to fetch.
  • args: any[]: Array of arguments to be passed to function.
const status = await tikua.fetchInspect("dragonStatus", [dragonId]);

Returns a promise that resolves to the inspect data of the transaction.

addNoticesListener(pollInterval : number, fn: (report: any) => void)

Listen for all notices triggered by the Cartesi Machine

  • pollInterval: number: Time between each request to GraphQL.
  • fn: (report: any) => void: The function to call when a report is received.
const unsubscribe = await tikua.addNoticesListener(1000, (result) => {
  console.log(result);
});

addMyNoticesListener(pollInterval : number, account:Address, fn: (report: any) => void)

Listen for all notices triggered related to your address. This is similar to addNoticesListener, but it uses your configured address to filter the results.

  • pollInterval: number: Time between each request to GraphQL.
  • account: Address: The account to listen for notices.
  • fn: (report: any) => void: The function to call when a report is received.

Returns an unsubscribe function to stop listening for reports.

const myWallet = "0x0123123123123";
const unsubscribe = await tikua.addNoticesListener(1000, myWallet, (result) => {
  console.log(result);
});

Backend

For the backend we use a framework call Deroll. It uses a Typescript backend structure centralized in an ABI protocol same way Tikua. You can start from an example implementation on our Examples folder. There you will find a project using Deroll framework to talk with a frontend using Tikua. Deroll uses ABI for encode and decode function calls/responses, accelerating your development in multiple aspects. Both Deroll and Tikua are based on Viem library for encode and decode ABI calls.

References

Human Readable ABI definition Viem library Deroll

For Maintainers

To deploy a new version use:

npm run build
npm publish

To deploy a local version for tests use:

npm run build
npm pack
0.4.1

16 days ago

0.4.0

16 days ago

0.3.2

18 days ago

0.3.3

18 days ago

0.3.1

19 days ago

0.3.0

19 days ago