Deploy Contract Contracts Using Ethers Js Ethers

[Solved] Deploy Contract Contracts Using Ethers Js Ethers | Solidity - Code Explorer | yomemimo.com
Question : Contract in ethers.js

Answered by : shirshak

Provider:
A Provider (in ethers) is a class which provides an abstraction for a connection to the Ethereum Network.
It provides read-only access to the Blockchain and its status.
import { ethers } from "ethers";
const provider = new ethers.providers.Web3Provider(window.ethereum)
Signer:
A Signer is a class which (usually) in some way directly or indirectly has access to a private key,
which can sign messages and transactions to authorize the network to charge your account ether to perform operations.
const signer = provider.getSigner()
Contract:
A Contract is an abstraction which represents a connection to a specific contract on the Ethereum Network,
so that applications can use it like a normal JavaScript object.

Source : https://docs.ethers.io/v5/getting-started/#getting-started--glossary | Last Update : Sun, 15 May 22

Question : deploy contract contracts using ethers.js ethers

Answered by : defiant-deer-84m5vgcf4jdu

const ethers = require("ethers")
// const solc = require("solc")
const fs = require("fs-extra")
require("dotenv").config()
async function main() { // First, compile this! // And make sure to have your ganache network up! let provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL) let wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider) // const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf8"); // let wallet = new ethers.Wallet.fromEncryptedJsonSync( // encryptedJson, // process.env.PRIVATE_KEY_PASSWORD // ); // wallet = wallet.connect(provider); const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8") const binary = fs.readFileSync( "./SimpleStorage_sol_SimpleStorage.bin", "utf8" ) const contractFactory = new ethers.ContractFactory(abi, binary, wallet) console.log("Deploying, please wait...") const contract = await contractFactory.deploy() // const contract = await contractFactory.deploy({ gasPrice: 100000000000 }) const deploymentReceipt = await contract.deployTransaction.wait(1) console.log(`Contract deployed to ${contract.address}`) let currentFavoriteNumber = await contract.retrieve() console.log(`Current Favorite Number: ${currentFavoriteNumber}`) console.log("Updating favorite number...") let transactionResponse = await contract.store(7) let transactionReceipt = await transactionResponse.wait() currentFavoriteNumber = await contract.retrieve() console.log(`New Favorite Number: ${currentFavoriteNumber}`)
}
main() .then(() => process.exit(0)) .catch((error) => { console.error(error) process.exit(1) })

Source : | Last Update : Sun, 11 Sep 22

Answers related to deploy contract contracts using ethers js ethers

Code Explorer Popular Question For Solidity