
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@gnosis-guild/eth-sdk
Advanced tools
đź› Generate type-safe, lightweight SDK for your Ethereum smart contracts
Generate type-safe, lightweight SDK for your Ethereum smart contracts
The quickest and easiest way to interact with Ethereum
This is a community fork of @dethcrypto/eth-sdk for making it ethers v6 compatible.
eth-sdk has been created and maintained by deth (@dethcrypto).
deth (@dethcrypto) MIT
with contributions by Gnosis Guild (@gnosisguild) MIT
yarn add --dev @gnosis-guild/eth-sdk @gnosis-guild/eth-sdk-client
eth-sdk uses ethers v6 and TypeScript, so these dependencies have to be installed as well.
eth-sdk [options]
Options:
-p, --path <path> working directory (default: ./eth-sdk)
eth-sdk looks for the config file in this directory, and saves downloaded ABIs there.
eth-sdk takes a JSON config file with ethereum addresses and generates a fully type-safe SDK that you can use right
away. The SDK is an object consisting of ethers.js contracts initialized with ABIs provided by etherscan and with types
generated via TypeChain.
The first step is to create a config file specifying contracts that we wish to interact with. Default path to this file
is eth-sdk/config.ts.
import { defineConfig } from '@gnosis-guild/eth-sdk'
export default defineConfig({
contracts: {
mainnet: {
dai: '0x6b175474e89094c44da98b954eedeac495271d0f',
},
},
})
The key directly under "contracts" is a network identifier, eth-sdk needs it to query ABI information automatically.
Following are key-value pairs of contract names and addresses. These can be deeply nested.
Now you're ready to run yarn eth-sdk. Few things will happen under the hood:
eth-sdk directory (you should commit them to git to speed up the process in the future).getMainnetSdk exposed. These functions wire addresses with ABIs
and create ethers.js contract instances.node_modules, access it as @gnosis-guild/eth-sdk-client.Using generated sdk is as simple as it gets:
import { getMainnetSdk } from '@gnosis-guild/eth-sdk-client' // yay, our SDK! It's tailored especially for our needs
import { ethers } from 'ethers'
async function main() {
const mainnetProvider = ethers.getDefaultProvider('mainnet')
const defaultSigner = ethers.Wallet.createRandom().connect(mainnetProvider)
const sdk = getMainnetSdk(defaultSigner) // default signer will be wired with all contract instances
// sdk is an object like { dai: DaiContract }
const balance = sdk.dai.balanceOf(defaultSigner.address)
}
main()
.then(() => console.log('DONE'))
.catch((error) => {
console.error(error)
process.exit(1)
})
eth-sdk looks for a file named config or eth-sdk.config with .ts, .json, .js or .cjs extension inside of
the directory specified by --path CLI argument.
You can use exports from @gnosis-guild/eth-sdk to leverage your IDE's intellisense. Exported types are EthSdkConfig,
EthSdkContracts, NestedAddresses and Address.
import type { EthSdkConfig } from '@gnosis-guild/eth-sdk'
const config: EthSdkConfig = {
// ...
}
export default config
Alternatively, you can use defineConfig function to write your config in a typesafe way without need for annotations.
import { defineConfig } from '@gnosis-guild/eth-sdk'
export default defineConfig({
// ...
})
contractsA map from network identifier into deeply nested key-value pairs of contract names and addresses.
{
"contracts": {
"eth": {
"dai": "0x6b175474e89094c44da98b954eedeac495271d0f",
"dao": {
"mkr": "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2"
}
}
}
}
Supported network identifiers are:
"eth" "holesky" "sep"
"gno" "base" "basesep"
"bsc" "oeth" "matic"
"arb1" "avax" "celo"
"sonic" "berachain" "mantle"
"zkevm" "unichain" "wc"
"bob" "hemi" "katana"
"linea" "ink" "blast"
"flare"
outputPathOutput directory for generated SDK.
Defaults to ./node_modules/.gnosisguild/eth-sdk
{
"outputPath": "./node_modules/.gnosisguild/eth-sdk"
}
Check out examples of using eth-sdk in /examples directory.
The primary motivation for the project is reducing the ceremony needed to interact with smart contracts on Ethereum while using JavaScript or TypeScript. It takes care of boring parts like ABI management and auto-generates all the boilerplate required to set up ethers.js contract instances. Finally, it makes DX great by ensuring that all contracts have type information so your IDE can assist you.
It works well with all sorts of scripts, backend services, and even frontend apps. Note: If you develop smart contracts it's better to use TypeChain directly (especially via HardHat integration).
Check out our contributing guidelines.
FAQs
đź› Generate type-safe, lightweight SDK for your Ethereum smart contracts
The npm package @gnosis-guild/eth-sdk receives a total of 69 weekly downloads. As such, @gnosis-guild/eth-sdk popularity was classified as not popular.
We found that @gnosis-guild/eth-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.