Wallet API

Javascript Signing SDK#

Overview#

Js-wallet-sdk is a wallet solution based on TypeScript/JavaScript language that includes various public chains' different cryptographic algorithms and common functionalities. You can use it for creating private keys, addresses, assembling transactions, and performing signatures, among other things. This document will provide a detailed guide on how to use this SDK. Currently, it supports various mainstream blockchains, with each token format having its own independent module implementation. We will continue to add support for more blockchains in the future.

Supported platforms#

As a Javascript SDK, it supports various browsers and JavaScript environments, and can be easily integrated into Web applications, mobile applications, or desktop applications.

Installation and building#

NPM building#

To use the Signing SDK, you first need to install it. You can use npm install to get the latest version.

Our Signing SDK supports two types of packages: public packages and single coin modules.

Public packages are for all currencies:

npm install @okxweb3/crypto-lib
npm install @okxweb3/coin-base

Integration of individual currencies, taking ETH and BTC as examples:

Integration of ETH:

npm install @okxweb3/coin-ethereum

Integration of BTC:

npm install @okxweb3/coin-bitcoin

Local building#

To build the SDK locally:

  1. Download the project source code
git clone https://github.com/okx/js-wallet-sdk.git
  1. Run the build script
sh build.sh

Main features#

Here is a specific introduction to the functions of each module in the Signing SDK.

  • crypto-lib: This module provides commonly used security encryption algorithms and signature algorithms, etc.
  • coin-base: This module provides a common interface for coins.
  • coin-*: This module implements methods for building and signing transactions for each coin. Each coin has a corresponding module, such as coin-ethereum, coin-bitcoin, etc. These modules provide transaction building and signing methods for specific coins.

Packages#

Package nameModuleDescription
@okxweb3/coin-basecoin-baseWe provide common functions for these chains or currencies, making access to these chains very simple.
@okxweb3/crypto-libcrypto-libWe provide common functions about bip32, bip39, ecdsa, ed25519, etc.
@okxweb3/coin-aptoscoin-aptosAptos SDK is used to interact with the Aptos blockchain, containing various functions that can be used for web3 wallets.
@okxweb3/coin-bitcoincoin-bitcoinBitcoin SDK is used to interact with the Bitcoin mainnet or testnet, containing various functions that can be used for web3 wallets. The SDK not only supports Bitcoin, but also supports the following chains: BTC, BSV, DOGE, LTC, TBTC.
@okxweb3/coin-cosmoscoin-cosmosCosmos SDK is used to interact with the Cosmos blockchain, containing various functions that can be used for web3 wallets.
@okxweb3/coin-eoscoin-eosEOS SDK is used to interact with the EOS blockchain, containing various functions that can be used for web3 wallets. The SDK not only supports EOS, but also supports WAX.
@okxweb3/coin-ethereumcoin-ethereumEthereum SDK is used to interact with the Ethereum blockchain or Evm blockchain, containing various functions that can be used for web3 wallets.
@okxweb3/coin-flowcoin-flowFlow SDK is used to interact with the Flow blockchain, containing various functions that can be used for web3 wallets.
@okxweb3/coin-nearcoin-nearNear SDK is used to interact with the Near Protocol, containing the main functions needed when interacting with the Near ecosystem.
@okxweb3/coin-polkadotcoin-polkadotPolkadot SDK is used to interact with the Polkadot blockchain, containing the main functions needed when interacting with the Polkadot ecosystem.
@okxweb3/coin-solanacoin-solanaSolana SDK is used to interact with the Solana chain, containing the main functions needed when interacting with the Solana ecosystem.
@okxweb3/coin-stackscoin-stacksStacks SDK is used to interact with the Stacks blockchain, containing various functions that can be used for web3 wallets.
@okxweb3/coin-starknetcoin-starknetStarknet SDK is used to interact with the Starknet blockchain, containing various functions that can be used for web3 wallets.
@okxweb3/coin-suicoin-suiSUI SDK is used to interact with the SUI blockchain, containing various functions that can be used for web3 wallets.
@okxweb3/coin-troncoin-tronTRX SDK is used to interact with the TRON blockchain, containing various functions that can be used for web3 wallets.
@okxweb3/coin-zkspacecoin-zkspaceZKSpace SDK is used to interact with ZK contracts, containing various functions that can be used for web3 wallets. The SDK not only supports ZKSpace, but also supports zkSync.

