-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script for interacting with a deployed contract
- Loading branch information
1 parent
c094007
commit 524fe76
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Script to interact with a deployed contract from hardhat console | ||
const dotenv = require("dotenv"); | ||
|
||
dotenv.config(); | ||
|
||
// Create a node provider | ||
const network = 'goerli'; | ||
const apiKey = process.env.ALCHEMY_GOERLI_API_KEY; | ||
const provider = new ethers.providers.AlchemyProvider(network, apiKey); | ||
|
||
|
||
// Create a wallet connected attached to the previous node provider | ||
const pk = process.env.GOERLI_PRIVATE_KEY; | ||
const signer = new ethers.Wallet(pk, provider); | ||
|
||
// Get deployed contract to interact with | ||
const contractName = 'Lock'; | ||
const contractAddress = '0xB58DCE7771876C71FE3b1ec4F9845C428971aA88'; | ||
const contract = await ethers.getContractAt(contractName, contractAddress, signer); | ||
|
||
// // Low-level way for doing the same | ||
// // Get contract factory | ||
// const contractFactory = await ethers.getContractFactory(contractName, signer); | ||
// // Attach contract with the deployed one | ||
// const contract = contractFactory.attach(contractAddress); | ||
|
||
|
||
// Interact | ||
await contract.unlockTime(); |