-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.ts
77 lines (68 loc) · 7.67 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// const ethers = require("ethers")
// const fs = require("fs-extra")
// require("dotenv").config()
import { ethers } from "ethers"
import * as fs from "fs-extra"
import "dotenv/config"
async function main() {
// connect to Ganache network using ethers.js
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL!)
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider)
const abi = fs.readFileSync("./SimpleStoreage_sol_SimpleStorage.abi", "utf8")
// const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf8");
// let wallet = new ethers.Wallet.fromEncryptedJsonSync(
// encryptedJson,
// process.env.PRIVATE_KEY_PASSWORD
// );
// wallet = await wallet.connect(provider);
const binary = fs.readFileSync(
"./SimpleStoreage_sol_SimpleStorage.bin",
"utf8"
)
// const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
// console.log("Deploying....Please wait...");
// const contract = await contractFactory.deploy(); // STOP here! Wait for the contract to be deployed
// // const contract = await contractFactory.deploy({gasPrice : 1000000000, gasLimit: 10000000000});
// can pass args to deploye as gasPrice, gasLimit
// Transaction Receipts - wait for block conformation (1)
// const transactionReceipt = await contract.deployTransaction.wait(1);
// console.log("Here is the deployment transaction (transaction response)");
// console.log(contract.deployTransaction);
// console.log("Here is the transaction receipt");
// // when you wait for block conformation then you get the transactionReceipt
// console.log(transactionReceipt);
// console.log("Let's deploy with only transaction data!");
// const nonce = await wallet.getTransactionCount(); // To get nonce from wallet
// const tx = {
// nonce: nonce,
// gasPrice: 20000000000,
// gasLimit: 1000000,
// to: null,
// value: 0,
// data: "0x608060405234801561001057600080fd5b5061093b806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80632e64cec11461005c5780636057361d1461007a5780636f760f41146100965780638bab8dd5146100b25780639e7a13ad146100e2575b600080fd5b610064610113565b60405161007191906102b2565b60405180910390f35b610094600480360381019061008f919061030d565b61011c565b005b6100b060048036038101906100ab9190610480565b610126565b005b6100cc60048036038101906100c791906104dc565b6101af565b6040516100d991906102b2565b60405180910390f35b6100fc60048036038101906100f7919061030d565b6101dd565b60405161010a9291906105a4565b60405180910390f35b60008054905090565b8060008190555050565b6001604051806040016040528083815260200184815250908060018154018082558091505060019003906000526020600020906002020160009091909190915060008201518160000155602082015181600101908161018591906107e0565b5050508060028360405161019991906108ee565b9081526020016040518091039020819055505050565b6002818051602081018201805184825260208301602085012081835280955050505050506000915090505481565b600181815481106101ed57600080fd5b906000526020600020906002020160009150905080600001549080600101805461021690610603565b80601f016020809104026020016040519081016040528092919081815260200182805461024290610603565b801561028f5780601f106102645761010080835404028352916020019161028f565b820191906000526020600020905b81548152906001019060200180831161027257829003601f168201915b5050505050905082565b6000819050919050565b6102ac81610299565b82525050565b60006020820190506102c760008301846102a3565b92915050565b6000604051905090565b600080fd5b600080fd5b6102ea81610299565b81146102f557600080fd5b50565b600081359050610307816102e1565b92915050565b600060208284031215610323576103226102d7565b5b6000610331848285016102f8565b91505092915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61038d82610344565b810181811067ffffffffffffffff821117156103ac576103ab610355565b5b80604052505050565b60006103bf6102cd565b90506103cb8282610384565b919050565b600067ffffffffffffffff8211156103eb576103ea610355565b5b6103f482610344565b9050602081019050919050565b82818337600083830152505050565b600061042361041e846103d0565b6103b5565b90508281526020810184848401111561043f5761043e61033f565b5b61044a848285610401565b509392505050565b600082601f8301126104675761046661033a565b5b8135610477848260208601610410565b91505092915050565b60008060408385031215610497576104966102d7565b5b600083013567ffffffffffffffff8111156104b5576104b46102dc565b5b6104c185828601610452565b92505060206104d2858286016102f8565b9150509250929050565b6000602082840312156104f2576104f16102d7565b5b600082013567ffffffffffffffff8111156105105761050f6102dc565b5b61051c84828501610452565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561055f578082015181840152602081019050610544565b60008484015250505050565b600061057682610525565b6105808185610530565b9350610590818560208601610541565b61059981610344565b840191505092915050565b60006040820190506105b960008301856102a3565b81810360208301526105cb818461056b565b90509392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061061b57607f821691505b60208210810361062e5761062d6105d4565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026106967fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82610659565b6106a08683610659565b95508019841693508086168417925050509392505050565b6000819050919050565b60006106dd6106d86106d384610299565b6106b8565b610299565b9050919050565b6000819050919050565b6106f7836106c2565b61070b610703826106e4565b848454610666565b825550505050565b600090565b610720610713565b61072b8184846106ee565b505050565b5b8181101561074f57610744600082610718565b600181019050610731565b5050565b601f8211156107945761076581610634565b61076e84610649565b8101602085101561077d578190505b61079161078985610649565b830182610730565b50505b505050565b600082821c905092915050565b60006107b760001984600802610799565b1980831691505092915050565b60006107d083836107a6565b9150826002028217905092915050565b6107e982610525565b67ffffffffffffffff81111561080257610801610355565b5b61080c8254610603565b610817828285610753565b600060209050601f83116001811461084a5760008415610838578287015190505b61084285826107c4565b8655506108aa565b601f19841661085886610634565b60005b828110156108805784890151825560018201915060208501945060208101905061085b565b8683101561089d5784890151610899601f8916826107a6565b8355505b6001600288020188555050505b505050505050565b600081905092915050565b60006108c882610525565b6108d281856108b2565b93506108e2818560208601610541565b80840191505092915050565b60006108fa82846108bd565b91508190509291505056fea26469706673582212204fdf5144f00283f6d3ccdd5c42dcf21eb0fd97acde52d73a42cc914c4b4ed54d64736f6c63430008110033",
// chainId: 1337,
// };
// // To sign the transaction
// // const signedTxResponse = await wallet.signTransaction(tx);
// // console.log(signedTxResponse);
// // To send the transaction
// const sendTxResponse = await wallet.sendTransaction(tx);
// await sendTxResponse.wait(1); // wait for 1 block conformation
// console.log(sendTxResponse);
const contractFactory = new ethers.ContractFactory(abi, binary, wallet)
console.log("Deploying....Please wait...")
const contract = await contractFactory.deploy() // STOP here! Wait for the contract to be deployed
await contract.deployTransaction.wait(1)
const currentFavoriteNumber = await contract.retrieve()
console.log(`Current Favorite Number = ${currentFavoriteNumber.toString()}`)
const transactionResponse = await contract.store("7")
const transactionReceipt = await transactionResponse.wait(1)
const updatedNumber = await contract.retrieve()
console.log(`updated Number = ${updatedNumber.toString()}`)
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})