coin-base#

The base package is the common basic module for all currencies, providing common interface method definitions, such as: random private key generation, private key derivation, obtaining derivation paths, etc. At present, the implementation packages of individual currencies have basically implemented common interface methods, but the functions supported by different currencies may vary slightly. For more details, you can refer to the function descriptions of each coin implementation package.

To get the latest version of the package via npm:

npm install @okxweb3/coin-base

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
validPrivateKeyValidate a private key
signMessageSign a message
verifyMessageVerify a signed message
ecRecoverRecover a signature to a public key
getAddressByPublicKeyGet an address through a public key
getHardWareRawTransactionGet the raw transaction of the hardware
getHardWareSignedTransactionGet the signed transaction of the hardware
getHardWareMessageHashGet the message hash of the hardware
calcTxHashGet a transaction hash through a raw transaction
getRawTransactionGenerate raw transaction data
validSignedTransactionCheck a signed transaction
estimateFeeEstimate gas fees

For more detailed information about the functions supported by the coin-base package and use cases, you can view the github document for more detailed content: coin-base function functions.

crypto-lib#

This is a library that includes implementations of commonly used security encryption and signature algorithms such as bip32, bip39, ecdsa, ed25519, etc. For example:

  • Common bip32 functions: These functions are mainly used to handle and operate tasks related to the Bitcoin Improvement Payment Protocol (BIP32).
  • bip39 mnemonic generation, public/private key, and message signing functions: These functions are mainly used to handle and operate tasks related to the Bitcoin Improvement Payment Protocol (BIP39), such as generating mnemonics, public/private keys, and signing messages.
  • Common hash and encoding/decoding functions: These functions are mainly used to handle common hash and encoding/decoding tasks, such as SHA256 hashing, Base64 encoding/decoding, etc.
  • Common ed5519 signature functions: These functions are mainly used to handle and operate tasks related to the ed5519 signature algorithm.
  • Common ecdsa signature functions: These functions are mainly used to handle and operate tasks related to the Elliptic Curve Digital Signature Algorithm (ECDSA).

To get the latest version of the package via npm:

npm install @okxweb3/crypto-lib

For more detailed information about the functions supported by the crypto-lib package and use cases, you can view the github document for more detailed content: crypto-lib function functions.

coin-aptos#

Aptos SDK is mainly used to integrate Aptos blockchain, containing functions such as private key generation, private key derivation, address generation, and transaction transfer.

To get the latest version of the package via npm:

npm install @okxweb3/coin-aptos

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
signMessageSign a message
verifyMessageVerify a signed message
calcTxHashGet a transaction hash through a raw transaction
validSignedTransactionCheck a signed transaction

Aptos transaction support types are:

"transfer", "tokenTransfer", "tokenMint", "tokenBurn", "tokenRegister", "dapp", "simulate", "offerNft", "claimNft", "offerNft_simulate", "claimNft_simulate"

For more detailed information about the functions supported by the coin-aptos package and use cases, you can view the github document for more detailed content: coin-aptos function functions.

coin-bitcoin#

coin-bitcoin is an SDK for integrating Bitcoin blockchain. It supports both the Bitcoin mainnet and testnet, and provides a series of functional methods, making it easier for developers to interact with the Bitcoin blockchain. In addition to BTC, it also supports other cryptocurrencies such as BSV, DOGE, LTC, and TBTC.

To get the latest version of the package via npm:

npm install @okxweb3/coin-bitcoin

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
signMessageSign a message
verifyMessageVerify a signed message
calcTxHashGet a transaction hash through a raw transaction
validSignedTransactionCheck a signed transaction
getAddressByPublicKeyGet an address through a public key

For more detailed information about the functions supported by the coin-bitcoin package and use cases, you can view the github document for more detailed content: coin-bitcoin function functions.

coin-cosmos#

Cosmos SDK is a toolkit for integrating with the Cosmos blockchain, providing a series of functional methods, including generating private keys, deriving private keys, generating addresses, and transferring transactions. It supports currencies including:

  • Atom
  • Axelar
  • Cronos
  • Evmos
  • Iris
  • Juno
  • Kava
  • Kujira
  • Osmos
  • Secret
  • Sei
  • Stargaze
  • Terra

To get the latest version of the package via npm:

