Created
August 5, 2026 21:49
-
-
Save Dustin4444/68f0f7e93468a0c8997d102295c86ae8 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.34+commit.80d5c536.js&optimize=undefined&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This script can be used to deploy the "Storage" contract using ethers.js library. | |
| // Please make sure to compile "./contracts/1_Storage.sol" file before running this script. | |
| // And use Right click -> "Run" from context menu of the file to run the script. Shortcut: Ctrl+Shift+S | |
| import { deploy } from './ethers-lib' | |
| (async () => { | |
| try { | |
| const result = await deploy('Storage', []) | |
| console.log(`address: ${result.address}`) | |
| } catch (e) { | |
| console.log(e.message) | |
| } | |
| })() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ethers } from 'ethers' | |
| /** | |
| * Deploy the given contract | |
| * @param {string} contractName name of the contract to deploy | |
| * @param {Array<any>} args list of constructor' parameters | |
| * @param {Number} accountIndex account index from the exposed account | |
| * @return {Contract} deployed contract | |
| */ | |
| export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => { | |
| console.log(`deploying ${contractName}`) | |
| // Note that the script needs the ABI which is generated from the compilation artifact. | |
| // Make sure contract is compiled and artifacts are generated | |
| const artifactsPath = `browser/artifacts/${contractName}.json` // Change this for different path | |
| const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) | |
| // 'web3Provider' is a remix global variable object | |
| const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) | |
| const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) | |
| const contract = await factory.deploy(...args) | |
| // The contract is NOT deployed yet; we must wait until it is mined | |
| await contract.deployed() | |
| return contract | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment