Giter Site home page Giter Site logo

pugson / abi-data Goto Github PK

View Code? Open in Web Editor NEW
43.0 4.0 4.0 557 KB

Grab your smart contract’s ABI as JSON from Etherscan. Supports multiple chains and testnets.

Home Page: https://abidata.net

License: The Unlicense

JavaScript 3.07% TypeScript 79.63% CSS 17.30%
ethereum ethereum-contract wagmi arbitrum polygon avalanche base bsc optimism

abi-data's Introduction

ABI Data — grab your smart contract’s ABI as JSON from Etherscan, Polygonscan, Arbiscan, BaseScan, BscScan, FTMScan, Snowtrace, GnosisScan

og-image

Fetch smart contract ABI JSON to use with wagmi and ethers.js in your app. Records are cached for 365 days, so after the initial request for a contract, the API will respond very quickly from the CDN. This is just a simple wrapper around various *scan APIs.

General usage

Supported networks:

Network name Network ID
Ethereum Mainnet none (default)
Ethereum Goerli Testnet goerli
Ethereum Sepolia Testnet sepolia
Avalanche Mainnet avalanche
Avalanche Fuji Testnet avalancheFuji
Arbitrum Mainnet arbitrum
Arbitrum Goerli Testnet arbitrumGoerli
Arbitrum Nova arbitrumNova
Base Mainnet base
Base Goerli Testnet baseGoerli
BSC Mainnet bsc
BSC Testnet bscTestnet
Fantom Mainnet fantom
Fantom Testnet fantomTestnet
Polygon Mainnet polygon
Polygon Mumbai Testnet polygonMumbai
Polygon zkEVM polygonZkEvm
Polygon zkEVM Testnet polygonZkEvmTestnet
Optimism Mainnet optimism
Optimism Goerli Testnet optimismGoerli
Gnosis Mainnet gnosis
https://abidata.net/<contract_address>?network=<network_id>

Examples:

React usage example

import { useState, useEffect } from "react";
import { useContractWrite, usePrepareContractWrite } from "wagmi";

const contractAddress = "0xecb504d39723b0be0e3a9aa33d646642d1051ee1";

const useContractABI = (contractAddress) => {
  const [contractABI, setContractABI] = useState(null);

  useEffect(() => {
    const fetchContractABI = async () => {
      const response = await fetch(`https://abidata.net/${contractAddress}`);
      const json = await response.json();
      setContractABI(json.abi);
    };

    fetchContractABI();
  }, [contractAddress]);

  return contractABI;
};

function App() {
  const contractABI = useContractABI(contractAddress);
  const { config } = usePrepareContractWrite({
    address: contractAddress,
    abi: contractABI,
    functionName: "feed",
  });

  const { data, isLoading, isSuccess, write } = useContractWrite(config);

  return (
    <div>
      <button disabled={!write} onClick={() => write?.()}>
        Feed
      </button>
      {isLoading && <div>Check Wallet</div>}
      {isSuccess && <div>Transaction: {JSON.stringify(data)}</div>}
    </div>
  );
}

Development

This is a Next.js app. First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev

Open http://localhost:3000 with your browser to see the result.

abi-data's People

Contributors

gskril avatar pugson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

abi-data's Issues

In search of type safe working example.

Hi @pugson I'm interested in using this along wagmi, as the example shows, but want to ensure that I'm getting type safety and the auto complete features that come with declaring your ABI as a const.

Do you know of any examples in the wild that are successfully achieving this?

Support more networks

AFAIK after reading the source code, I found that the app only supports Ethereum Mainnet and Goerli testnet. Since the most used networks also have their etherscan-like explorers, like Polygon has polygonscan.com, etc. It should be possible to include the support for all of these.

I will be very happy to submit a PR if maintainers are interested.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.