npm install @okxweb3/coin-cosmos

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
signMessageSign a message
verifyMessageVerify a signed message
calcTxHashGet a transaction hash through a raw transaction
validSignedTransactionCheck a signed transaction
getAddressByPublicKeyGet an address through a public key

For more detailed information about the functions supported by the coin-cosmos package and use cases, you can view the github document for more detailed content: coin-cosmos function functions.

coin-eos#

EOS SDK is a toolkit for integrating with the EOS blockchain. It provides a series of functional methods, including generating private keys, deriving private keys, generating addresses, and transaction serialization. In addition to EOS, it also supports the Wax coin.

These functional methods make it easier for developers to interact with the EOS blockchain, including creating and managing wallets, sending and receiving transactions, and querying blockchain information.

To get the latest version of the package via npm:

npm install @okxweb3/coin-eos

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
signTransactionSign a transaction
getDerivedPathGet a bip44 path
calcTxHashGet a transaction hash through a raw transaction

For more detailed information about the functions supported by the coin-eos package and use cases, you can view the github document for more detailed content: coin-eos function functions.

coin-ethereum#

Ethereum SDK is a toolkit for integrating with the Ethereum blockchain and other blockchains that support EVM (Ethereum Virtual Machine). It provides a series of functional methods, including generating private keys, deriving private keys, generating addresses, and transferring transactions.

These functional methods make it easier for developers to interact with the Ethereum blockchain, including creating and managing wallets, sending and receiving transactions, and querying blockchain information.

To get the latest version of the package via npm:

npm install @okxweb3/coin-ethereum

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
validPrivateKeyValidate a private key
signMessageSign a message
verifyMessageVerify a signed message
ecRecoverRecover a signature to a public key
getAddressByPublicKeyGet an address through a public key
getHardWareRawTransactionGet the raw transaction of the hardware
getHardWareSignedTransactionGet the signed transaction of the hardware
getHardWareMessageHashGet the message hash of the hardware
calcTxHashGet a transaction hash through a raw transaction
getRawTransactionGenerate raw transaction data
validSignedTransactionCheck a signed transaction

For more detailed information about the functions supported by the coin-ethereum package and use cases, you can view the github document for more detailed content: coin-ethereum function functions.

coin-flow#

Flow blockchain is a next-generation, future-oriented blockchain platform, specifically designed for high-performance applications and games.

Flow SDK is a toolkit for integrating with the Flow blockchain. It provides a series of functional methods, enabling developers to interact more conveniently with the Flow blockchain. The specific functionalities offered by the SDK can facilitate the development of applications on the Flow blockchain.

To get the latest version of the package via npm:

npm install @okxweb3/coin-flow

Supported functions:

Function nameFunctionalityRemarks
validateAddressValidate an address
signTransactionSign a transaction

Flow supports two types of transactions: Account and Transfer.

For more detailed information about the functions supported by the coin-flow package and use cases, you can view the github document for more detailed content: coin-flow function functions.

coin-near#

Near Protocol is a scalable blockchain platform that achieves high throughput and low latency transaction processing by using a novel consensus mechanism and sharding technology. Near SDK allows developers to interact more conveniently with the Near blockchain.

Near SDK is a toolkit for integrating with the Near Protocol, containing the main functions needed when interacting with the Near ecosystem.

To get the latest version of the package via npm:

npm install @okxweb3/coin-near

Supported functions:

Function nameFunctionalityRemarks
getAddressGet an address through a seed
validateAddressValidate an address
signTransactionSign a transaction
transferTransfer a coin
fullAccessKeyGet a full access key
publicKeyFromSeedGet a public key from a seed

For more detailed information about the functions supported by the coin-near package and use cases, you can view the github document for more detailed content: coin-near function functions.

coin-polkadot#

Polkadot is a multi-chain heterogeneous blockchain platform, which allows various blockchain networks to run in parallel with a shared security model, and can also realize seamless transfer of information and value between chains.

Polkadot SDK is a toolkit for integrating with the Polkadot blockchain, containing the main functions needed when interacting with the Polkadot ecosystem.

To get the latest version of the package via npm:

npm install @okxweb3/coin-polkadot

Supported functions:

Function nameFunctionalityRemarks
getAddressGet an address through a seed
validateAddressValidate an address
SignTxSign a transaction

For more detailed information about the functions supported by the coin-polkadot package and use cases, you can view the github document for more detailed content: coin-polkadot function functions.

coin-solana#

