Skip to content

Commit 0f1e883

Browse files
committed
standardize
1 parent 23fc6a7 commit 0f1e883

File tree

6 files changed

+233
-17
lines changed

6 files changed

+233
-17
lines changed

.env.sample

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHAINSTACK_FULL_NODE="CHAINSTACK_FULL_NODE_URL"
2+
CHAINSTACK_ARCHIVE_NODE="CHAINSTACK_ARCHIVE_NODE_URL"

.gitignore

+120-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,120 @@
1-
node_modules/
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Microbundle cache
58+
.rpt2_cache/
59+
.rts2_cache_cjs/
60+
.rts2_cache_es/
61+
.rts2_cache_umd/
62+
63+
# Optional REPL history
64+
.node_repl_history
65+
66+
# Output of 'npm pack'
67+
*.tgz
68+
69+
# Yarn Integrity file
70+
.yarn-integrity
71+
72+
# dotenv environment variables file
73+
.env
74+
.env.test
75+
.env.production
76+
77+
# parcel-bundler cache (https://parceljs.org/)
78+
.cache
79+
.parcel-cache
80+
81+
# Next.js build output
82+
.next
83+
out
84+
85+
# Nuxt.js build / generate output
86+
.nuxt
87+
dist
88+
89+
# Gatsby files
90+
.cache/
91+
# Comment in the public line in if your project uses Gatsby and not Next.js
92+
# https://nextjs.org/blog/next-9-1#public-directory-support
93+
# public
94+
95+
# vuepress build output
96+
.vuepress/dist
97+
98+
# Serverless directories
99+
.serverless/
100+
101+
# FuseBox cache
102+
.fusebox/
103+
104+
# DynamoDB Local files
105+
.dynamodb/
106+
107+
# TernJS port file
108+
.tern-port
109+
110+
# Stores VSCode versions used for testing VSCode extensions
111+
.vscode-test
112+
113+
# yarn v2
114+
.yarn/cache
115+
.yarn/unplugged
116+
.yarn/build-state.yml
117+
.yarn/install-state.gz
118+
.pnp.*
119+
120+
# End of https://mrkandreev.name/snippets/gitignore-generator/#Node

README.md

+91-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,97 @@
1-
# Full vs Archive Node query
1+
<img width="1200" alt="Labs" src="https://user-images.githubusercontent.com/99700157/213291931-5a822628-5b8a-4768-980d-65f324985d32.png">
22

3-
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.
3+
> Chainstack is the leading suite of services connecting developers with Web3 infrastructure.
44
5-
For the full walkthrough, see [Querying full and archive Ethereum nodes with JavaScript](https://chainstack.com/querying-full-and-archive-evm-nodes-with-javascript/).
5+
<p align="center">
6+
<a target="_blank" href="https://chainstack.com/build-better-with-ethereum/"><img src="https://img.shields.io/badge/Ethereum-3C3C3D?style=for-the-badge&logo=Ethereum&logoColor=white" /></a>&nbsp;
7+
<a target="_blank" href="https://chainstack.com/build-better-with-bnb-smart-chain/"><img src="https://tinyurl.com/mp2wu3xx" /></a>&nbsp;
8+
</p>
69

7-
### Instructions
10+
<p align="center">
11+
• <a target="_blank" href="https://chainstack.com/">Homepage</a> •
12+
<a target="_blank" href="https://chainstack.com/protocols/">Supported protocols</a> •
13+
<a target="_blank" href="https://chainstack.com/blog/">Chainstack blog</a> •
14+
<a target="_blank" href="https://docs.chainstack.com/quickstart/">Chainstack docs</a> •
15+
<a target="_blank" href="https://docs.chainstack.com/quickstart/">Blockchain API reference</a> •
16+
<a target="_blank" href="https://console.chainstack.com/user/account/create">Start for free</a> •
17+
</p>
818

19+
# Querying full and archive EVM nodes with JavaScript
20+
21+
This project allows the retrieval of historical data from the blockchain programmatically, switching between a full and archive node provider when necessary.
22+
23+
See the full tutorial on the Chainstack blog:
24+
* [Querying full and archive Ethereum nodes with JavaScript](https://chainstack.com/querying-full-and-archive-evm-nodes-with-javascript/)
25+
26+
## Project details
27+
28+
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.
29+
30+
This tool queries the blockchain using the web3 and inquirer libraries for JavaScript.
31+
32+
## Quick start
33+
34+
### Clone this repository
35+
36+
```sh
37+
git clone https://github.com/yieniggu/chainstack-full-vs-archive-query-js.git
938
```
10-
git clone https://github.com/yieniggu/chainstack-full-vs-archive-query-js.git
11-
cd chainstack-full-vs-archive-query-js
12-
npm i
13-
node index
39+
40+
### Install dependencies
41+
42+
```sh
43+
npm ci
44+
```
45+
46+
> Use `npm ci` to launch a `clean install` of the dependencies, this will install the same version as in the `package.json` file.
47+
48+
### edit the .env.sample file
49+
50+
Add your RPC node URLs and rename the file to `.env`.
51+
52+
```env
53+
CHAINSTACK_FULL_NODE="CHAINSTACK_FULL_NODE_URL"
54+
CHAINSTACK_ARCHIVE_NODE="CHAINSTACK_ARCHIVE_NODE_URL"
55+
```
56+
57+
### Run the program
58+
59+
```sh
60+
npm run start
61+
```
62+
63+
## Prerequisites
64+
65+
* Node.js: ^16.17.0— [install Node](https://nodejs.org/en/download/)
66+
* A full and archive node RPC endpoints.
67+
68+
Deploy a full and archive node with Chainstack:
69+
70+
1. [Sign up with Chainstack](https://console.chainstack.com/user/account/create).
71+
1. [Deploy a node](https://docs.chainstack.com/platform/join-a-public-network).
72+
1. [View node access and credentials](https://docs.chainstack.com/platform/view-node-access-and-credentials).
73+
74+
## Dependencies
75+
76+
* dotenv: ^16.0.3
77+
* inquirer: ^8.2.4
78+
* web3.js: ^1.7.4
79+
80+
## Install
81+
82+
Clone this repository:
83+
84+
```sh
85+
git clone https://github.com/yieniggu/chainstack-full-vs-archive-query-js.git
86+
```
87+
88+
Install the dependencies in the project's directory:
89+
90+
```sh
91+
cd query-full-and-archive-nodes-javascript
92+
```
93+
94+
```sh
95+
npm ci
1496
```
97+
> Use `npm ci` to launch a `clean install` of the dependencies, this will install the same version as in the `package.json` file.

package-lock.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "query-full-archive",
33
"version": "1.0.0",
4-
"description": "",
4+
"description": "This tool allows the retrieval of historical data from the blockchain programmatically, switching between a full and archive node provider when necessary.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"start" : "node index"
88
},
99
"keywords": [],
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13+
"dotenv": "^16.0.3",
1314
"inquirer": "^8.2.4",
1415
"web3": "^1.7.4"
1516
}

src/utils.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
// Initial Config
22
const Web3 = require("web3");
3+
require('dotenv').config()
34

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

129
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
1310

0 commit comments

Comments
 (0)