Skip to content

Commit

Permalink
Add script for interacting with a deployed contract
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiascaricato committed Jan 29, 2023
1 parent c094007 commit 524fe76
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions scripts/interact-with-deployed-contract.ts
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();

0 comments on commit 524fe76

Please sign in to comment.