Solana is a high-performance blockchain platform that achieves high throughput and low latency transaction processing through an innovative consensus algorithm and block generation mechanism.

Solana SDK is a toolkit for integrating the Solana blockchain, containing the main functions needed when interacting with the Solana ecosystem.

To get the latest version of the package via npm:

npm install @okxweb3/coin-solana

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
signMessageSign a message
calcTxHashGet a transaction hash through a raw transaction
validSignedTransactionCheck a signed transaction
getHardWareRawTransactionGet the raw transaction of the hardware
getHardWareSignedTransactionGet the signed transaction of the hardware
getHardWareMessageHashGet the message hash of the hardware

For more detailed information about the functions supported by the coin-solana package and use cases, you can view the github document for more detailed content: coin-solana function functions.

coin-stacks#

Stacks is an open-source blockchain platform that allows developers to build smart contracts and decentralized applications on the Stacks blockchain.

Stacks SDK is mainly used to integrate Stacks blockchain, containing various functions that can be used for web3 wallets.

To get the latest version of the package via npm:

npm install @okxweb3/coin-stacks

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
signMessageSign a message
verifyMessageVerify a signed message
calcTxHashGet a transaction hash through a raw transaction
getRawTransactionGet a raw transaction

For more detailed information about the functions supported by the coin-stacks package and use cases, you can view the github document for more detailed content: coin-stacks function functions.

coin-starknet#

StarkNet is a decentralized, scalable blockchain network that uses zero-knowledge proof technology to enhance the efficiency and security of transaction processing.

StarkNet SDK is a toolkit for integrating the StarkNet blockchain, providing a series of functional methods that make it easier for developers to interact with the StarkNet blockchain.

To get the latest version of the package via npm:

npm install @okxweb3/coin-starknet

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
signMessageSign a message
verifyMessageVerify a signed message

For more detailed information about the functions supported by the coin-starknet package and use cases, you can view the github document for more detailed content: coin-starknet function functions.

coin-sui#

SUI SDK is a toolkit for integrating the SUI blockchain, containing various functions that can be used for web3 wallets.

To get the latest version of the package via npm:

npm install @okxweb3/coin-sui

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
signMessageSign a message
calcTxHashGet a transaction hash through a raw transaction
Note
Note: Unlike secp256k1, ed25519 only supports hard mode derivation for private keys. For more details, refer to: https://github.com/satoshilabs/slips/blob/master/slip-0010.md

For more detailed information about the functions supported by the coin-sui package and use cases, you can view the github document for more detailed content: coin-sui function functions.

coin-tron#

TRON SDK is a toolkit for integrating the TRON blockchain, containing various functions that can be used for web3 wallets.

To get the latest version of the package via npm:

npm install @okxweb3/coin-tron

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
validPrivateKeyValidate a private key
signMessageSign a message
verifyMessageVerify a signed message
ecRecoverRecover a signature to a public key
getAddressByPublicKeyGet an address through a public key
getHardWareRawTransactionGet the raw transaction of the hardware
getHardWareSignedTransactionGet the signed transaction of the hardware
getHardWareMessageHashGet the message hash of the hardware
calcTxHashGet a transaction hash through a raw transaction
getRawTransactionGenerate raw transaction data
validSignedTransactionCheck a signed transaction

For more detailed information about the functions supported by the coin-tron package and use cases, you can view the github document for more detailed content: coin-tron function functions.

coin-zkspace#

ZKSpace SDK is mainly used to integrate ZK contracts, containing various functions that can be used for web3 wallets. In addition to ZKSpace, it also supports zkSync.

To get the latest version of the package via npm:

npm install @okxweb3/coin-zkspace

Supported functions:

Function nameFunctionalityRemarks
getRandomPrivateKeyGenerate a random private key
getDerivedPrivateKeyGenerate a private key from DerivePriKeyParams
getNewAddressGet a new address through a private key
validAddressValidate an address
signTransactionSign a transaction
getDerivedPathGet a bip44 path
validPrivateKeyValidate a private key
signMessageSign a message
verifyMessageVerify a signed message
ecRecoverRecover a signature to a public key
getAddressByPublicKeyGet an address through a public key
getHardWareRawTransactionGet the raw transaction of the hardware
getHardWareSignedTransactionGet the signed transaction of the hardware
getHardWareMessageHashGet the message hash of the hardware
calcTxHashGet a transaction hash through a raw transaction
getRawTransactionGenerate raw transaction data

