1.0.0 • Published 2 years ago

@vondas/loupe v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

loupe

One tool for Smart Contract extraction

What does it do?

loupe excels at one thing, Smart Contract extraction. It can extract master Solidity files which contain multiple contracts in one file as well as Solidity files that are aggregated into a nested JSON file. The type of Solidity file returned by loupe is blockchain dependent.

Ethereum/Binance

On Ethereum/Binance, we found most Smart Contracts are either an individual Smart contract with multiple functions or a Smart Contract that containes multiple Solidity files.

Avalanche

On Avalanche, we found most responses to be JSON files containing multiple Solidity files nested within an object.

0x053502bf08b7d3a54891bb66fb966ea4c4ba7d02

Preparing files for compiling

Requirements

Support Blockchains

An API key is required for each Etherscan clone, free tiers are available.

Testnet

TestnetBlockchainEndpoint
RopstenEthereumhttps://api-ropsten.etherscan.io
KovanEthereumhttps://api-kovan.etherscan.io
RinkebyEthereumhttps://api-rinkeby.etherscan.io

Mainnet

MainnetEndpointDocs
Ethereumhttps://api.etherscan.iohttps://docs.etherscan.io/
Avalanchehttps://api.snowtrace.iohttps://snowtrace.io/apis
Binancehttps://api.bscscan.comhttps://docs.bscscan.com/
Hecohttps://api.hecoinfo.comhttps://hecoinfo.com/apis
Cronoshttps://api.cronoscan.comhttps://cronoscan.com/apis
Moonriverhttps://api-moonriver.moonscan.iohttps://moonriver.moonscan.io/apis
Moonbeamhttps://blockscout.moonbeam.networkhttps://blockscout.moonbeam.network/api-docs
Arbitrumhttps://api.arbiscan.iohttps://arbiscan.io/apis
Fantomhttps://api.ftmscan.comhttps://ftmscan.com/apis
Hooscanhttps://api.hooscan.comhttps://hooscan.com/apis
Optimismhttps://api-optimistic.etherscan.iohttps://optimistic.etherscan.io/apis

Usage

Create .env file for Environmental Variables

  • In the root folder, create a new file for the environmental variables called .env
  • Copy/paste the text below into the .env file
  • Remove XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX and add the associated API Key
  • Save .env
# ADD API KEYS HERE
ETHEREUM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
AVALANCHE_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
BINANCE_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
HECO_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
CRONOS_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
MOONRIVER_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
MOONBEAM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ARBITRUM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
FANTOM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
HOOSCAN_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
OPTIMISM_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  • The API keys above are associated with an array located in init.js
var chainKey = {
    "keyEthereum": process.env.ETHEREUM_API_KEY,
    "keyAvalanche": process.env.AVALANCHE_API_KEY,
    "keyBinance": process.env.BINANCE_API_KEY,
    "keyHeco": process.env.HECO_API_KEY,
    "keyCronos": process.env.CRONOS_API_KEY,
    "keyMoonriver": process.env.MOONRIVER_API_KEY,
    "keyMoonbeam": process.env.MOONBEAM_API_KEY,
    "keyArbitrum": process.env.ARBITRUM_API_KEY,
    "keyFantom": process.env.FANTOM_API_KEY,
    "keyHooscan": process.env.HOOSCAN_API_KEY,
    "keyOptimism": process.env.OPTIMISM_API_KEY
}

Installation

npm

npm i @vondas/loupe

Usage

//Load express module with `require` directive
let dotenv_module;
dotenv_module = require("dotenv");
dotenv_module.config();

const loupe = require('./lib/loupe');

const blockchains = ['ethereum', 'avalanche', 'binance', 'heco', 'cronos', 'moonriver', 'moonbeam', 'arbitrum', 'fantom', 'hooscan', 'optimism'];
const blockchain = blockchains[1];
const contract_address = '0x6cddb55d0ac3204a0bc4f3e3eb03407b1ad59e5c';
console.log(blockchain, contract_address);
loupe.getSmartContracts(blockchain, contract_address);