All Projects → adrianmcli → Web3 Vs Ethers

adrianmcli / Web3 Vs Ethers

A basic cheatsheet of Web3.js vs Ethers (along w/ example apps!)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Web3 Vs Ethers

Eth Crypto
Cryptographic javascript-functions for ethereum and tutorials to use them with web3js and solidity
Stars: ✭ 420 (+307.77%)
Mutual labels:  ethereum, dapp, web3, truffle, web3js
Starter Kit
An OpenZeppelin starter kit containing React, OpenZeppelin SDK & OpenZeppelin Contracts.
Stars: ✭ 101 (-1.94%)
Mutual labels:  ethereum, dapp, web3, truffle, web3js
React Ethereum Dapp Example
A starter boilerplate for an Ethereum dapp using web3.js v1.0, truffle, react, and parity
Stars: ✭ 384 (+272.82%)
Mutual labels:  ethereum, web3, truffle, web3js
Eth.social
An Ethereum dApp for posting social events.
Stars: ✭ 17 (-83.5%)
Mutual labels:  ethereum, dapp, web3, truffle
Eth Vue
Featured in Awesome Vue [https://github.com/vuejs/awesome-vue], a curated list maintained by vuejs of awesome things related to the Vue.js framework, and Awesome List [https://awesomelists.net/150-Vue.js/3863-Open+Source/18749-DOkwufulueze-eth-vue], this Truffle Box provides everything you need to quickly build Ethereum dApps that have authentication features with vue, including configuration for easy deployment to the Ropsten Network. It's also Gravatar-enabled. Connecting to a running Ganache blockchain network from Truffle is also possible -- for fast development and testing purposes. Built on Truffle 5 and Vue 3, eth-vue uses vuex for state management, vuex-persist for local storage of app state, and vue-router for routing. Authentication functionalities are handled by Smart Contracts running on the Ethereum blockchain.
Stars: ✭ 171 (+66.02%)
Mutual labels:  ethereum, dapp, web3, truffle
Trace
Supply chain transparency platform proof-of-concept based on the Ethereum blockchain ✍️
Stars: ✭ 52 (-49.51%)
Mutual labels:  ethereum, dapp, web3, truffle
Erc20 Generator
Create an ERC20 Token for FREE in less than a minute with the most used Smart Contract Generator for ERC20 Token. No login. No setup. No coding required.
Stars: ✭ 202 (+96.12%)
Mutual labels:  ethereum, dapp, truffle, web3js
Web3swift
Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.
Stars: ✭ 237 (+130.1%)
Mutual labels:  ethereum, dapp, web3, web3js
Typechain
🔌 TypeScript bindings for Ethereum smart contracts
Stars: ✭ 769 (+646.6%)
Mutual labels:  ethereum, web3, truffle
Web3 React
🧰 A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps
Stars: ✭ 788 (+665.05%)
Mutual labels:  ethereum, dapp, web3
Marketprotocol
Ethereum based derivatives trading protocol creating digital tokens for any asset
Stars: ✭ 78 (-24.27%)
Mutual labels:  ethereum, web3, truffle
Eattheblocks
Source code for Eat The Blocks, a screencast for Ethereum Dapp Developers
Stars: ✭ 431 (+318.45%)
Mutual labels:  ethereum, web3, truffle
Web Sdk
Portis Web SDK
Stars: ✭ 65 (-36.89%)
Mutual labels:  ethereum, dapp, web3
Truffle eth class2
Stars: ✭ 330 (+220.39%)
Mutual labels:  ethereum, dapp, truffle
Angular Truffle Dapp
Angular + Truffle = Beautiful Material Dapp that can be scaled
Stars: ✭ 12 (-88.35%)
Mutual labels:  dapp, web3, truffle
Trust Wallet Ios
📱 Trust - Ethereum Wallet and Web3 DApp Browser for iOS
Stars: ✭ 1,228 (+1092.23%)
Mutual labels:  ethereum, dapp, web3
Dapp
TypeScript React Redux Ethereum IPFS Starter Kit
Stars: ✭ 33 (-67.96%)
Mutual labels:  ethereum, dapp, truffle
Web3e
Web3E Ethereum for Embedded devices running Arduino framework
Stars: ✭ 50 (-51.46%)
Mutual labels:  ethereum, dapp, web3
Ethereumbook
Mastering Ethereum, by Andreas M. Antonopoulos, Gavin Wood
Stars: ✭ 11,663 (+11223.3%)
Mutual labels:  ethereum, dapp, web3js
Solidity Idiosyncrasies
Solidity gotchas, pitfalls, limitations, and idiosyncrasies.
Stars: ✭ 267 (+159.22%)
Mutual labels:  ethereum, web3, truffle

Web3.js vs Ethers.js

A guide to the basic differences between Web3.js and Ethers.js, the two most popular libraries for interacting with the Ethereum blockchain. And two example frontend apps using React + Hooks!


Sample Dapp Contract

Inside the smart-contracts folder, you will find a simple Truffle project with the following Solidity contract:

pragma solidity ^0.5.0;

contract Counter {
  uint count = 0;

  function increment() public {
    count = count + 1;
  }

  function getCount() public view returns (uint) {
    return count;
  }
}

Setup Truffle project

Before you run any of the frontend UIs, make sure to start the development console with truffle develop, and then run the migrate command to compile and deploy the contract onto the development chain.

Two Frontend UIs

There are two folders (app-ethers and app-web3js) each containing a simple React frontend for the above contract. The only substantial difference between these two UIs is located in the useCounterContract.js files.

Here are the direct links for your convenience:

Running the apps

In each of these apps, you can serve the frontends with the following commands:

npm install
npm start

This will serve the frontend on http://localhost:1234 which you can view in your browser.

Differences

There are three major portions in this code: the setup, reading (calling a constant method), and writing (calling a non-constant mutating method).

Setup

With Web3.js, we need the following to instantiate a connected contract instance that can make read/write calls:

  • contract ABI
  • deployed contract address
  • a from address (for send transactions)

Note that the networkId is required for us to fetch the deployed address from our contract artifact.

// Web3.js
const web3 = new Web3("http://127.0.0.1:8545");
const accounts = await web3.eth.getAccounts();
const networkId = await web3.eth.net.getId();
const contractAddress = artifact.networks[networkId].address;

contractInstance = new web3.eth.Contract(artifact.abi, contractAddress, {
  from: accounts[0],
});

With Ethers.js, we need the following for our contract instance:

  • deployed contract address
  • contract ABI
  • a Signer object (similar to Provider, but with a specified Signer)
// Ethers.js
const provider = new ethers.providers.JsonRpcProvider();
const network = await provider.getNetwork();
const contractAddress = artifact.networks[network.chainId].address;

contractInstance = new ethers.Contract(
  contractAddress,
  artifact.abi,
  provider.getSigner(),
);

Calling a constant method

// Web3.js
const count = await contractInstance.methods.getCount().call();
console.log(count); // returns a String
// Ethers.js
const count = await contractInstance.getCount();
console.log(count); // returns a BigNumber instance

These two are very similar, but in our example Ethers.js returns a BigNumber instance by default whereas Web3.js will return the number as a String.

Calling a non-constant method

// Web3.js
await contract.current.methods.increment().send();
// tx has been mined
// Ethers.js
const tx = await contract.current.increment();
await tx.wait(); // wait for mining

Note that Web3.js will return a PromiEvent which allows you to subscribe to confirmations, errors, and the transaction hash.

Ethers.js will return a transaction object where a bunch of information relating to the transaction is kept. You can grab the hash via tx.hash, but you must await on tx.wait() if you want to make sure it has been mined.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].