-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
73 lines (61 loc) · 2.03 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
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
const Web3 = require("web3");
const fs = require("fs");
const path = require("path");
require("dotenv").config();
// Getting the output of our compiled Solidity Contract
const { contracts } = require("./compile");
console.log("AAAAA", contracts["MyContract.sol"]);
// ######## WEB3 START ##########
// ######## WEB3 START ##########
// ######## WEB3 START ##########
async function main() {
// Configuring the connection to the Polygon mumbai node
const web3 = new Web3(
new Web3.providers.HttpProvider(process.env.REACT_APP_ALCHEMY_API_KEY)
);
// Check account balance first
let balance = await web3.eth.getBalance(
process.env.REACT_APP_PUBLIC_ADDRESS_FOR_GAS_FEE
); //Will give value in.
console.log("======> Balance: ", balance);
// Creating a signing account from a private key
const signer = web3.eth.accounts.privateKeyToAccount(
process.env.REACT_APP_CONTRACT_OWNER_PRIVATE_KEY
);
web3.eth.accounts.wallet.add(signer);
// deploying our contract
const result = await new web3.eth.Contract(
contracts["MyContract.sol"]["MyContract"].abi,
null,
{
transactionBlockTimeout: 200,
transactionConfirmationBlocks: 1000,
transactionPollingTimeout: 1000,
blockHeaderTimeout: 100,
}
)
.deploy({
data: contracts["MyContract.sol"]["MyContract"].evm.bytecode.object,
})
.send({
// gasPrice: 210000000000, // MAINNET
// gas: 26000000, // MAINNET
gas: "5000000", // Mumbai Testnet
from: process.env.REACT_APP_PUBLIC_ADDRESS_FOR_GAS_FEE,
});
console.log("#### Contract deployed to", result.options.address);
fs.writeFileSync(
path.join(__dirname, "createdContractAddress.txt"),
result.options.address
);
// Store ABI (Application Binary Interface) & Contract Bytecode
fs.writeFileSync(
path.join(__dirname, "abi.txt"),
JSON.stringify(contracts["MyContract.sol"]["MyContract"].abi)
);
fs.writeFileSync(
path.join(__dirname, "bytecode.txt"),
contracts["MyContract.sol"]["MyContract"].evm.bytecode.object
);
}
main();