@gnosis-guild/eth-sdk

中文文档
0.4.0发布于 2025/09/29MITTypeScriptCommonJS近 30 天下载 3742

🛠 Generate type-safe, lightweight SDK for your Ethereum smart contracts

原始使用文档
文档目录10 节
  1. eth-sdk
  2. Features ⚡
  3. Fork notice
  4. License
  5. CLI Options
  6. Getting started
  7. Configuration
  8. contracts
  9. outputPath
  10. Videos

eth-sdk

Generate type-safe, lightweight SDK for your Ethereum smart contracts

The quickest and easiest way to interact with Ethereum

Features ⚡

  • minimal - just provide addresses of contracts that you wish to interact with
  • easy to use - ABIs will be automatically downloaded from Etherscan
  • familiar API - Generates ethers.js contract wrappers
  • type-safe - Leverages TypeChain for maximum type-safety

Fork notice

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).

License

deth (@dethcrypto) MIT

with contributions by Gnosis Guild (@gnosisguild) MIT


Installation

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.

Usage

eth-sdk [options]

CLI 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.

Getting started

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:

  1. Etherscan API will be queried in search of ABIs corresponding to the addresses. ABIs will be downloaded into eth-sdk directory (you should commit them to git to speed up the process in the future).
  2. Minimal SDK will be generated with functions like getMainnetSdk exposed. These functions wire addresses with ABIs and create ethers.js contract instances.
  3. TypeScript types will be generated for SDK using TypeChain.
  4. SDK is generated directly into 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)
  })

Configuration

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({
  // ...
})

contracts

A 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"

outputPath

Output directory for generated SDK.

Defaults to ./node_modules/.gnosisguild/eth-sdk

{
  "outputPath": "./node_modules/.gnosisguild/eth-sdk"
}

Examples

Check out examples of using eth-sdk in /examples directory.

Videos

Motivation and use cases

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).

Contributing

Check out our contributing guidelines.

版本与发布记录

@gnosis-guild/eth-sdk 共发布 8 个版本,首次发布于 2024/08/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.4.0latest2025/09/291.1 年前
0.3.102025/07/261.3 年前
0.3.92025/05/291.5 年前
0.3.82025/04/031.6 年前
0.3.72024/08/292 年前
0.3.62024/08/282 年前

关于 @gnosis-guild/eth-sdk 的常见问题

@gnosis-guild/eth-sdk 是什么?

🛠 Generate type-safe, lightweight SDK for your Ethereum smart contracts

如何安装 @gnosis-guild/eth-sdk?

在项目目录运行 npm install @gnosis-guild/eth-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ethers(^6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 eth-sdk,可以用 npx eth-sdk 直接运行。

@gnosis-guild/eth-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gnosis-guild/eth-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@gnosis-guild/eth-sdk 可以商用吗?

@gnosis-guild/eth-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gnosis-guild/eth-sdk 的下载量有多少?

根据 npm 官方下载统计,@gnosis-guild/eth-sdk 在 2026/10/17 – 2026/11/15 这 30 天内被下载 3,742 次,日均约 125 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gnosis-guild/eth-sdk 还在维护吗?

最新版本 0.4.0 发布于 2025/09/29(1.1 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/08/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。