I<Anything>
- Generate Solidity interfaces to any contract
solface
is a command-line tool which helps you generate Solidity interfaces from smart contract ABIs.
You can install solface
using:
go install github.com/moonstream-to/solface
It's as simple as:
$ solface -name IOwnableERC20 fixtures/abis/OwnableERC20.json
// Interface generated by solface: https://github.com/moonstream-to/solface
// solface version: 0.1.0
interface IOwnableERC20 {
// structs
// events
event Approval(address owner, address spender, uint256 value);
event OwnershipTransferred(address previousOwner, address newOwner);
event Transfer(address from, address to, uint256 value);
// functions
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function decimals() external view returns (uint8);
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);
function increaseAllowance(address spender, uint256 addedValue) external returns (bool);
function mint(address account, uint256 amount) external ;
function name() external view returns (string memory);
function owner() external view returns (address);
function renounceOwnership() external ;
function symbol() external view returns (string memory);
function totalSupply() external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function transferOwnership(address newOwner) external ;
// errors
}
You can also pipe ABIs into solface
:
$ cat fixtures/abis/OwnableERC20.json | solface -name IOwnableERC20
// Interface generated by solface: https://github.com/moonstream-to/solface
// solface version: 0.1.0
interface IOwnableERC20 {
// structs
// events
event Approval(address owner, address spender, uint256 value);
event OwnershipTransferred(address previousOwner, address newOwner);
event Transfer(address from, address to, uint256 value);
// functions
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function decimals() external view returns (uint8);
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);
function increaseAllowance(address spender, uint256 addedValue) external returns (bool);
function mint(address account, uint256 amount) external ;
function name() external view returns (string memory);
function owner() external view returns (address);
function renounceOwnership() external ;
function symbol() external view returns (string memory);
function totalSupply() external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function transferOwnership(address newOwner) external ;
// errors
}
You can set the -annotations
flag to annotate a generated interface with comments containing the interface identifier for the interface
and the selector for each method in the interface:
$ solface -name IOwnableERC20 -annotations fixtures/abis/OwnableERC20.json
// Interface generated by solface: https://github.com/moonstream-to/solface
// solface version: 0.1.0
// Interface ID: 47e0e5cb
interface IOwnableERC20 {
// structs
// events
event Approval(address owner, address spender, uint256 value);
event OwnershipTransferred(address previousOwner, address newOwner);
event Transfer(address from, address to, uint256 value);
// functions
// Selector: dd62ed3e
function allowance(address owner, address spender) external view returns (uint256);
// Selector: 095ea7b3
function approve(address spender, uint256 amount) external returns (bool);
// Selector: 70a08231
function balanceOf(address account) external view returns (uint256);
// Selector: 313ce567
function decimals() external view returns (uint8);
// Selector: a457c2d7
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);
// Selector: 39509351
function increaseAllowance(address spender, uint256 addedValue) external returns (bool);
// Selector: 40c10f19
function mint(address account, uint256 amount) external ;
// Selector: 06fdde03
function name() external view returns (string memory);
// Selector: 8da5cb5b
function owner() external view returns (address);
// Selector: 715018a6
function renounceOwnership() external ;
// Selector: 95d89b41
function symbol() external view returns (string memory);
// Selector: 18160ddd
function totalSupply() external view returns (uint256);
// Selector: a9059cbb
function transfer(address recipient, uint256 amount) external returns (bool);
// Selector: 23b872dd
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
// Selector: f2fde38b
function transferOwnership(address newOwner) external ;
// errors
}
This is really useful if you want to set or check supportsInterface
or quickly decode a message from
raw calldata.
Enjoy!
PRs welcome. Please use our GitHub issues to communicate with us: https://github.com/moonstream-to/solface/issues/new