All Projects → dethcrypto → eth-sdk

dethcrypto / eth-sdk

Licence: MIT license
Type-safe, lightweight SDKs for Ethereum smart contracts

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to eth-sdk

solidity-cli
Compile solidity-code faster, easier and more reliable
Stars: ✭ 49 (-82.69%)
Mutual labels:  dapp, web3
openzeppelin-network.js
An easy to use and reliable library that provides one line access to Web3 API.
Stars: ✭ 45 (-84.1%)
Mutual labels:  dapp, web3
kleros-api-DEPRECATED
A Javascript library that makes it easy to build relayers and other DApps that use the Kleros protocol. DEPRECATED use https://github.com/kleros/archon for interfacing with standard arbitration contracts.
Stars: ✭ 20 (-92.93%)
Mutual labels:  dapp, web3
NFT-Dapp-Boilerplate
A highly scalable NFT and DEFI boilerplate with pre added web3 and different wallets with a focus on performance and best practices
Stars: ✭ 51 (-81.98%)
Mutual labels:  dapp, web3
eth-commerce
Javascript library to accept ethereum payments on any website
Stars: ✭ 24 (-91.52%)
Mutual labels:  dapp, web3
court
The Kleros court user interface.
Stars: ✭ 19 (-93.29%)
Mutual labels:  dapp, web3
ton-client-js
Everscale Javascript SDK
Stars: ✭ 60 (-78.8%)
Mutual labels:  dapp, web3
dtube
Decentralized video sharing & social media platform on Ethereum blockchain.
Stars: ✭ 70 (-75.27%)
Mutual labels:  dapp, web3
typescript-eth-starter
🔌 Ethereum Dapp Basic Typescript Starter
Stars: ✭ 125 (-55.83%)
Mutual labels:  dapp, web3
MultiDexArbBot
This is an arbitrage bot that uses existing price aggregators such as 1inch, Paraswap, dex.ag, matcha and more to get the best exchange rates across different decentralized exchanges on different blockchains and ecosystems.
Stars: ✭ 67 (-76.33%)
Mutual labels:  dapp, web3
vue-web3
🐙 Web3 blockchain bindings for Vue.js (inspired by Vuefire and Drizzle)
Stars: ✭ 63 (-77.74%)
Mutual labels:  dapp, web3
web3-webpacked
Drop-in web3 solution for single-page Ethereum dApps
Stars: ✭ 36 (-87.28%)
Mutual labels:  dapp, web3
colonyDapp
Colony dApp client
Stars: ✭ 52 (-81.63%)
Mutual labels:  dapp, web3
foodprint
Algorand dApp for blockchain-enabled food transparency and traceability in local food supply chains. For use by smallholder farmers, food co-operatives and consumers.
Stars: ✭ 43 (-84.81%)
Mutual labels:  dapp, web3
LunDAO
LunDAO 是一個鼓勵撰寫與 Ethereum 社群相關的中深度的中文文章,透過一個短期的實驗專案嘗試 DAO 可以如何進行社群治理以及回饋社群貢獻。
Stars: ✭ 50 (-82.33%)
Mutual labels:  dapp, web3
starter-kit-gsn
An OpenZeppelin starter kit focused on GSN.
Stars: ✭ 39 (-86.22%)
Mutual labels:  dapp, web3
zksync-dapp-checkout
zkCheckout — trustable permissionless DeFi payment gateway. Brand new zkSync dApp w/t all L2 perks: fast&cheap transfers / simple&quick withdrawal
Stars: ✭ 37 (-86.93%)
Mutual labels:  dapp, web3
create-react-native-dapp
Your next Ethereum application starts here. ⚛️ 💪 🦄
Stars: ✭ 410 (+44.88%)
Mutual labels:  dapp, web3
cyberevents
The protocol for EVENTs and TICKETs
Stars: ✭ 16 (-94.35%)
Mutual labels:  dapp, web3
nft-app
How to create your own NFT and mint NFT token
Stars: ✭ 145 (-48.76%)
Mutual labels:  dapp, web3

eth-sdk

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

The quickest and easiest way to interact with Ethereum

Build Status Software License Join our discord!

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

Installation

yarn add --dev @dethcrypto/eth-sdk @dethcrypto/eth-sdk-client

eth-sdk uses ethers.js 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 '@dethcrypto/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 @dethcrypto/eth-sdk-client.

Using generated sdk is as simple as it gets:

import { getMainnetSdk } from '@dethcrypto/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 @dethcrypto/eth-sdk to leverage your IDE's intellisense. Exported types are EthSdkConfig, EthSdkContracts, NestedAddresses and Address.

import type { EthSdkConfig } from '@dethcrypto/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 '@dethcrypto/eth-sdk'
export default defineConfig({
  // ...
})

contracts

A map from network identifier into deeply nested key-value pairs of contract names and addresses.

{
  "contracts": {
    "mainnet": {
      "dai": "0x6b175474e89094c44da98b954eedeac495271d0f",
      "dao": {
        "mkr": "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2"
      }
    }
  }
}

Predefined network identifiers are:

"mainnet"            "ropsten"            "rinkeby"
"goerli"             "kovan"              "bsc"
"bscTestnet"         "heco"               "hecoTestnet"
"opera"              "ftmTestnet"         "optimism"
"optimismKovan"      "polygon"            "polygonMumbai"
"arbitrumOne"        "arbitrumTestnet"

You can use other networks, but you will need to configure Etherscan URLs for them in etherscanURLs or provide networkIds when using Sourcify as abiSource.

outputPath

Output directory for generated SDK.

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

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

etherscanKeys

Etherscan API keys

Defaults to eth-sdk's own keys.

{
  "etherscanKeys": {
    // API key for https://etherscan.io
    "mainnet": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    // API key for https://polygonscan.com
    "polygon": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
  }
}

etherscanURLs

Key-value pairs of network identifier and Etherscan API URL to fetch ABIs from.

{
  "etherscanURLs": {
    "helloworld": "https://api.etherscan.io/api"
  },
  "contracts": {
    "helloworld": {}
  }
}

rpc

Configuration for Ethereum JSON-RPC provider needed for following proxies.

{
  "rpc": {
    "mainnet": "https://mainnet.infura.io/v3/00000000000000000000000000000000",
    "kovan": "https://kovan.infura.io/v3/00000000000000000000000000000000"
  }
}

For every contract address, eth-sdk checks if it's a proxy, and if it is, it saves the ABI of the implementation contract instead of the ABI of the proxy.

noFollowProxies

You can opt out of proxy following by setting noFollowProxies flag in your config to true.

{
  "noFollowProxies": true
}

abiSource

Default: "etherscan"

One of "etherscan", "sourcify". Specifies the source to fetch contract ABIs from.

networkIds

As Sourcify /files endpoint requires network identifier, you will need to provide one when using a custom network.

{
  "abiSource": "sourcify",
  "networkIds": {
    "myNetwork": 3
  },
  "contracts": {
    "myNetwork": {
      "dai": "0x6b175474e89094c44da98b954eedeac495271d0f"
    }
  }
}

eth-sdk already knows ids of 19 commonly used networks, including mainnet, testnets, Optimism and Arbitrum, so you won't need to provide them. You can find the list of all predefined networks in contracts documentation.

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.

License

deth (@dethcrypto) MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].