Development with IMA-SDK

IMA-SDK is a tool for dApp developers that emulates SKALE Node + IMA env on a single machine for dev purposes. This article will demonstrate how to setup and use the IMA-SDK in combination with IMA-JS library for dApp development.

The IMA SDK provides a locally hosted environment for developing with the SKALE IMA Bridge. Two chains are provided on different ports: on Ganache 8545, the Ethereum side IMA contracts such as DepositBoxes are deployed, and on SKALED Port 15000, the SKALE Chain side IMA contracts such as TokenManagers are deployed.

This IMA SDK works for Mac, Windows, and 64-bit Linux.

This is everything you need to develop a full dApp on SKALE with IMA Bridge and Filestorage.

What you get:

  • A SKALE Chain endpoint

  • An Ethereum Chain (Ganache) endpoint

  • Deployed IMA contracts on Ethereum (mainnet)

  • Deployed IMA contracts on SKALE Chain

  • 10GB of SKALE Filestorage

  • Web3 server

Overview of the IMA SDK

Get Started with the IMA SDK

  1. Ensure that the following prerequisites are installed:

  2. Clone the IMA SDK repository

    git clone https://github.com/skalenetwork/skale-ima-sdk
    cd skale-ima-sdk
  3. Copy the .env template and add your accounts:

    cp .env-compose-sample .env
    nano .env
  4. Export the environment variables:

    export $(grep -v '^#' .env | xargs)
  5. (OPTIONAL) Place SSL cert & key in ssl folder:

    Names must be ssl_key and ssl_cert:
    cp privkey.pem ~/skale-ima-sdk/ssl/ssl_key
    cp cert.pem ~/skale-ima-sdk/ssl/ssl_cert
  6. (OPTIONAL) Add additional accounts

    This step is optional. Proceed to the next step if you need only 1 account with funds.

    You can pass any number of additional accounts to the SDK. All accounts will have pre-allocated ETH both on Mainnet and sChain sides. To do that add additional_accounts.json file in the root of the project. Structure of the file:

    [
        {
            "private_key": "0x...",
            "address": "0x.."
        },
        {
            "private_key": "0x...",
            "address": "0x.."
        }
        ...
    ]
  7. Startup the SDK and deploy IMA contracts to local ganache and Skaled:

    WAIT=True bash scripts/run_sdk.sh

    Output:

    Updating skaled configuration file
    Will load JSON file "/Users/cskale/Projects/skale-ima-sdk/config0.json"...
    Did loaded content of JSON file "/Users/cskale/Projects/skale-ima-sdk/config0.json", will parse it...
    Done, loaded content of JSON file "/Users/cskale/Projects/skale-ima-sdk/config0.json".
    Updated chainId: -4
    Address 0x66c5a87f4a49DD75e970055A265E8dd5C3F8f852 is already in accounts section
    Will save JSON file "/Users/cskale/Projects/skale-ima-sdk/config0.json"...
    Done, saved content of JSON file "/Users/cskale/Projects/skale-ima-sdk/config0.json".
    Done.
    Creating ima_sdk         ... done
    Creating ima_sdk_ganache ... done
    Mainnet contracts deployed: /Users/cskale/Projects/skale-ima-sdk/scripts/../contracts_data/proxyMainnet.json
    Waiting for sChain contracts 0/100
    Waiting for sChain contracts 1/100
    ...

    You can check that the ima_sdk_ganache, ima_sdk, and ima_sdk_nginx containers are up by executing:

    docker ps -a
  8. Wait for completion of IMA contract deployments and startup of the IMA Agent. You can check the progress as follows:

    docker logs ima_sdk_ganache

    You should see this final line in the log outputs: Listening on 0.0.0.0:8545

    docker logs ima_sdk

    And you should see this complete final output before using the sdk:

    ...
    Will start SKALE Chain...
    Successfully started SKALE Chain
    
    Will deploy IMA to Main Net...
    Successfully deployed IMA to Main Net...
    
    Will deploy IMA to S-Chain...
    Successfully deployed IMA to SKALE Chain...
    
    Will register IMA...
    Successfully registered IMA.
    
    Will start IMA agent transfer loop...
    Successfully started IMA agent transfer loop
    
    Press any key to stop this docker container

    You can also test the Ganache using geth attach:

    geth attach http://127.0.0.1:8545

    Should output:

    Welcome to the Geth JavaScript console!
    
    instance: EthereumJS TestRPC/v2.11.3-beta.0/ethereum-js
    coinbase: 0x98664cee8831d7a61d394d7e10207df074e5a895
    at block: 0 (Mon Aug 16 2021 14:58:31 GMT-0700 (PDT))
     modules: eth:1.0 evm:1.0 net:1.0 personal:1.0 rpc:1.0 web3:1.0

    And attaching to the SKALE chain:

    geth attach http://127.0.0.1:15000

    Should output:

    Welcome to the Geth JavaScript console!
    
    instance: skaled/3.7.3+commit.ecaa2572/linux/gnu7.5.0/debug
    coinbase: 0x66c5a87f4a49dd75e970055a265e8dd5c3f8f852
    at block: 40 (Mon Aug 16 2021 15:01:55 GMT-0700 (PDT))
     modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 skale:0.1 skaleDebug:1.0 skaleStats:1.0 web3:1.0

Working with the SDK

Access ABIs

The ABIs generated for the IMA contracts deployed to Ganache and the SKALE Chain are found here:

skale-ima-sdk/contracts_data/proxyMainnet.json # Mainnet part
skale-ima-sdk/contracts_data/proxySchain_Bob.json # SKALE Chain part

Endpoints

Use the following endpoints to deploy and transact with each chain.

# SKALE Chain
http://$IP_ADDRESS:15000
http://$DOMAIN_NAME/schain # if you have a domain name
https://$DOMAIN_NAME/schain # if you have SSL certs and domain name
# Ethereum (Ganache)
http://$IP_ADDRESS:1545
http://$DOMAIN_NAME/mainnet # if you have a domain name
https://$DOMAIN_NAME/mainnet # if you have SSL certs and domain name

IMA-JS integration

To start development of your dApp using IMA-SDK with IMA-JS refer to this doc.

Using the IMA Bridge

Please refer to the IMA Bridge documentation here.

Stopping the SDK

CLEANUP=True  bash scripts/stop_sdk.sh

Get a Domain Name

Get SSL Certificates

Troubleshooting

If you encounter any issues you can run cleanup and start from scratch:

CLEANUP=True  bash scripts/stop_sdk.sh

You can inspect the data_dir/all_ima_*.txt files for logs.