
Product
Introducing Immutable Scans
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.
hardhat-diamond-abi
Advanced tools
Hardhat plugin to combine multiple ABIs into a Diamond ABI artifact.
Hardhat plugin to combine multiple ABIs into a Diamond ABI artifact
The Diamond Pattern, or EIP-2535, is an upgrade and proxy pattern that registers functions from many different Smart Contracts, called Facets, into a single Diamond.
Once registered, all functions can be accessed through the Diamond; however, you still need the ABI for the original Facet to make interacting easy. This plugin can be used to combine all the ABIs from your Facets into a single ABI to work with any functions in your Diamond.
This is also very useful if you are using TypeChain and @nomiclabs/hardhat-ethers because we ensure that TypeChain will generate types for your Diamond ABI, which can then be loaded using:
const diamond = await hre.ethers.getContractAt("MyDiamond", CONTRACT_ADDRESS);
npm install hardhat-diamond-abi
Import the plugin in your hardhat.config.js:
require("hardhat-diamond-abi");
Or if you are using TypeScript, in your hardhat.config.ts:
import "hardhat-diamond-abi";
This plugin hooks Hardhat's internal TASK_COMPILE_SOLIDITY_COMPILE_JOBS task, and doesn't provide any additional tasks.
The reason for this is two-fold:
artifacts directory the next time Hardhat is run.As mentioned above, this plugin uses the same hook as TypeChain. If you load this plugin before TypeChain, it will see the artifact we generate and create TypeScript types for your Diamond ABI!
It is very important that you import this plugin before TypeChain, otherwise it won't see our artifact when it generates types.
Set up your project (we'll use best_dapp_ever/) with the following minimal hardhat.config.js at the root. The only required property is name, which is used to name your Diamond ABI.
module.exports = {
solidity: "0.8.10",
diamondAbi: {
// (required) The name of your Diamond ABI
name: "BestDappEver",
},
};
Your project structure should look like this:
j:~/best_dapp_ever/ $ tree
βββ hardhat.config.js
βββ contracts
βββ FacetA.sol
βββ FacetB.sol
Now, when you use npx hardhat compile to compile your contracts, a new ABI will exist in your artifacts.
j:~/best_dapp_ever/ $ tree
βββ hardhat.config.js
βββ artifacts
β βββ contracts
β β βββ FacetA.sol
β β β βββ FacetA.dbg.json
β β β βββ FacetA.json
β β βββ FacetB.sol
β β βββ FacetB.dbg.json
β β βββ FacetB.json
β βββ hardhat-diamond-abi
β βββ BestDappEver.sol
β βββ BestDappEver.json
βββ contracts
βββ FacetA.sol
βββ FacetB.sol
If you'd like to adjust details about the included ABIs or individual functions, you can adjust any of these settings:
module.exports = {
solidity: "0.8.10",
diamondAbi: {
// (required) The name of your Diamond ABI.
name: "BestDappEver",
// (optional) An array of strings, matched against fully qualified contract names, to
// determine which contracts are included in your Diamond ABI.
include: ["Facet"],
// (optional) An array of strings, matched against fully qualified contract names, to
// determine which contracts are excluded from your Diamond ABI.
exclude: ["vendor"],
// (optional) A function that is called with the ABI element, index, entire ABI,
// and fully qualified contract name for each item in the combined ABIs.
// If the function returns `false`, the function is not included in your Diamond ABI.
filter: function (abiElement, index, fullAbi, fullyQualifiedName) {
return abiElement.name !== "superSecret";
},
// (optional) Whether exact duplicate sighashes should cause an error to be thrown,
// defaults to true.
strict: true,
},
};
FAQs
Hardhat plugin to combine multiple ABIs into a Diamond ABI artifact.
The npm package hardhat-diamond-abi receives a total of 116 weekly downloads. As such, hardhat-diamond-abi popularity was classified as not popular.
We found that hardhat-diamond-abi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 2 open source maintainers 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.

Product
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.