Socket
Book a DemoInstallSign in
Socket

mxw-api

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mxw-api

Maxonrow blockchain SDK

0.1.4
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

SDK for MXW blockchain

Getting started

1. Install mxw-api package

If you want the latest, stable version, install the package from NPM.

npm install --save mxw-api

If you want the bleeding edge version which is possibly unstable, you can install the package from this Git repo.

npm install --save git+https://github.com/Sentrylink/mxw-api.git

2. Use it in your project

// Load the SDK (with require)
const MxwApi = require('mxw-api')

// Load the SDK (with import)
// import MxwApi from 'mxw-api'

// Define all nodes from which SDK can choose one
// The following list of nodes represents the current MXW testnet
const NODES = [
    'ws://node-1.testnet.space:26657',
    'ws://node-2.testnet.space:26657',
    'ws://node-3.testnet.space:26657',
    'ws://node-4.testnet.space:26657',
    'ws://node-5.testnet.space:26657',
    'ws://node-6.testnet.space:26657',
    'ws://node-7.testnet.space:26657',
    'ws://node-8.testnet.space:26657',
    'ws://node-9.testnet.space:26657',
    'ws://node-10.testnet.space:26657',
]

// Define the indexing service endpoint
// The provided URL is the Indexing service used by the testnet
const INDEXER = 'http://services.testnet.space:1234'

// Instantiate the SDK
const API = new MxwApi({
    nodes: NODES,
    indexer: INDEXER,
    backend: 'cosmos',
})

Tips

You can find detailed usage examples in the examples folder.

  • Assets / examples/assets.js
  • Alias / examples/alias.js
  • Events / examples/events.js
  • Faucet / examples/faucet.js
  • KYC / examples/kyc.js
  • Transfer / examples/transfer.js
  • Utilities / examples/util.js

API reference / Features

MXW SDK module

Kind: global namespace
Version: 0.1.4

mxw.events : object

Events

Kind: static namespace of mxw
Example: examples/events.js

events~onTx(fnc)

Set the new transaction handler.

Kind: inner method of events

ParamTypeDescription
fncfunctionFunction that will be called on every new transaction (format: (data) => {})

events~onBlock(fnc)

Set the new block handler.

Kind: inner method of events

ParamTypeDescription
fncfunctionFunction that will be called on every new block (format: (data) => {})

events~removeHandler(type)

Removes a certain handler

Kind: inner method of events

