Ethers.js
Ethers.js is a compact library for interacting with Ethereum Virtual Machine (EVM) based blockchains. With Velocitybeing an EVM chain, you can use Ethers.js to interact with the Velocity ecosystem.
Adding Ethers.js to your Projectβ
npm install --save ethersTo import the ethers library into your project using Node.js, use the following:
const { ethers } = require("ethers");import { ethers } from "ethers";Connecting to Velocity with MetaMaskβ
After installing, you need to create a web3 instance and set a provider. Most Ethereum supported wallets, such as MetaMask, have an EIP-1193 compliant provider at window.ethereum. This works for connecting to Velocity as well.
// A Web3Provider wraps a standard Web3 provider, which is
// what MetaMask injects as window.ethereum into each page
const provider = new ethers.providers.Web3Provider(window.ethereum)
// MetaMask requires requesting permission to connect users accounts
await provider.send("eth_requestAccounts", []);
// The MetaMask plugin also allows signing transactions to
// send ether and pay to change state within the blockchain.
// For this, you need the account signer...
const signer = provider.getSigner()View the official Ethers.js MetaMask docs here.
Connecting to Velocity via RPCβ
View the official Ethers.js RPC docs here.
Interacting with a Contractβ
To connect to and interact with a deployed contract, you can do the following:
View the official Ethers.js contract docs here.
Last updated