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:
IMA.js
IMA.JS is a Typescirpt/Javascript library which implements client for SKALE Interchain Messaging Agent (IMA).
Implementation Example
Package Install
Usage
Initialization
There are 2 ways to use IMA.js library in your project:
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:
Accessing Mainnet and Schain parts:
ima.mainnet
- equals toMainnetChain
objectima.schain
- equals toSchain
objectWorking with 2 separate objects
Import and init Mainnet object:
Import and init Schain object:
ETH and token transfers
Detailed documentation about ETH and token transfers using IMA-JS can be found here:
missing link
missing link
missing link
missing link
Signing transactions
There are 2 ways to sign a transaction in the current version of IMA-JS:
Signing with private key
To sing and send a transaction using local private key you should specify
privateKey
andaddress
in thetxOpts
object:Signing with Metamask
Just drop
privateKey
from thetxOpts
object to trigger external signing, keepaddress
field: