Skip to content

Latest commit

 

History

History
192 lines (127 loc) · 5.25 KB

typedoc_template.md

File metadata and controls

192 lines (127 loc) · 5.25 KB

< Back home

iExec SDK Library API

npm version npm version license

Use the iExec decentralized marketplace for off-chain computing in your dapp.

Content


Install

Install iexec sdk

npm install iexec

Quick start

Front-end integration

import { IExec } from 'iexec';

// connect injected provider
const iexec = new IExec({ ethProvider: window.ethereum });

Read more about popular bundlers integration

Back-end integration

import { IExec, utils } from 'iexec';

const { PRIVATE_KEY } = process.env;

const ethProvider = utils.getSignerFromPrivateKey(
  'http://localhost:8545', // blockchain node URL
  PRIVATE_KEY,
);
const iexec = new IExec({
  ethProvider,
});

API

IExecModules

IExec SDK is split into IExecModules, each providing a set of methods relatives to a specific field.

Additionally the IExec module exposes all the following listed modules under the corresponding namespace.

Imports

As your app won't probably use all the features, you may want to import only the modules you need.

Each module is available as an independent package under iexec/MODULE_NAME and is exported in the umbrella package.

example:

  • import from module package
import IExecWalletModule from 'iexec/IExecWalletModule';
  • import from umbrella
import { IExecWalletModule } from 'iexec';

Usage

IExecModules are instantiated with an IExecConfig providing the configuration to access to a specific instance of the iExec platform.

Once created, an IExecConfig can be shared with any IExecModule.

example:

  • standard usage
import IExecConfig from 'iexec/IExecConfig';

import IExecWalletModule from 'iexec/IExecWalletModule';
import IExecAccountModule from 'iexec/IExecAccountModule';

// create the config once for the target iExec instance
const config = new IExecConfig({ ethProvider: window.ethereum });

// share it with all the modules
const wallet = IExecWalletModule.fromConfig(config);
const account = IExecAccountModule.fromConfig(config);
  • reuse instantiated module configuration
import IExecWalletModule from 'iexec/IExecWalletModule';
// some IExecModule instance
import iexecModule from './my-module';

// IExecModules expose their IExecConfig under config
const wallet = IExecWalletModule.fromConfig(iexecModule.config);
  • quick instantiation (shorter but not recommended)
import IExecWalletModule from 'iexec/IExecWalletModule';

// the IExecConfig step can be skipped
const wallet = new IExecWalletModule({ ethProvider: window.ethereum });

utils

The utils namespace exposes some utility methods.

example:

import utils from 'iexec/utils';

Or

import { utils } from 'iexec';

errors

The errors namespace exposes the errors thrown by the library, use them if you want specific error handling.

example:

import errors from 'iexec/errors';

Or

import { errors } from 'iexec';

Live demos


< Back home