From ca177a0ffe2e3bd3d845cdbd7508bc303e3b5eb1 Mon Sep 17 00:00:00 2001 From: zoruka Date: Thu, 8 Dec 2022 16:28:03 -0300 Subject: [PATCH] refactor: util script to get contract using hardhat defined network --- scripts/mint.js | 7 ++----- scripts/tokenURI.js | 9 +++------ scripts/upgrade.js | 9 +++------ scripts/util.js | 7 +++++++ 4 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 scripts/util.js diff --git a/scripts/mint.js b/scripts/mint.js index f1eb3de..7c302cc 100644 --- a/scripts/mint.js +++ b/scripts/mint.js @@ -1,7 +1,7 @@ // npx hardhat run scripts/mint.js --network mumbai +const { getContract } = require('./util'); // TODO: make this arguments -const contractAddress = '0x91A425C1CA320A99a09BE1bee114Fce5d30153d9'; const params = [ '0x7ED735b7095C05d78dF169F991f2b7f1A1F1A049', // to 'Fleek App', // name @@ -15,10 +15,7 @@ const params = [ ]; (async () => { - const contract = await hre.ethers.getContractAt( - 'FleekERC721', - contractAddress - ); + const contract = getContract('FleekERC721'); const transaction = await contract.mint(...params); diff --git a/scripts/tokenURI.js b/scripts/tokenURI.js index 05e112d..98a89c9 100644 --- a/scripts/tokenURI.js +++ b/scripts/tokenURI.js @@ -1,14 +1,11 @@ // npx hardhat run scripts/tokenURI.js --network mumbai +const { getContract } = require('./util'); // TODO: make this arguments -const contractAddress = '0x91A425C1CA320A99a09BE1bee114Fce5d30153d9'; -const tokenId = 3; +const tokenId = 1; (async () => { - const contract = await hre.ethers.getContractAt( - 'FleekERC721', - contractAddress - ); + const contract = await getContract('FleekERC721'); const transaction = await contract.tokenURI(tokenId); diff --git a/scripts/upgrade.js b/scripts/upgrade.js index 96db896..2ab2f1e 100644 --- a/scripts/upgrade.js +++ b/scripts/upgrade.js @@ -1,19 +1,16 @@ // npx hardhat run scripts/upgrade.js --network mumbai +const { getContract } = require('./util'); // TODO: make this arguments -const contractAddress = '0x91A425C1CA320A99a09BE1bee114Fce5d30153d9'; const params = [ - 3, // tokenId + 1, // tokenId '97e7908f70f0862d753c66689ff09e70caa43df2', // commit hash 'https://github.com/org/new-repo', // repo 'new-author', // author ]; (async () => { - const contract = await hre.ethers.getContractAt( - 'FleekERC721', - contractAddress - ); + const contract = await getContract('FleekERC721'); const transaction = await contract.setTokenBuild(...params); diff --git a/scripts/util.js b/scripts/util.js new file mode 100644 index 0000000..2f13dda --- /dev/null +++ b/scripts/util.js @@ -0,0 +1,7 @@ +module.exports.getContract = async function (contractName) { + const { + address, + } = require(`../deployments/${hre.network.name}/${contractName}.json`); + + return hre.ethers.getContractAt(contractName, address); +};