-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.ts
44 lines (39 loc) · 1.54 KB
/
deploy.ts
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
35
36
37
38
39
40
41
42
43
44
import { ContractFactory, ethers } from "ethers"
import * as fs from "fs-extra"
import "dotenv/config"
async function main() {
let provider = new ethers.JsonRpcProvider(process.env.RPC_URL)
console.log(process.env.RPC_URL)
console.log(process.env.PRIVATE_KEY)
let wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider)
const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8")
const binary = fs.readFileSync(
"./SimpleStorage_sol_SimpleStorage.bin",
"utf8",
)
const contractFactory = new ethers.ContractFactory(abi, binary, wallet)
console.log(`Deploying from: ${wallet.address}`)
const contractDeploy = await contractFactory.deploy()
const txReceipt = await contractDeploy.deploymentTransaction()!.wait()
const contractAddress = txReceipt!.contractAddress
console.log(`Contract deployed to ${contractAddress}`)
//interact with the contract
const contract = new ethers.Contract(contractAddress!, abi, wallet)
const updateValue = await contract.store(13)
await updateValue.wait()
console.log("Tx successful with hash " + updateValue.hash)
const data = await contract.retrieve()
console.log(`Data stored in contract: ${data}`)
await contract.addPerson("Fabio", 26)
console.log(
"Person added has number: " +
(await contract.nameToFavoriteNumber("Fabio")),
)
console.log(await contract.people(0))
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error)
process.exit(1)
})