Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethers v6 #62

Closed
Tracked by #13
manuelbarbas opened this issue Dec 26, 2023 · 2 comments
Closed
Tracked by #13

Ethers v6 #62

manuelbarbas opened this issue Dec 26, 2023 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@manuelbarbas
Copy link
Collaborator

manuelbarbas commented Dec 26, 2023

Ethers V6

The ethers.js library is a comprehensive and concise library for engaging with the Ethereum Blockchain and its surrounding ecosystem.

Some of the main features are:

  • Import and export JSON wallets (Geth, Parity and crowdsale)
  • Import and export BIP 39 mnemonic phrases (12 word backup phrases) and HD Wallets
  • Meta-classes create JavaScript objects from any contract ABI, including ABIv2 and Human-Readable ABI
    Connect to Ethereum nodes over JSON-RPC, INFURA, Etherscan, Alchemy or Metamask

The biggest difference between v5 and v6 is in the use of modern ES6 features. The major changes can been seen on:

For more information check the Ethers v6 documentation.

Implementation Example

Package Install:

npm install ethers

Using Wallets

Tab -> Wallet.createRandom();
Tab -> new Wallet(PRIVATE_KEY);

Using Provider

Tab -> JsonRpcProvider
Tab -> Web3Provider (Injected Wallets i.e Metamask)

Full Example of Sending a Transaction

import { ethers } from 'ethers';
import {contract_abi,contract_adress} from "./contract";
import dotenv from 'dotenv'; 
dotenv.config();

const skale_provider = "https://staging-v3.skalenodes.com/v1/staging-fast-active-bellatrix";
const provider = new ethers.JsonRpcProvider(skale_provider);
const pk = process.env.PRIVATE_KEY || "";
const signer = new ethers.Wallet(pk, provider);

const contract = new ethers.Contract(contract_adress, contract_abi, signer);

async function ContractSendTx() {
    const data = await contract._mintTest.populateTransaction(signer.address);
    data.gasLimit = ethers.toBigInt(500000);
    data.gasPrice = ethers.toBigInt(100000);
    data.nonce = await provider.getTransactionCount(signer.address);

    const tx = await signer.sendTransaction(data)

    console.log(tx.hash);

}
ContractSendTx();
@manuelbarbas
Copy link
Collaborator Author

What is: Library
Language: Javascript, Typescript
Target: Web

@TheGreatAxios
Copy link
Collaborator

TheGreatAxios commented Jan 4, 2024

# Use NPM
npm add ethers

# Use Yarn
yarn add ethers

# Use PNPM
pnpm install ethers

@manuelbarbas manuelbarbas added the documentation Improvements or additions to documentation label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants