Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
ethereum-input-data-decoder
Advanced tools
Ethereum smart contract transaction input data decoder
https://lab.miguelmota.com/ethereum-input-data-decoder
npm install ethereum-input-data-decoder
Pass ABI file path to decoder constructor:
const InputDataDecoder = require('ethereum-input-data-decoder');
const decoder = new InputDataDecoder(`${__dirname}/abi.json`);
Alternatively, you can pass ABI array object to constructor;
const abi = [{ ... }]
const decoder = new InputDataDecoder(abi);
Then you can decode input data:
const data = `0x67043cae0000000000000000000000005a9dac9315fdd1c3d13ef8af7fdfeb522db08f020000000000000000000000000000000000000000000000000000000058a20230000000000000000000000000000000000000000000000000000000000040293400000000000000000000000000000000000000000000000000000000000000a0f3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c800000000000000000000000000000000000000000000000000000000000000034254430000000000000000000000000000000000000000000000000000000000`;
const result = decoder.decodeData(data);
console.log(result);
{
"name": "registerOffChainDonation",
"types": [
"address",
"uint256",
"uint256",
"string",
"bytes32"
],
"inputs": [
<BN: 5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02>,
<BN: 58a20230>,
<BN: 402934>,
"BTC",
<Buffer f3 df ... 71 c8>
]
}
Example using input response from web3.getTransaction:
web3.eth.getTransaction(txHash, (error, txResult) => {
const result = decoder.decodeData(txResult.input);
console.log(result);
});
All numbers are returned in big number format to preserve precision.
Here's an example of how to convert the big number to a human readable format.
console.log(result.inputs[0].toString(10)) // "5"
console.log(result.inputs[0].toNumber()) // 55
Please keep in mind that JavaScript only supports numbers up to 64 bits. Solidity numbers can be up to 256 bits, so you run the risk of truncation when casting or having the big number library error out when trying to parse a large number to a JavaScript Number type.
const n = new BN("543534254523452352345234523455")
console.log(n.toString(10)) // "543534254523452352345234523455"
console.log(n.toNumber()) // ERROR!
npm install -g ethereum-input-data-decoder
$ ethereum_input_data_decoder --help
Ethereum smart contract transaction input data decoder
Usage
$ ethereum_input_data_decoder [flags] [input]
Options
--abi, -a ABI file path
--input, -i Input data file path
Examples
$ ethereum_input_data_decoder --abi token.abi --input data.txt
$ ethereum_input_data_decoder --abi token.abi "0x23b872dd..."
Pass ABI file and input data as file:
$ ethereum_input_data_decoder --abi abi.json --input data.tx
name registerOffChainDonation
address 0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256 1487012400
uint256 4204852
string BTC
bytes32 0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8
Pass ABI file and input data as string:
$ ethereum_input_data_decoder --abi abi.json 0x67043cae0...000000
name registerOffChainDonation
address 0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256 1487012400
uint256 4204852
string BTC
bytes32 0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8
You can also pipe the input data:
$ cat data.txt | ethereum_input_data_decoder --abi abi.json
name registerOffChainDonation
address 0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256 1487012400
uint256 4204852
string BTC
bytes32 0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8
npm test
git clone git@github.com:miguelmota/ethereum-input-data-decoder.git
cd ethereum-input-data-decoder/
npm install
Make changes.
Run tests:
npm test
npm run lint:fix
Q: How can I retrieve the ABI?
A: You can generate the ABI from the solidity source files using the Solidity Compiler.
solc --abi MyContract.sol -o build
Q: Can this library decode contract creation input data?
FAQs
Ethereum smart contract transaction input data decoder
The npm package ethereum-input-data-decoder receives a total of 1,549 weekly downloads. As such, ethereum-input-data-decoder popularity was classified as popular.
We found that ethereum-input-data-decoder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.