Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

wicc-wallet-lib

WaykiChain39MIT2.1.0

A pure and powerful JavaScript Wicc Wallet library.

bitcoin, transaction, address, p2p, ecies, cryptocurrency, blockchain, payment, bip21, bip32, bip37, bip69, bip70, multisig, wicc, wusd, wgrt, dex, cdp

readme

wicc-wallet-utils-js v2.0

Official JavaScript library that provides WICC Offline Wallet capabilities

Installation

CDN

<script src="https://sw91.net/devops/wicc-wallet-utils/wicc-wallet-lib-2.0.0.js"></script>

NPM

npm install wicc-wallet-lib

Usage

const { Wallet, WalletManager, WaykiTransaction, BaasClient } = require("wicc-wallet-lib")

Key Classes

Wallet —— Constructor of a blockchain wallet

Demo

const privKeyWIF = "Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13"
const wallet = new Wallet(privKeyWIF) 
//{privateKey: 'Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13', address: 'wLKf2NqwtHk3BfzK5wMDfbKYN1SC3weyR4' }

Instance Methods

  • signMessage

    Message signature method

const msg = "wicc test"
const signTx = wallet.signMessage(msg) 
  • publicKeyAsHex

    Get wallet public key

const pubKey = wallet.publicKeyAsHex()

WalletManager —— Constructor of wallet management

Demo

const networkType = "testnet"
var walletManager = new WalletManager(networkType)

Instance Methods

  • randomMnemonicCodes

    Generate a mnemonic randomly

    const lang = "ENGLISH" // or CHINESE
    const mnemonics = walletManager.randomMnemonicCodes(lang) 
    //mnemonics = "clinic dose kingdom fetch away industry squirrel cheese purchase mean slide mixed"
  • switchMnemonicCodes

    Switching from mnemonics in the current language to mnemonics in another language, both can generate the same wallet `javascript var mnemonics1 = walletManager.randomMnemonicCodes("ENGLISH") var wallet1 = walletManager.importWalletFromMnemonic(mnemonics)

var mnemonics2 = walletManager.switchMnemonicCodes(mnemonics1, "CHINESE") var wallet2 = walletManager.importWalletFromMnemonic(mnemonics2)

wallet1.address === wallet2.address

- **createWallet**

    Create a blockchain wallet from valid mnemonics, returns a instance object of **Wallet**
```javascript
var wallet = walletManager.createWallet(mnemonics)
  • importWalletFromMnemonic

    Import an existing wallet from its mnemonics

    var wallet = walletManager.importWalletFromMnemonic(mnemonics)
  • importWalletFromPrivateKey

    Import an existing wallet from its private key

    var wallet = walletManager.importWalletFromPrivateKey(privateKeyWIF)

WaykiTransaction —— Constructor of transaction signature

var wallet = new Wallet(privKeyWIF) 
var txParams = {
  nTxType: 15, // transaction type
  nValidHeight: 34400,    // create height
  srcRegId: '0-1',    // sender's regId
  appId: "24555-1",  // app regId
  feeSymbol: "WICC",
  coinSymbol: "WUSD",
  fees: 1000000,         // fees pay for miner
  amount: 8,              // amount of WICC to be sent to the app account
  vContract: "f018"      // contract method, hex format string
};
var transaction = new WaykiTransaction(txParams, wallet)

Instance Methods

BaasClient —— Contains some of Baas (Blockchain as a Service) API; HTTP requerts

Demo

var baasClient = new BaasClient(BaasUrl)
BaasNetwork BaasUrl Remarks
TestNetwork https://baas-test.wiccdev.org/v2/api documentation
ProdNetwork https://baas.wiccdev.org/v2/api documentation

Instance Methods

  • getAccountInfo

    Get information of a specific wallet address, returns a Promise

    const address = "whiRBzMprDzY5wq3oPsHvAnyDV8ggYNaZE"
    const response = baasClient.getAccountInfo(address)
    response.then(data => {
      console.log(data)
    })
  • getBlockCount

    Get the current block height, returns a Promise

    const response = baasClient.getBlockCount()
    response.then(data => {
      console.log(data)
    })
  • sendRawTx

    Broadcast transaction signature data to blockchain, returns a Promise

    const rawTx = "0301818c760200011476c6077b5679c8ef47f4243ca25537d5c3f7fad883e1ac009f80e7eeef000d74657374207472616e73666572473045022100e2853b6dfb8a892659de4a43181f8a02e983cca319def2457ea7b0a14c8966ea0220733ce86e172bff8aba750d104b6f39b737c897df7c33413142bd13b2415ce2f2"
    const response = baasClient.sendRawTx(rawTx)
    response.then(data => {
      console.log(data)
    })
  • decodeRawTx

    Get the original transaction detail based on the signature data, returns a Promise

    const rawTx = "0301818c760200011476c6077b5679c8ef47f4243ca25537d5c3f7fad883e1ac009f80e7eeef000d74657374207472616e73666572473045022100e2853b6dfb8a892659de4a43181f8a02e983cca319def2457ea7b0a14c8966ea0220733ce86e172bff8aba750d104b6f39b737c897df7c33413142bd13b2415ce2f2"
    const response = baasClient.decodeRawTx(rawTx)
    response.then(data => {
      console.log(data)
    })

Development & Tests

$ git clone https://github.com/WaykiChain/wicc-wallet-utils-js.git
$ cd wicc-wallet-utils-js
$ npm install

Build (you will get a UMD module):

  • Execution Command
    $ npm run build 
  • Output
    dist/wicc-wallet-lib-2.0.js

    Examples

Run all the Demos:

$ npm run test

Reference Projects

bitpay/bitcore-lib

Contact us

To get community assistance and ask for help with implementation questions

License

Code released under the MIT license.

© 2017-present WaykiChain, Inc.