1.0.0 • Published 5 years ago
eth-token-encode v1.0.0
eth-token-encode
Encode easily the data value of Ethereum (Also works with Binance Smartchain, and any ethereum fork) for token transactions.
NPM and version
Install
Install using NPM with the following command:
npm i eth-token-encodeUsage
Here are a few examples that can be used:
const genData = require("eth-token-encode");
let data = new genData(18); // creates object
data.generate("0x82B176BBdd8892df7d6B4b46Ec446a07A60F347E", 0.1); // returns 0xa9059cbb00000000000000000000000082B176BBdd8892df7d6B4b46Ec446a07A60F347E000000000000000000000000000000000000000000000000016345785d8a0000Keep in mind that this is only for token transfers! You should set the value to 0x0 and data to this encoded value.
For now it only works with the contract function transfer(address,uint256) (0xa9059cbb)
API
genData(decimals)
decimals is the number of decimals of said token/contract, (Ex. 18 for most tokens)
.generate(toAddress, Amount)
toAddress is the receiving address in a valid hex format.
Amount is the number of tokens desired to send.
Dependencies
isStrHex
locutus
Test
Run npm test for more tests.
Notes
- This is still a WIP, functional but basic.
- Main reason of this was to interact with Binance SmartChain as most existing packages won't work on the signing part.
- If you had the same trouble as me, I'd recommend to use @warren-bank/ethereumjs-tx-sign instead of ethereumjs-tx (ChainID for BSC doesn't work with ethereumjs-tx, plus it's lightweight).
Might implement:
- Direct use with @warren-bank/ethereumjs-tx-sign for easier signing.
- File with common tokens to support easier search.
1.0.0
5 years ago