itsnickbarry / hardhat-abi-exporter Goto Github PK
View Code? Open in Web Editor NEW๐งฐ Export Ethereum contract ABIs on compilation โ๏ธ
License: MIT License
๐งฐ Export Ethereum contract ABIs on compilation โ๏ธ
License: MIT License
If validations are done in extendConfig
, errors will be thrown at startup rather than when the export-abi
task is run.
Hi, I was wondering would it be possible to also have a flag to also generate files with bytecode for the contract? From what I understand they already exist in the artifacts.
Such a feature would save some time when generating abi files to be used in for example bindings for golang
getting this error when having
require('hardhat-abi-exporter');
When there are files in the output directory the plugin fails, even though I have clear set to true in config.
Full error:
{ Error: ENOTEMPTY: directory not empty, rmdir '/Users/solar/dev/eth/tug-of-war/solidity/../dapp/src/abi'
at Object.rmdirSync (fs.js:684:3)
at OverriddenTaskDefinition._action (/Users/solar/dev/eth/tug-of-war/solidity/node_modules/hardhat-abi-exporter/index.js:31:8)
errno: -66,
syscall: 'rmdir',
code: 'ENOTEMPTY',
path: '/Users/solar/dev/eth/tug-of-war/solidity/../dapp/src/abi' }
Seeing this warning on the latest LTS version of node (16.13.0):
(node:21035) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead
Should be a small fix. If possible!
Hi, I am getting this ABI output from running yarn run hardhat export-abi
. It does not look like a valid contract ABI format.
[
"constructor(string,string,uint256)",
"event Approval(address indexed,address indexed,uint256)",
"event Transfer(address indexed,address indexed,uint256)",
"function allowance(address,address) view returns (uint256)",
"function approve(address,uint256) returns (bool)",
"function balanceOf(address) view returns (uint256)",
"function decimals() view returns (uint8)",
"function decreaseAllowance(address,uint256) returns (bool)",
"function increaseAllowance(address,uint256) returns (bool)",
"function name() view returns (string)",
"function symbol() view returns (string)",
"function totalSupply() view returns (uint256)",
"function transfer(address,uint256) returns (bool)",
"function transferFrom(address,address,uint256) returns (bool)"
]
contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract ERC20Contract is ERC20 {
constructor(
string memory name,
string memory symbol,
uint256 supply
) public ERC20(name, symbol) {
_mint(msg.sender, supply);
}
}
packages
"hardhat": "2.2.1",
"hardhat-abi-exporter": "^2.6.1",
node version
node --version
v16.13.0
Hello, author! I have a suggestion: Maybe, the plugin could be added a function: export .bin file, Why?
Becouse .abi + .bin could generate .go/.java/.objc abi-object-file by abigen(thus hardhat-abi-exporter plugin will be more useful, not only for ethers or web3js), eg:
[^ plus]: .bin file content is bytecode without 0x
in raw Oracle.json, like this:
{
// ...
"bytecode": "0x60806040523480156200001157600080fd5b5060405162001ac638038062001...",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100a9576000...",
"linkReferences": {},
"deployedLinkReferences": {}
}
โโโโ
60806040523480156200001157600080fd5b50604051620031d3380380620031d383398181016040528101...
( :: output File name suffix is not important, it's up to you, but maybe .bin
for bytecode and .abi
for abi are more accurate)
'
'
'
abigen target file like this:
abigen --bin Oracle.bin --abi Oracle.abi --pkg oracle -o oracle.go
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package oracle
import (
"errors"
"math/big"
"strings"
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
)
// Reference imports to suppress errors if they are not otherwise used.
var (
_ = errors.New
_ = big.NewInt
_ = strings.NewReader
_ = ethereum.NotFound
_ = bind.Bind
_ = common.Big1
_ = types.BloomLookup
_ = event.NewSubscription
)
// OracleMetaData contains all meta data concerning the Oracle contract.
var OracleMetaData = &bind.MetaData{
ABI: "[{\"inputs\":[],\"name\":\"ETH\",\"outputs\":...",
}
// OracleABI is the input ABI used to generate the binding from.
// Deprecated: Use OracleMetaData.ABI instead.
var OracleABI = OracleMetaData.ABI
// Oracle is an auto generated Go binding around an Ethereum contract.
type Oracle struct {
OracleCaller // Read-only binding to the contract
OracleTransactor // Write-only binding to the contract
OracleFilterer // Log filterer for contract events
}
// has more...
salute!
Hi
Thanks for such a great library!
I was wondering if there would be a feature to put all flattened ABIs into one file.
reasons:
I would expect the hardhat clean
command to remove the generated abis, the same way that typechain hooks into the clean
command and removes the code that it generates. Would be helpful when you've borked something and want to confirm that the state is fresh.
Thanks for this tool, it's super helpful. One feature I wish it supported is passing in a regex pattern and/or specifying specific subfolders to exclude in the except array.
For example if I had a file structure like:
contracts
L interfaces
..L IERC20.sol
..L IERC721.sol
MyContract.sol
OtherContract.sol
It would be great if I had a way to exclude all of the contracts in the interfaces directory without specifying each of the files individually. Would you consider adding support for this feature?
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch [email protected]
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/hardhat-abi-exporter/index.d.ts b/node_modules/hardhat-abi-exporter/index.d.ts
index 7b44cdf..baeb105 100644
--- a/node_modules/hardhat-abi-exporter/index.d.ts
+++ b/node_modules/hardhat-abi-exporter/index.d.ts
@@ -12,6 +12,8 @@ interface AbiExporterUserConfig {
format?: string,
filter?: (abiElement: any, index: number, abi: any, fullyQualifiedName: string) => boolean,
rename?: (sourceName: string, contractName: string) => string,
+ fileExtension?: '.json' | '.ts',
+ renameABI?: (name: string) => string,
}
declare module 'hardhat/types/config' {
@@ -32,6 +34,8 @@ declare module 'hardhat/types/config' {
format?: string,
filter: (abiElement: any, index: number, abi: any, fullyQualifiedName: string) => boolean,
rename: (sourceName: string, contractName: string) => string,
+ fileExtension?: '.json' | '.ts',
+ renameABI?: (name: string) => string,
}[]
}
}
diff --git a/node_modules/hardhat-abi-exporter/tasks/export_abi.js b/node_modules/hardhat-abi-exporter/tasks/export_abi.js
index d0c6ccd..9fdaa4c 100644
--- a/node_modules/hardhat-abi-exporter/tasks/export_abi.js
+++ b/node_modules/hardhat-abi-exporter/tasks/export_abi.js
@@ -61,9 +61,9 @@ subtask(
const destination = path.resolve(
outputDirectory,
config.rename(sourceName, contractName)
- ) + '.json';
+ ) + config.fileExtension || '.json';
- outputData.push({ abi, destination });
+ outputData.push({ abi, destination, contractName });
}));
outputData.reduce(function (acc, { destination }) {
@@ -79,8 +79,15 @@ subtask(
await hre.run('clear-abi-group', { path: config.path });
}
- await Promise.all(outputData.map(async function ({ abi, destination }) {
+ await Promise.all(outputData.map(async function ({ abi, destination, contractName }) {
await fs.promises.mkdir(path.dirname(destination), { recursive: true });
- await fs.promises.writeFile(destination, `${JSON.stringify(abi, null, config.spacing)}\n`, { flag: 'w' });
+ let fileContent = '';
+ if (config.fileExtension === '.ts') {
+ const name = config.renameABI ? config.renameABI(contractName) : `ABI_${contractName}`;
+ fileContent = `const ${name} = ${JSON.stringify(abi, null, config.spacing)} as const;\nexport default ${name};\n`;
+ } else {
+ fileContent = `${JSON.stringify(abi, null, config.spacing)}\n`;
+ }
+ await fs.promises.writeFile(destination, fileContent, { flag: 'w' });
}));
});
This issue body was partially generated by patch-package.
The hardhat-coverage
plugin modifies contract code, and also the associated ABIs. ABI export should be disabled when this plugin is in use.
See also: ItsNickBarry/hardhat-contract-sizer#8
Hi there, thanks for this plugin!
Would be great to have the option to export only some functions and events to have lighter ABIs...
Is this feature would makes sense on this plugin? What do you recommend to implement it?
It'd be happy to contribute on this one.
Best regards,
Luca
hardhat-abi-exporter/tasks/export_abi.js
Line 71 in 4949db3
This line throws when I compile a combination of Uniswap v3 core and periphery contract libraries. I get:
Error in plugin hardhat-abi-exporter: duplicate output destination: .../uniswap/v3-core/abi/IUniswapV3Factory.json
when compiling, despite there only being one interface in the whole repo named IUniswapV3Factory.
Disabling this line throws no error.
Perhaps the error is unnecessary since a set is used anyway, so duplicate abi's will just be ignored anyway? or perhaps the abi's should be diffed instead (e.g. using lodash.isEqual
) and if the diff does not match, then the error thrown.
I am trying to deploy a contract, and each version has the same error message, deleting the ABI folder does nothing, deleting all cache folders and other compile time folders also doesn't work.
Error in plugin hardhat-abi-exporter: duplicate output destination: /Users/computer/folder/testCoin-4/abis/Ownable.json
I have tried running clear & also trying a fresh install. I have also changed folder names, and moved their destination, starting from a fresh starter also doesn't help.
abiExporter: { path: "./abis", runOnCompile: true, clear: true, flat: true, only: [], spacing: 2, pretty: true, },
The description explicitly mentions solidity but isn't ABI generation only dependent on the bytecode?
Will it work for vyper too?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.