The transaction signature supports data types including: transfer and changePubkey.

For more detailed information about the functions supported by the coin-zkspace package and use cases, you can view the github document for more detailed content: coin-zkspace function functions.

Test cases#

On github, there is a tests directory under the package corresponding to each module, which contains test cases for various coin modules. You can learn more about the usage of functions in the SDK through these test cases.

Supported coins#

Coin familyCoinDerivation path
BTCBTCRegular address:
m/44'/0'/0/0'/0
SegWit:
m/49'/0'/0/0'/0
m/84'/0'/0/0'/0
m/86'/0'/0/0'/0
BTCBCHm/44'/145'/0'/0/0
BTCBSVm/44'/236'/0'/0/0
BTCLTCm/44'/2'/0'/0/0
BTCDogem/44'/3'/0'/0/0
BTCTBTCm/44'/0'/0/0'/0
BTCOmni USDTm/44'/0'/0/0'/0
ETHETHm/44'/60'/0'/0/0
ETHArbitrum Onem/44'/60'/0'/0/0
ETHArbitrum Novam/44'/60'/0'/0/0
ETHAvalanche Cm/44'/60'/0'/0/0
ETHBobam/44'/60'/0'/0/0
ETHBNB Chainm/44'/60'/0'/0/0
ETHBasem/44'/60'/0'/0/0
ETHCorem/44'/60'/0'/0/0
ETHCronos(EVM)m/44'/60'/0'/0/0
ETHCelom/44'/60'/0'/0/0
ETHConflux(EVM)m/44'/60'/0'/0/0
ETHEndurancem/44'/60'/0'/0/0
ETHEthereumPoWm/44'/60'/0'/0/0
ETHEthereumFairm/44'/60'/0'/0/0
ETHFilecoin EVMm/44'/60'/0'/0/0
ETHFantomm/44'/60'/0'/0/0
ETHFlarem/44'/60'/0'/0/0
ETHGnosism/44'/60'/0'/0/0
ETHGoerlim/44'/60'/0'/0/0
ETHHAQQ Networkm/44'/60'/0'/0/0
ETHKlaytnm/44'/60'/0'/0/0
ETHKCCm/44'/60'/0'/0/0
ETHKava EVMm/44'/60'/0'/0/0
ETHLineam/44'/60'/0'/0/0
ETHMetism/44'/60'/0'/0/0
ETHMoonebeamm/44'/60'/0'/0/0
ETHMoonriverm/44'/60'/0'/0/0
ETHMantlem/44'/60'/0'/0/0
ETHOmega Networkm/44'/60'/0'/0/0
ETHOKTCm/44'/60'/0'/0/0
ETHOptimismm/44'/60'/0'/0/0
ETHopBNBm/44'/60'/0'/0/0
ETHPolygonm/44'/60'/0'/0/0
ETHPolygon zkEVMm/44'/60'/0'/0/0
ETHPulseChainm/44'/60'/0'/0/0
ETHSepoliam/44'/60'/0'/0/0
ETHzkSync Eram/44'/60'/0'/0/0
ETHZetaChianm/44'/60'/0'/0/0
CosmosAtomm/44'/118'/0'/0/0
CosmosAxelarm/44'/118'/0'/0/0
CosmosCronosm/44'/394'/0'/0/0
CosmosOsmosm/44'/118'/0'/0/0
CosmosEvmosm/44'/60'/0'/0/0
CosmosIrism/44'/118'/0'/0/0
CosmosJunom/44'/118'/0'/0/0
CosmosKavam/44'/459'/0'/0/0
CosmosKujiram/44'/118'/0'/0/0
CosmosSecretm/44'/529'/0'/0/0
CosmosSeim/44'/118'/0'/0/0
CosmosStargazem/44'/118'/0'/0/0
CosmosTerram/44'/330'/0'/0/0
AptosAptosm/44'/637'/0'/0/0
EOSEOSm/44'/194'/0'/0/0
SolanaSolanam/44'/501'/0'/0/0
StacksStacksm/44'/5757'/0'/0/0
ETH lay2Starknetm/44'/9004'/0'/0/0
SUISUIm/44'/784'/0'/0/0
TRXTROMm/44'/195'/0'/0/0
ETH lay2ZKSpacem/44'/60'/0'/0/0
ETH lay2zkSyncm/44'/60'/0'/0/0