
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@dlsl/hardhat-gobind
Advanced tools
Hardhat plugin to simplify generation of smart contract bindings for Golang.
This plugin helps you generate .go
files with bindings to call smart contracts from Go code. To produce them, the plugin uses abigen
in a wasm
binary form that is built from go-ethereum/cmd/abigen Go module.
npm install --save-dev @dlsl/hardhat-gobind
Add the following statement to your hardhat.config.js
:
require("@dlsl/hardhat-gobind")
Or, if you are using TypeScript, add this to your hardhat.config.ts
:
import "@dlsl/hardhat-gobind"
The bindings generation can be run either with built-in compile
or the provided gobind
task.
To view the available options, run these help commands:
npx hardhat help compile
npx hardhat help gobind
This plugin does not extend the environment.
The plugin works out of the box: npx hardhat gobind
will compile and generate bindings for all the contracts used in the project into the default folder.
To generate the most recent bindings, clean old artifacts with npx hardhat clean
beforehand.
The default configuration looks as follows. You may customize all fields in your hardhat config file.
module.exports = {
gobind: {
outdir: "./generated-types/bindings",
deployable: false,
runOnCompile: false,
verbose: false,
onlyFiles: [],
skipFiles: [],
},
}
outdir
: The directory where the generated bindings will be placeddeployable
: Generates the bindings with the bytecode (makes them deployable within Go)runOnCompile
: Whether to run bindings generation on compilationverbose
: Detailed logging on generation (e.g. count of included and skipped contracts, source paths, names)onlyFiles
: If specified, bindings will be generated only for matching sources, other will be ignoredskipFiles
: Bindings will not be generated for any matching sources, also if those match onlyFiles
Some of the parameters are only available in CLI and they override the ones defined in your hardhat config (e.g. --deployable
will generate deploy method regardless of config.gobind.deployable
value). Run npx hardhat help gobind
to get available options.
.sol
file or directory.node_modules
must not be present in the path.The plugin runs compile
task (if --no-compile
is not given), gets the artifacts from Hardhat Runtime Environment (HRE), filters them according to onlyFiles
and skipFiles
, and performs the following actions:
ContractName.abi
(and ContractName.bin
with bytecode)../contracts
, the folder will be ./your_outdir/contracts
../your_outdir/nested/My_Contracts
it will be mycontracts
.abigen
via WebAssembly: abigen --abi /path/to/file.abi --pkg packagename --type ContractName --lang go --out /path/to/your_project/your_outdir
(and --bin /path/to/file.bin
, if necessary).Bindings are generated for contracts, not files. Having 3 contracts in a single file, you get 3 .go
files named after contracts. If you skip the file, all 3 contracts are ignored.
Consider we have Hardhat project with the following structure (excluding some files for brevity):
.
├── contracts
│ ├── Example.sol
│ ├── Sample.sol
│ └── interfaces
│ ├── IExample.sol
│ └── ISample.sol
├── hardhat.config.ts
└── node_modules
└── @openzeppelin
└── contracts
└── access
├── Ownable.sol
└── Ownable2Step.sol
npx hardhat gobind
with the default configuration will create the following directory structure. Note there are no node_modules
parent directory for @openzeppelin
dependency.
generated-types
└── bindings
├── @openzeppelin
│ └── contracts
│ └── access
│ ├── Ownable.go
│ └── Ownable2Step.go
└── contracts
├── Example.go
├── Sample.go
└── interfaces
├── IExample.go
└── ISample.go
In most cases, you want bindings only for your contracts/
directory, excluding contracts/interfaces
and all the dependencies from node_modules
.
It is achieved by adding the following into your hardhat config:
onlyFiles: ["contracts"],
skipFiles: ["contracts/interfaces", "@openzeppelin", "@dlsl"],
--verbose
is not available in CLI because of names clash with Hardhat. Learn more.node_modules
must not be present in the path.FAQs
Generation of smart contract bindings for Golang
We found that @dlsl/hardhat-gobind 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.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.