@jadepool/lib-ethereum
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Ethereum Transaction Builder for NodeJS

License

One of Jadepool support library - Ethereum transaction builder.

How to install

npm install @jadepool/lib-ethereum

How to use

  const lib = require('@jadepool/lib-ethereum')
  const pubKey = 'ECDSA PUBLIC KEY'
  // genAddressByPubKey
  const address = lib.genAddressByPubKey(pubKey)
  // normalizeAddress
  const normalizedAddress = lib.normalizeAddress(address.toLowerCase())
  // validateAddress
  const isValid = lib.validateAddress(address)
  // composeUnsignedTransferTx
  const transferInfo = {
    from: 'fromAddress',
    to: 'toAddress',
    value: 'amount',
    // optional for ERC20 or ERC721, format: '0x123...321' or 'ERC20:0x123...321' or 'ERC721:0x123...321'
    contract: 'contract address', // optional
    usingTransferFrom: false, // optional, using transferFrom method or not
  }
  const params = {
    nonce: 0,
    chainId: 42,
    gasPrice: 1e9, // this is default
    gasLimit: 21000 // this is default
  }
  const { unsignedHash, rawtx } = lib.composeUnsignedTransferTx(info, params)
  // buildTransferTx
  const signature = 'sig hex'
  const recovery = 1
  const { txid, rawtx } = lib.buildTransferTx(info, params, signature, recovery)
  // or build by public key
  const { txid, rawtx } = lib.buildTransferTx(info, params, signature, pubKey)

Readme

Keywords

Package Sidebar

Install

npm i @jadepool/lib-ethereum

Weekly Downloads

3

Version

0.2.0

License

MIT

Unpacked Size

20 kB

Total Files

9

Last publish

Collaborators

  • btspoony
  • kristieguo
  • cisaman
  • woyoutlz