Skip to content

Commit

Permalink
Merge pull request #1 from soos3d/main
Browse files Browse the repository at this point in the history
standardize
  • Loading branch information
akegaviar authored Jan 26, 2023
2 parents 23fc6a7 + c49f5b4 commit f05bdc8
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CHAINSTACK_FULL_NODE="CHAINSTACK_FULL_NODE_URL"
CHAINSTACK_ARCHIVE_NODE="CHAINSTACK_ARCHIVE_NODE_URL"
121 changes: 120 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,120 @@
node_modules/
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env.production

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# End of https://mrkandreev.name/snippets/gitignore-generator/#Node
104 changes: 96 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,102 @@
# Full vs Archive Node query
<img width="1200" alt="Labs" src="https://user-images.githubusercontent.com/99700157/213291931-5a822628-5b8a-4768-980d-65f324985d32.png">

This repository contains the javascript version to query common state functions such as `getBalance()` and custom smart contract functions such as `symbol()` (ERC-20) from a given block in a programmatic way, switching between full and archive nodes when needed.
<p>
<h3 align="center">Chainstack is the leading suite of services connecting developers with Web3 infrastructure</h3>
</p>

For the full walkthrough, see [Querying full and archive Ethereum nodes with JavaScript](https://chainstack.com/querying-full-and-archive-evm-nodes-with-javascript/).
<p align="center">
<a target="_blank" href="https://chainstack.com/build-better-with-ethereum/"><img src="https://github.com/soos3d/blockchain-badges/blob/main/protocols_badges/Ethereum.svg" /></a>&nbsp;
<a target="_blank" href="https://chainstack.com/build-better-with-bnb-smart-chain/"><img src="https://github.com/soos3d/blockchain-badges/blob/main/protocols_badges/BNB.svg" /></a>&nbsp;
<a target="_blank" href="https://chainstack.com/build-better-with-polygon/"><img src="https://github.com/soos3d/blockchain-badges/blob/main/protocols_badges/Polygon.svg" /></a>&nbsp;
<a target="_blank" href="https://chainstack.com/build-better-with-avalanche/"><img src="https://github.com/soos3d/blockchain-badges/blob/main/protocols_badges/Avalanche.svg" /></a>&nbsp;
<a target="_blank" href="https://chainstack.com/build-better-with-fantom/"><img src="https://github.com/soos3d/blockchain-badges/blob/main/protocols_badges/Fantom.svg" /></a>&nbsp;
</p>

### Instructions
<p align="center">
• <a target="_blank" href="https://chainstack.com/">Homepage</a> •
<a target="_blank" href="https://chainstack.com/protocols/">Supported protocols</a> •
<a target="_blank" href="https://chainstack.com/blog/">Chainstack blog</a> •
<a target="_blank" href="https://docs.chainstack.com/quickstart/">Chainstack docs</a> •
<a target="_blank" href="https://docs.chainstack.com/quickstart/">Blockchain API reference</a> •
<a target="_blank" href="https://console.chainstack.com/user/account/create">Start for free</a> •
</p>

# Querying full and archive EVM nodes with JavaScript

This project allows the retrieval of historical data from the blockchain programmatically, switching between a full and archive node provider when necessary.

See the full tutorial on the Chainstack blog:
* [Querying full and archive Ethereum nodes with JavaScript](https://chainstack.com/querying-full-and-archive-evm-nodes-with-javascript/)

## Project details

This repository holds the JavaScript version of a tool to query common state functions. Some essential functions include getting an address balance and storage at a given position, a contract bytecode, or even the whole transactions included on a given block.

This tool queries the blockchain using the web3 and inquirer libraries for JavaScript.

## Quick start

### Clone this repository

```sh
git clone https://github.com/yieniggu/chainstack-full-vs-archive-query-js.git
```
git clone https://github.com/yieniggu/chainstack-full-vs-archive-query-js.git
cd chainstack-full-vs-archive-query-js
npm i
node index

### Install dependencies

```sh
npm ci
```

> Use `npm ci` to launch a `clean install` of the dependencies, this will install the same version as in the `package.json` file.
### edit the .env.sample file

Add your RPC node URLs and rename the file to `.env`.

```env
CHAINSTACK_FULL_NODE="CHAINSTACK_FULL_NODE_URL"
CHAINSTACK_ARCHIVE_NODE="CHAINSTACK_ARCHIVE_NODE_URL"
```

### Run the program

```sh
npm run start
```

## Prerequisites

* Node.js: ^16.17.0— [install Node](https://nodejs.org/en/download/)
* A full and archive node RPC endpoints.

Deploy a full and archive node with Chainstack:

1. [Sign up with Chainstack](https://console.chainstack.com/user/account/create).
1. [Deploy a node](https://docs.chainstack.com/platform/join-a-public-network).
1. [View node access and credentials](https://docs.chainstack.com/platform/view-node-access-and-credentials).

## Dependencies

* dotenv: ^16.0.3
* inquirer: ^8.2.4
* web3.js: ^1.7.4

## Install

Clone this repository:

```sh
git clone https://github.com/yieniggu/chainstack-full-vs-archive-query-js.git
```

Install the dependencies in the project's directory:

```sh
cd query-full-and-archive-nodes-javascript
```

```sh
npm ci
```
> Use `npm ci` to launch a `clean install` of the dependencies, this will install the same version as in the `package.json` file.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "query-full-archive",
"version": "1.0.0",
"description": "",
"description": "This tool allows the retrieval of historical data from the blockchain programmatically, switching between a full and archive node provider when necessary.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start" : "node index"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.3",
"inquirer": "^8.2.4",
"web3": "^1.7.4"
}
Expand Down
9 changes: 3 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// Initial Config
const Web3 = require("web3");
require('dotenv').config()

// Init Full and Archive providers
const fullNodeProvider = new Web3(
"https://nd-479-987-415.p2pify.com/271156373b36700f7576cf46e68b1262"
);
const archiveNodeProvider = new Web3(
"https://nd-072-228-848.p2pify.com/3f7a80739e2f6739cae0256a2660725b"
);
const fullNodeProvider = new Web3(process.env.CHAINSTACK_FULL_NODE);
const archiveNodeProvider = new Web3(process.env.CHAINSTACK_ARCHIVE_NODE);

const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";

Expand Down

0 comments on commit f05bdc8

Please sign in to comment.