Node JS CLI script for converting Solidity ABI to interface contract
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.
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"
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;
}
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.
Options for contributing to abi-to-interface and solidity-utilities
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 ofinstall
to avoid mutating thepackage.json
, and/orpackage-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.
Methods for financially supporting
solidity-utilities
that maintainsabi-to-interface
Thanks for even considering it!
Via Liberapay you may
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.
-
Etherum StackExchange -- How to create interface to read Struct in mapping?
-
Medium -- Build and Publish Your First Command Line Application with Node.JS and NPM
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.