-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (34 loc) · 1.28 KB
/
index.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
const { Web3 } = require("web3"); // "{ }" FOR HAVING LATEST VERSION
require('dotenv-safe').config({
allowEmptyValues: false,
example: '.env.example',
});
const fs = require('fs');
const {abi, bytecode } = JSON.parse(fs.readFileSync("out/PhotoNFT.sol/PhotoNFT.json"));
async function main () {
const alchemyUrl = process.env.ALCHEMY_SEPOLIA_NETWORK + process.env.ALCHEMY_API_KEY;
const web3 = new Web3(alchemyUrl);
const signer = web3.eth.accounts.privateKeyToAccount(
'0x' + process.env.WALLET_PRIVATE_KEY,
);
web3.eth.accounts.wallet.add(signer);
const initialOwner = signer.address;
// Using the signing account to deploy the contract
const contract = new web3.eth.Contract(abi);
contract.options.data = bytecode.object;
const deployTx = contract.deploy({
arguments: [initialOwner],
});
const deployedContract = await
deployTx.send({
from: signer.address,
gas: await deployTx.estimateGas(),
})
.once (
"transactionHash", (txhash) => {
console.log(`Mining deployment transaction ...`);
});
// The contract is now deployed on chain!
console.log(`Contract deployed at ${deployedContract.options.address}`);
}
main();