Skip to content

Commit

Permalink
Update contract to deploy test net and verify
Browse files Browse the repository at this point in the history
  • Loading branch information
naruhitokaide committed Apr 30, 2024
1 parent cefc789 commit 41c47a4
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 16 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# testnet
PRIVATE_KEY =

# livenet
# PRIVATE_KEY =

INFURA = "6e9457c7d3754cc2a205c109a69e516f"
ETHEREUM_API_KEY = "S1VH5HN4RW22314GI9APVKVFIJ36IH5SXV"
SEPOLIA_API_KEY = "U2nZW5r0_xgomMtKnbOAruRlIQv3GhYT"
OPTIMISM_API_KEY = "P5K84TXHSZAXCDHM58VKHAB9HEGK3WZICH"
ARBITRUM_API_KEY = "NN4Z8UJ8UXANGVZV22YX1SWMYZZPY7GKG4"
BSC_API_KEY = "W29G6AQ1BNQFTNS86GFJH5ZN12WA5RTM4T"
FANTOM_API_KEY = "4MR937N251D431QWQE9R55W8YJMXPW17CV"
10 changes: 10 additions & 0 deletions contracts/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Token is ERC20 {
constructor(uint256 initialSupply) ERC20("test token", "test") {
_mint(msg.sender, initialSupply * 1e18);
}
}
35 changes: 33 additions & 2 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
}
});

const INFURA = process.env.INFURA || "";
const ETHEREUM_API_KEY = process.env.ETHEREUM_API_KEY || "api-key";
const OPTIMISM_API_KEY = process.env.OPTIMISM_API_KEY || "api-key";
const BSC_API_KEY = process.env.BSC_API_KEY || "api-key";
const FANTOM_API_KEY = process.env.FANTOM_API_KEY || "api-key";
const POLYGONSCAN_API_KEY = process.env.POLYGONSCAN_API_KEY || "api-key";
const ARBITRUM_API_KEY = process.env.ARBITRUM_API_KEY || "api-key";

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

