@jadepool/lib-ethereum
v0.2.0
Published
Ethereum Transaction Builder for NodeJS - Jadepool
Downloads
4
Keywords
Readme
Ethereum Transaction Builder for NodeJS
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)