Skip to content

Commit 63082ef

Browse files
committed
Added deploy and interact scripts
1 parent fbe1d3c commit 63082ef

File tree

5 files changed

+72
-21
lines changed

5 files changed

+72
-21
lines changed

.env.schema

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
HARDHAT_KLAYTN_BAOBAB_TESTNET_URL=
2+
HARDHAT_KLAYTN_ACCOUNT_ADDRESS=
23
HARDHAT_KLAYTN_ACCOUNT_PRIVATE_KEY=
34

4-
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=
5+
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=
6+
NEXT_PUBLIC_NETWORK_TYPE=

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"web:build": "next build",
77
"web:start": "next start",
88
"web:lint": "next lint",
9-
"contracts:compile": "hardhat compile"
9+
"contracts:compile": "hardhat compile",
10+
"contracts:deploy": "hardhat run scripts/deploy.js --network baobab",
11+
"contracts:read": "hardhat run scripts/read.js --network baobab"
1012
},
1113
"dependencies": {
1214
"@ant-design/cssinjs": "^1.18.0-alpha.0",

scripts/deploy.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
// We require the Hardhat Runtime Environment explicitly here. This is optional
2-
// but useful for running the script in a standalone fashion through `node <script>`.
3-
//
4-
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
5-
// will compile your contracts, add the Hardhat Runtime Environment's members to the
6-
// global scope, and execute the script.
7-
const hre = require('hardhat');
1+
const { ethers } = require('hardhat');
2+
3+
// Load env variables
4+
require('dotenv').config();
85

96
async function main() {
10-
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
11-
const unlockTime = currentTimestampInSeconds + 60;
7+
const deployerAddress = process.env.HARDHAT_KLAYTN_ACCOUNT_ADDRESS;
8+
const deployer = await ethers.getSigner(deployerAddress);
129

13-
const lockedAmount = hre.ethers.parseEther('0.001');
10+
console.log(`Deploying contracts with the account: ${deployer.address}`);
11+
console.log(`Account balance: ${(await deployer.provider.getBalance(deployerAddress)).toString()}`);
1412

15-
const lock = await hre.ethers.deployContract('Lock', [unlockTime], {
16-
value: lockedAmount,
17-
});
13+
const contract = await ethers.deployContract('HouseformManager');
14+
await contract.waitForDeployment();
1815

19-
await lock.waitForDeployment();
16+
const contractAddress = await contract.getAddress();
2017

21-
console.log(
22-
`Lock with ${ethers.formatEther(lockedAmount)}ETH and unlock timestamp ${unlockTime} deployed to ${lock.target}`,
23-
);
18+
console.log(`HouseformManager contract deployed`);
19+
console.log(`Contract address is ${contractAddress}`);
20+
console.log(`Check it on https://baobab.scope.klaytn.com/account/${contractAddress}`);
2421
}
2522

26-
// We recommend this pattern to be able to use async/await everywhere
27-
// and properly handle errors.
2823
main().catch((error) => {
2924
console.error(error);
3025
process.exitCode = 1;

scripts/read.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { ethers } = require('hardhat');
2+
3+
// Load env variables
4+
require('dotenv').config();
5+
6+
const managerContractAddress = '0x3a5CC2Be65e56d896f0D3adf427474c33239a1F9';
7+
const shareContractAddress = '0x873340073b531a2F76b8c0e7567A434f762Eae31';
8+
9+
async function main() {
10+
const managerContract = (await ethers.getContractFactory('HouseformManager')).attach(managerContractAddress);
11+
const shareContract = (await ethers.getContractFactory('HouseformShare')).attach(shareContractAddress);
12+
13+
console.log(`Share contract address: ${await managerContract.shareContract()}`);
14+
console.log(`Share contract name: ${await shareContract.name()}`);
15+
console.log(`Share contract symbol: ${await shareContract.symbol()}`);
16+
}
17+
18+
main().catch((error) => {
19+
console.error(error);
20+
process.exitCode = 1;
21+
});

src/constants/klaytn.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export type NetworkType = 'testnet' | 'mainnet';
2+
3+
export const NETWORK_DATA_MAP = {
4+
mainnet: {
5+
contracts: {
6+
HouseformManager: {
7+
address: '',
8+
},
9+
HouseformShare: {
10+
address: '',
11+
},
12+
},
13+
},
14+
testnet: {
15+
contracts: {
16+
HouseformManager: {
17+
address: '0x3a5CC2Be65e56d896f0D3adf427474c33239a1F9',
18+
},
19+
HouseformShare: {
20+
address: '0x873340073b531a2f76b8c0e7567a434f762eae31',
21+
},
22+
},
23+
},
24+
};
25+
26+
export class KlaytnConstants {
27+
// This defines the network to be used through the app (mainnet or testnet) loaded through env
28+
public static NETWORK_TYPE = (process.env.NEXT_PUBLIC_NETWORK_TYPE || 'testnet') as NetworkType;
29+
// This is always used to access network data
30+
public static NETWORK_DATA = NETWORK_DATA_MAP[KlaytnConstants.NETWORK_TYPE];
31+
}

0 commit comments

Comments
 (0)