Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMA.js #57

Open
Tracked by #13
manuelbarbas opened this issue Dec 22, 2023 · 2 comments
Open
Tracked by #13

IMA.js #57

manuelbarbas opened this issue Dec 22, 2023 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@manuelbarbas
Copy link
Collaborator

manuelbarbas commented Dec 22, 2023

IMA.js

IMA.JS is a Typescirpt/Javascript library which implements client for SKALE Interchain Messaging Agent (IMA).

Implementation Example

Package Install

npm install --save @skalenetwork/ima-js

Usage

Initialization

There are 2 ways to use IMA.js library in your project:

  • As a single object that contains both Mainnet and Schain (SKALE chain) parts
  • Use Mainnet and Schain objects separately

First approach is more convenient in general because single IMA object have simplified API for some functionality that
requires both Mainnet and Schain interactions, but in this case you will need two web3 objects to be available at the same time.

Second approach is more flexible but requires more developer work in some cases.

Working with a single IMA object

Import and init single IMA-JS object:

import { IMA } from '@skalenetwork/ima-js';

import mainnetAbi from './mainnetAbi.json'; // your local sources
import schainAbi from './schainAbi.json'; // your local sources

const MAINNET_ENDPOINT = '[YOUR_ETHEREUM_MAINNET_ENDPOINT]';
const SCHAIN_ENDPOINT = '[YOUR_SCHAIN_ENDPOINT]';

const mainnetWeb3 = new Web3(MAINNET_ENDPOINT);
const sChainWeb3 = new Web3(SCHAIN_ENDPOINT);

let ima = new IMA(mainnetWeb3, sChainWeb3, mainnetAbi, sChainAbi);

Accessing Mainnet and Schain parts:

  • Mainnet: ima.mainnet - equals to MainnetChain object
  • sChain: ima.schain - equals to Schain object

Working with 2 separate objects

Import and init Mainnet object:

import { MainnetChain } from '@skalenetwork/ima-js';
import mainnetAbi from './mainnetAbi.json'; // your local sources

const MAINNET_ENDPOINT = '[YOUR_ETHEREUM_MAINNET_ENDPOINT]';
const mainnetWeb3 = new Web3(MAINNET_ENDPOINT);

let mainnet = new MainnetChain(mainnetWeb3, mainnetAbi);

Import and init Schain object:

import { SChain } from '@skalenetwork/ima-js';
import schainAbi from './schainAbi.json'; // your local sources

const SCHAIN_ENDPOINT = '[YOUR_SCHAIN_ENDPOINT]';
const sChainWeb3 = new Web3(SCHAIN_ENDPOINT);

let schain = new SChain(sChainWeb3, schainAbi);

ETH and token transfers

Detailed documentation about ETH and token transfers using IMA-JS can be found here:

  • [ETH transfers] missing link
  • [ERC20 token transfers] missing link
  • [ERC721 token transfers] missing link
  • [ERC1155 token transfers] missing link

Signing transactions

There are 2 ways to sign a transaction in the current version of IMA-JS:

  • Signing directly with private key
  • Signing with an external provider (currently only Metamask is supported)

Signing with private key

To sing and send a transaction using local private key you should specify privateKey and address in the txOpts object:

// init ima object

const txOpts = {
    address: "[ADDRESS]",
    privateKey: "[PRIVATE_KEY]"
}

this.state.sChain.withdrawETH(
    receiverAddress,
    amountWei,
    txOpts
);

Signing with Metamask

Just drop privateKey from the txOpts object to trigger external signing, keep address field:

// init ima object

const txOpts = {
    address: "[ADDRESS]"
}

this.state.sChain.withdrawETH(
    receiverAddress,
    amountWei,
    txOpts
);
@manuelbarbas
Copy link
Collaborator Author

Missing the section "ETH and token transfers" due to broken links

@manuelbarbas
Copy link
Collaborator Author

What is: Tool
Language: Javascript, Typescript
Target: Web

@manuelbarbas manuelbarbas added the documentation Improvements or additions to documentation label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant