@solidity-utilities/abi-to-interface

0.0.1 • Public • Published

Solidity ABI To Interface

Node JS CLI script for converting Solidity ABI to interface contract

Byte size of Abi To Interface Open Issues Open Pull Requests Latest commits License



Requirements

Prerequisites and/or dependencies that this project needs to function properly

Node JS and NPM, or similar Node JS package manager, is required to utilize this project and dependencies.


Quick Start

Perhaps as easy as one, 2.0,...

Install project globally...

npm install --global @solidity-utilities/abi-to-interface

Available CLI parameters may be listed via --help option...

solidity-abi-to-interface --help

Note, if solidity-abi-to-interface reports errors similar to...

bash: solidity-abi-to-interface: command not found

... then please ensure the PATH variable includes a reference to the NPM prefixed bin/ directory, eg.

# Add prefix if not defined
grep -qE '^prefix ' <(npm config ls) || {
  tee -a "${HOME}/.npmrc" 1>/dev/null <<EOF
prefix = "${HOME}/.npm"
EOF
}


# Append to PATH variable if not defined
_npm_prefix="$(awk '/^prefix / {
  gsub("\"", "");
  print $3;
}' <(npm config ls))"

grep -qE "(:)?(${_npm_prefix}/bin)(:)?" <<<"${PATH}" || {
  tee -a "${HOME}/.bashrc" 1>/dev/null <<EOF
export PATH="${PATH}:${_npm_prefix}/bin"
EOF
}


# Reload Bash RC file
source "${HOME}/.bashrc"

Usage

How to utilize this repository

Change current working directory to a Solidity project...

cd ~/git/hub/solidity-utilities/example

Compile contract(s) into ABI JSON file(s)...

truffle compile

Generate an interface contract based on Account contract ABI...

solidity-abi-to-interface --abi build/contracts/Account.json\
                          --out contracts/InterfaceAccount.sol

A source contract such as...

contracts/Account.sol

// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.7;

contract Account {
    string public name;
    address payable public owner;

    function updateName(string calldata _new_name) external {
        require(msg.sender == owner, "Owner required");
        name = _new_name;
    }
}

Will result in an interface similar to...

contracts/InterfaceAccount.sol

// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.7;

/// @title Automatically generated by `@solidity-utilities/abi-to-interface`
interface InterfaceAccount {
    /* Variable getters */

    function name() external view returns (string memory);

    function owner() external view returns (address payable);

    /* Function definitions */

    function updateName(string calldata _new_name) external;
}

Notes

Additional things to keep in mind when utilizing this project

This repository may not be feature complete and/or fully functional, Pull Requests that add features or fix bugs are certainly welcomed.


Contributing

Options for contributing to abi-to-interface and solidity-utilities


Forking

Tips for forking abi-to-interface

Make a Fork of this repository to an account that you have write permissions for.

  • Clone fork URL. The URL syntax is git@github.com:<NAME>/<REPO>.git, then add this repository as a remote...
mkdir -p ~/git/hub/solidity-utilities

cd ~/git/hub/solidity-utilities

git clone --origin fork git@github.com:<NAME>/abi-to-interface.git

git remote add origin git@github.com:solidity-utilities/abi-to-interface.git
  • Install development dependencies
cd ~/git/hub/solidity-utilities/abi-to-interface

npm ci

Note, the ci option above is recommended instead of install to avoid mutating the package.json, and/or package-lock.json, file(s) implicitly

  • Commit your changes and push to your fork, eg. to fix an issue...
cd ~/git/hub/solidity-utilities/abi-to-interface


git commit -F- <<'EOF'
:bug: Fixes #42 Issue


**Edits**


- `<SCRIPT-NAME>` script, fixes some bug reported in issue
EOF


git push fork main
  • Then on GitHub submit a Pull Request through the Web-UI, the URL syntax is https://github.com/<NAME>/<REPO>/pull/new/<BRANCH>

Note; to decrease the chances of your Pull Request needing modifications before being accepted, please check the dot-github repository for detailed contributing guidelines.


Sponsor

Methods for financially supporting solidity-utilities that maintains abi-to-interface

Thanks for even considering it!

Via Liberapay you may sponsor__shields_io__liberapay on a repeating basis.

For non-repeating contributions Ethereum is accepted via the following public address;

0x5F3567160FF38edD5F32235812503CA179eaCbca

Regardless of if you're able to financially support projects such as abi-to-interface that solidity-utilities maintains, please consider sharing projects that are useful with others, because one of the goals of maintaining Open Source repositories is to provide value to the community.


Attribution


License

Node JS CLI script for converting Solidity ABI to interface contract
Copyright (C) 2021 S0AndS0

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

For further details review full length version of AGPL-3.0 License.

Readme

Keywords

Package Sidebar

Install

npm i @solidity-utilities/abi-to-interface

Weekly Downloads

2

Version

0.0.1

License

AGPL-3.0

Unpacked Size

238 kB

Total Files

60

Last publish

Collaborators

  • s0ands0