-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
36 lines (27 loc) · 1.01 KB
/
deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { address, abiFactory } from "./config";
import web3modal from "web3modal";
import { ethers } from "ethers";
async function getContract() {
const modal = new web3modal();
const connection = await modal.connect();
const provider = new ethers.providers.Web3Provider(connection);
const signer = provider.getSigner();
const contract = new ethers.Contract(address, abiFactory, signer);
return contract;
}
export async function hasDeployed(username) {
const contract = await getContract();
const data = await contract.hasDeployed(username);
return data;
}
export async function getAddress(username) {
const contract = await getContract();
const hasDeployedValue = await hasDeployed(username);
if (hasDeployedValue) {
const address = await contract.userToContract(username);
return address;
}
console.log("contract is not deployed, deploying....")
const deployContractAddress = await contract.deploy(username);
return deployContractAddress;
}