ParamTypeDescription
typestringHandler type ('tx'

mxw.main : object

Main

Kind: static namespace of mxw
Example: examples/transfer.js

main~balance(address) ⇒ Promise

Returns the balance of the given address.

Kind: inner method of main
Returns: Promise - balance - Wallet balance

ParamTypeDescription
addressstringAddress of the wallet

main~transfer(privateKey, address) ⇒ Promise

Transfer tokens from one address to another.

Kind: inner method of main
Returns: Promise - tx - Transaction result
Params: number amount - Amount of tokens

ParamTypeDescription
privateKeystringPrivate key of the wallet from which we're transfering tokens
addressstringAddress of the wallet to which we're transfering tokens

main~signTransfer(privateKey, address) ⇒ Promise

Signs a transfer transaction without relaying it.

Kind: inner method of main
Returns: Promise - tx - Transaction signature
Params: number amount - Amount of tokens

ParamTypeDescription
privateKeystringPrivate key of the wallet from which we're transfering tokens
addressstringAddress of the wallet to which we're transfering tokens

mxw.util : object

Utilities

Kind: static namespace of mxw
Example: examples/util.js

util~getAddressByPrivateKey(privateKey) ⇒ string

Returns wallet address.

Kind: inner method of util
Returns: string - address - Wallet address

ParamTypeDescription
privateKeystringWallet's private key

util~getAddressByPublicKey(publicKey) ⇒ string

Returns wallet address.

Kind: inner method of util
Returns: string - address - Wallet address

ParamTypeDescription
publicKeystringWallet's public key

util~generateKeyPair() ⇒ object

Generates a new private/public key pair and a wallet address.

Kind: inner method of util
Returns: object - keyPair - Generated keypair

util~getAddressFromPublicKeyByteArray(byteArray) ⇒ string

Returns wallet address.

Kind: inner method of util
Returns: string - address - Wallet address

ParamTypeDescription
byteArrayBufferWallet's public key as a byte array

util~decodeTx(encoded) ⇒ object

Decodes a tendermint transaction.

Kind: inner method of util
Returns: object - tx - Decoded transaction

ParamTypeDescription
encodedstringBase64 encoded transaction

util~getSha256(str) ⇒ string

Get SHA256 hash of a given string.

Kind: inner method of util
Returns: string - hash - Hashed string

ParamTypeDescription
strstringArbitrary string

util~getBlock(height) ⇒ Promise

Get a block at given height.

Kind: inner method of util
Returns: Promise - block - Block data

ParamTypeDescription
heightnumberBlock height

util~getTxsByHeight(height) ⇒ Promise

Get transactions at given height.

Kind: inner method of util
Returns: Promise - txs - Transactions

ParamTypeDescription
heightnumberBlock height

util~getTx(hash) ⇒ Promise

Get a single transaction by hash.

Kind: inner method of util
Returns: Promise - tx - Transaction data

ParamTypeDescription
hashstringTransaction hash

util~getTxs(address) ⇒ Promise

Get transactions by wallet address.

Kind: inner method of util
Returns: Promise - txs - Transactions

ParamTypeDescription
addressstringWallet address

mxw.alias : object

Aliasing module

Kind: static namespace of mxw
Example: examples/alias.js

alias~setAlias(privateKey, alias) ⇒ Promise

Set an alias.

Kind: inner method of alias
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringWallet's private key
aliasstringAn alias

alias~removeAlias(privateKey, alias) ⇒ Promise

Remove an alias.

Kind: inner method of alias
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringWallet's private key
aliasstringAn alias

alias~getAliasByAddress(address) ⇒ Promise

Gets alias for a given address

Kind: inner method of alias
Returns: Promise - alias - Alias

ParamTypeDescription
addressstringAddress of a wallet

alias~getAddressByAlias(alias) ⇒ Promise

Gets the address of an alias

Kind: inner method of alias
Returns: Promise - address - Wallet address

ParamTypeDescription
aliasstringAn alias

mxw.kyc : object

KYC module

Kind: static namespace of mxw
Example: examples/kyc.js

kyc~requestWhitelist(privateKey, whitelistAddress) ⇒ Promise

Allows users to request whitelisting from the mock KYC service.

Kind: inner method of kyc
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the KYC provider
whitelistAddressstringAddress that we're whitelisting

kyc~isWhitelisted(address) ⇒ Promise

Checks if the wallet address is whitelisted.

Kind: inner method of kyc
Returns: Promise - whitelist - Boolean

ParamTypeDescription
addressstringAddress of a wallet

mxw.faucet : object

Faucet module

Kind: static namespace of mxw
Example: examples/faucet.js

faucet~getStatus(address) ⇒ Promise

Allows users to see when they can request new coins from the faucet.

Kind: inner method of faucet
Returns: Promise - state - Query result

ParamTypeDescription
addressstringAddress of the wallet

faucet~requestCoins(privateKey, address) ⇒ Promise

Allows users to request coins from the faucet if they have less than 100 MXW.

Kind: inner method of faucet
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's requesting tokens
addressstringAddress of the wallet that's receiving tokens (optional)

mxw.asset : object

Asset module

Kind: static namespace of mxw
Example: examples/assets.js

Allows users to create a new fungible asset class.

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's creating the new fungible asset class
classIdstringId of the new asset class
dynamicSupplyboolA flag that determines if there will be a dynamic supply
initialSupplynumberInitial supply of the new asset class
totalSupplynumberTotal supply of the new asset class
dataLinkstringData link

Allows users to approve a fungible asset class.

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's approving the asset class
classIdstringId of the asset class
dataLinkstringData link

Allows users to reject a fungible asset class.

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's rejecting the asset class
classIdstringId of the asset class
dataLinkstringData link

Allows users to freeze a fungible asset class.

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's freezing the asset class
classIdstringId of the asset class
dataLinkstringData link

Allows users to unfreeze a fungible asset class.

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's unfreezing the asset class
classIdstringId of the asset class
dataLinkstringData link

Allows users to issue a fungible asset.

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's issuing the asset
classIdstringId of the asset class
ownerstringOwner of the issued asset
countnumberNumber of assets

asset~transferFungibleAsset(privateKey, classId, count, newOwner) ⇒ Promise

Allows users to transfer fungible assets.

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's transferring the asset
classIdstringId of the asset class
countnumberNumber of assets
newOwnerstringNew owner of the issued asset

asset~burnFungibleAsset(privateKey, classId, count) ⇒ Promise

Allows users to burn fungible assets.

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's burning the asset
classIdstringId of the asset class
countnumberNumber of assets

Allows users to freeze a fungible asset account

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's freezing the asset account
classIdstringId of the asset class
ownerstringOwner of the asset account
dataLinkstringData link

Allows users to unfreeze a fungible asset account

Kind: inner method of asset
Returns: Promise - tx - Transaction result

ParamTypeDescription
privateKeystringPrivate key of the wallet that's unfreezing the asset account
classIdstringId of the asset class
ownerstringOwner of the asset account
dataLinkstringData link

asset~listClasses() ⇒ Promise

Allows users to list all available asset classes

Kind: inner method of asset
Returns: Promise - data - All asset classes

asset~queryClass(classId) ⇒ Promise

Allows users to query an asset class by class id

Kind: inner method of asset
Returns: Promise - data - Asset class

ParamTypeDescription
classIdstringId of the asset class

asset~queryAccount(classId, address) ⇒ Promise

Allows users to query an account with assets

Kind: inner method of asset
Returns: Promise - data - Account

ParamTypeDescription
classIdstringId of the asset class
addressstringAccount address

Notes

  • If the SDK loses a connection to one of the blockchain nodes, it'll try to reconnect to a different random node. It'll try to do this 10 times. If the reconnection is not successful, it'll throw an error.
  • On MXW testnet, block time is around 5 seconds. This means that it'll take around 5 seconds until you can see commited changes when executing methods that query blockchain state (eg, API.util.balance). So, after executing a transaction, you won't see the changes immediatelly. This lag is normal and it's due to Tendermint implementation.

FAQs

Package last updated on 15 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.