Expand All @@ -30,6 +38,10 @@ module.exports = {
url: "https://rpc.testnet.fantom.network",
accounts: [process.env.PRIVATEKEY],
},
bscTestnet: {
url: `https://data-seed-prebsc-1-s1.bnbchain.org:8545`,
accounts: [process.env.PRIVATEKEY],
},
ethereum: {
url: "https://main-light.eth.linkpool.io/",
accounts: [process.env.PRIVATEKEY],
Expand Down Expand Up @@ -58,7 +70,26 @@ module.exports = {
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: "WQKQ9RXXCTK715PKG1H7JUMV4ZEUW3KKXN",
apiKey: {
// Ethereum
mainnet: ETHEREUM_API_KEY,
sepolia: ETHEREUM_API_KEY,
// Optimism
optimisticEthereum: OPTIMISM_API_KEY,
optimismSepolia: OPTIMISM_API_KEY,
// polygon
polygon: POLYGONSCAN_API_KEY,
polygonMumbai: POLYGONSCAN_API_KEY,
// Arbitrum
arbitrumOne: ARBITRUM_API_KEY,
arbitrumSepolia: ARBITRUM_API_KEY,
// Bsc
bsc: BSC_API_KEY,
bscTestnet: BSC_API_KEY,
// Fantom
ftmTestnet: FANTOM_API_KEY,
//
},
},
solidity: {
version: "0.8.25",
Expand All @@ -70,6 +101,6 @@ module.exports = {
},
},
mocha: {
timeout: 200000,
timeout: 20000000000,
},
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"scripts": {
"test": "npx hardhat test",
"deploy": "npx hardhat run --network fantomtestnet scripts/deploy.js",
"deploy": "npx hardhat run --network bscTestnet scripts/deploy.js",
"verify": "npx hardhat run --network bscTestnet scripts/verify.js",
"deploy_fantom": "npx hardhat run --network fantom scripts/deploy.js",
"deploy_icicb": "npx hardhat run --network ICICB scripts/deploy.js",
"deploy_icicbtest": "npx hardhat run --network ICICBtestnet scripts/deploy.js",
Expand Down
38 changes: 25 additions & 13 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const fs = require("fs");
const { ethers } = require("hardhat");
const { setTargetAddress } = require("./helpers");
// const metadata_hashs = require("../resources/metadata_hash.json");

const saveFiles = async (fileName, data) => {
Expand Down Expand Up @@ -32,22 +34,30 @@ const saveAbis = async () => {
};

async function main() {
saveAbis();
await saveAbis();

const network = hre.network.name;

// ERC20
const ERC20Token_ = await ethers.getContractFactory("Token");
const ERC20Token = await ERC20Token_.deploy(1e9);
await ERC20Token.deployed();
setTargetAddress("Token", network, ERC20Token.address);

//NFT
const NFT_1 = await hre.ethers.getContractFactory("NFT");
const NFT_1 = await ethers.getContractFactory("NFT");
const NFT1 = await NFT_1.deploy("test1 NFT", "t1NFT");
await NFT1.deployed();
setTargetAddress("NFT1", network, NFT1.address);

// for (var i = 0; i < 5; i++) {
// await NFT1.create(metadata_hashs[i]);
// }

const NFT_2 = await hre.ethers.getContractFactory("NFT");
const NFT_2 = await ethers.getContractFactory("NFT");
const NFT2 = await NFT_2.deploy("test2 NFT", "t2NFT");
await NFT2.deployed();
setTargetAddress("NFT2", network, NFT2.address);

// for (var i = 2; i < 4; i++) {
// await NFT2.create(metadata_hashs[i]);
Expand All @@ -56,6 +66,7 @@ async function main() {
const NFT_3 = await hre.ethers.getContractFactory("NFT");
const NFT3 = await NFT_3.deploy("test3 NFT", "t3NFT");
await NFT3.deployed();
setTargetAddress("NFT3", network, NFT3.address);

// for (var i = 1; i < 5; i++) {
// await NFT3.create(metadata_hashs[i]);
Expand All @@ -65,17 +76,18 @@ async function main() {
const Marketplace_ = await hre.ethers.getContractFactory("Marketplace");
const Marketplace = await Marketplace_.deploy(ERC20Token.address);
await Marketplace.deployed();
setTargetAddress("Marketplace", network, Marketplace.address);

const addresses = {
ERC20: ERC20Token.address,
NFT: {
NFT1: NFT1.address,
NFT2: NFT2.address,
NFT3: NFT3.address,
},
Marketplace: Marketplace.address,
};
await saveFiles("addresses.json", JSON.stringify(addresses, undefined, 4));
// const addresses = {
// Token: ERC20Token.address,
// NFT: {
// NFT1: NFT1.address,
// NFT2: NFT2.address,
// NFT3: NFT3.address,
// },
// Marketplace: Marketplace.address,
// };
// await saveFiles("addresses.json", JSON.stringify(addresses, undefined, 4));
}

main()
Expand Down
28 changes: 28 additions & 0 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require("fs");
const addresses = require("../build/addresses.json");

const getTargetAddress = (contractName, network) => {
return addresses[network][contractName];
};

const setTargetAddress = (contractName, network, address) => {
if (addresses[network] == undefined) {
addresses[network] = {};
}
addresses[network][contractName] = address;
fs.writeFileSync(
"build/addresses.json",
JSON.stringify(addresses),
function (err) {
if (err) return console.log(err);
}
);
console.log(
`${contractName} | ${network} | ${addresses[network][contractName]}`
);
};

module.exports = {
getTargetAddress,
setTargetAddress,
};
72 changes: 72 additions & 0 deletions scripts/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const addresses = require("../build/addresses.json");
const { getTargetAddress } = require("./helpers");

async function main() {
const network = hre.network.name;
getTargetAddress("Token", network);
const Token = getTargetAddress("Token", network);
const NFT1 = getTargetAddress("NFT1", network);
const NFT2 = getTargetAddress("NFT2", network);
const NFT3 = getTargetAddress("NFT3", network);
const Marketplace = getTargetAddress("Marketplace", network);
console.log({ Token }, { NFT1 }, { NFT2 }, { NFT3 }, { Marketplace });

try {
await run("verify:verify", {
address: Token,
constructorArguments: [1e9],
});
console.log("Verified Token");
} catch (e) {
console.log(e);
}

try {
await run("verify:verify", {
address: NFT1,
constructorArguments: ["test1 NFT", "t1NFT"],
});
console.log("Verified NFT1");
} catch (e) {
console.log(e);
}

try {
await run("verify:verify", {
address: NFT2,
constructorArguments: ["test2 NFT", "t2NFT"],
});
console.log("Verified NFT2");
} catch (e) {
console.log(e);
}

try {
await run("verify:verify", {
address: NFT3,
constructorArguments: ["test3 NFT", "t3NFT"],
});
console.log("Verified NFT3");
} catch (e) {
console.log(e);
}

try {
await run("verify:verify", {
address: Marketplace,
constructorArguments: [Token],
});
console.log("Verified Marketplace");
} catch (e) {
console.log(e);
}
}

main()
.then(() => {
process.exit(0);
})
.catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit 41c47a4

Please sign in to comment.