@coolwallet/iotx
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

CoolWallet IoTex SDK

This is a typescript library with support for the integration of IoTex for third party application, include the functionalities of generation of addresses and signed transactions.

Install

npm install @coolwallet/iotx

Usage

import Iotx, { Options } from '@coolwallet/iotx';
import { crypto } from '@coolwallet/core';
import { createTransport } from '@coolwallet/transport-web-ble';

const appId = 'appId that had been registered by wallet';
const transport = await createTransport();
const { privateKey: appPrivateKey } = crypto.key.generateKeyPair();

// Initialize
const iotx = new Iotx();

// Get Address
const addressIndex = 0;
const address = await iotx.getAddress(transport, appPrivateKey, appId, addressIndex);

// Sign Transaction
const options: Options = { transport, appPrivateKey, appId };
const transaction = {
  addressIndex,
  nonce: 1,
  gasLimit: 10000,
  gasPrice: '1000000000000',
  amount: '10000000000000000',
  recipient: 'io13nq26mfmse47uk8rgakld34yqrghgnl5hklnnc',
};
const signedTx = await iotx.signTransaction(transaction, options);

Methods

getAddress

The address generated is compatible to BIP44 with account and change set to 0, which means calling getAddress with addressIndex = i will get the address of folllowing BIP44 path:

m/44'/304'/0'/0/{i}
async getAddress(
    transport: types.Transport,
    appPrivateKey: string,
    appId: string,
    addressIndex: number
): Promise<string>

signTransaction

For transferring IOTX tokens.

type Integer = string | number;

interface Options {
  transport: Transport;
  appPrivateKey: string;
  appId: string;
  confirmCB?: Function;
  authorizedCB?: Function;
}

interface BaseTransaction {
  addressIndex: number;
  nonce: Integer;
  gasLimit: Integer;
  gasPrice: Integer;
}

interface Transfer extends BaseTransaction {
  amount: Integer;
  recipient: string;
  payload?: string;
}

async signTransaction(
  transaction: Transfer,
  options: Options
): Promise<string> {

signExecution

For EVM transaction.

interface Execution extends BaseTransaction {
  amount: Integer;
  contract: string;
  data?: string;
}

async signExecution(
  transaction: Execution,
  options: Options
): Promise<string> {

signStakeCreate

For creating bucket for voting.

interface StakeCreate extends BaseTransaction {
  candidateName: string;
  amount: Integer;
  duration: Integer;
  isAuto: boolean;
}

async signStakeCreate(
  transaction: StakeCreate,
  options: Options
): Promise<string> {

signStakeUnstake

For releasing a over-time bucket.

interface StakeUnstake extends BaseTransaction {
  bucketIndex: Integer;
}

async signStakeUnstake(
  transaction: StakeUnstake,
  options: Options
): Promise<string> {

signStakeWithdraw

For withdraw IOTX from a released bucket

interface StakeWithdraw extends BaseTransaction {
  bucketIndex: Integer;
}

async signStakeWithdraw(
  transaction: StakeWithdraw,
  options: Options
): Promise<string> {

Readme

Keywords

none

Package Sidebar

Install

npm i @coolwallet/iotx

Weekly Downloads

3

Version

1.0.1

License

Apache-2.0

Unpacked Size

147 kB

Total Files

17

Last publish

Collaborators

  • coolwallet-team