Skip to content

zuyux/ethers_calls

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ethers RPC Samples

Learn how to interact with Ethereum using Ethers.js through these simplified and modular examples.

Technology Stack & Tools

  • ES Modules: Modern JavaScript syntax for improved readability and maintainability.
  • Ethers.js: A powerful library for blockchain interaction.
  • Node.js: For running scripts and managing dependencies.
  • Infura: A node provider for Ethereum blockchain access.

Setting Up

1. Clone or Download the Repository:

$ git clone https://github.com/zuyux/ethers_calls
$ cd ethers_calls

2. Install Dependencies:

$ npm install

3. Environment Variables:

Create a .env file in the root directory and include the following details:

INFURA_ID=your_infura_project_id
ACCOUNT1=your_account1_address
ACCOUNT2=your_account2_address
PRIVATE_KEY1=your_account1_private_key
ERC20_CONTRACT=your_erc20_contract_address

ETH RPC Scripts

1. getAccount.js: Read ETH balance of a wallet address.

  • Ensures readability by formatting Ether balance in human-readable units.
  • Uses ES Modules to load dependencies.
$ node calls/getAccount.js

2. getBlocks.js: Fetches transactions from a specific block.

  • Extracts detailed transaction data for inspection and logging.
$ node calls/getBlocks.js

3. getContract.js: Fetches the balance of a wallet address from a smart contract (e.g., DAI contract).

  • Demonstrates how to interact with ERC20 contracts using Ethers.js.
$ node calls/getContract.js

4. getStream.js: Queries blocks for Transfer events.

  • Streams real-time blockchain data using Ethers.js’s event querying API.
$ node calls/getStream.js

5. postContract.js: Transfers the entire balance of an ERC20 token from one account to another.

  • Shows how to connect a wallet to an ERC20 contract and send tokens securely.
$ node calls/postContract.js

6. postTX.js: Transfers 0.025 ETH from one account to another.

  • Includes detailed logging of sender and receiver balances before and after the transaction.
  • Uses .env for securely managing private keys.
$ node calls/postTX.js

About

ethers rpc samples

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%