-
Notifications
You must be signed in to change notification settings - Fork 2
/
deploy.js
39 lines (37 loc) · 1.41 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
require('dotenv').config();
const endpoint = process.env.ENDPOINT_URL;
const address = process.env.PUBLIC_KEY;
const privKey = process.env.PRIVATE_KEY;
var Web3 = require('web3');
var web3 = new Web3(Web3.givenProvider || endpoint);
var fs = require('fs');
var contractABI = JSON.parse(fs.readFileSync('./PCHNFT_sol_PlaceholderHeroes.abi', 'utf8'));
var contractBIN = fs.readFileSync('./PCHNFT_sol_PlaceholderHeroes.bin', 'utf8');
//Create asynchronous deploy function
const deploy = async() => {
console.log('Attempting to deploy contract from: ', address);
//Create new contract object
const contractNFT = new web3.eth.Contract(contractABI, address);
//Deploy contract object as a transaction
const contractTX = contractNFT.deploy({
//Set transaction data as the contract bytecode
data: contractBIN,
});
//Sign the transaction
const createTransaction = await web3.eth.accounts.signTransaction({
//Define transaction parameters
from: address,
data: contractTX.encodeABI(),
gas: '2968862',
},
privKey
);
//Return transaction receipt
const createReceipt = await web3.eth.sendSignedTransaction(
createTransaction.rawTransaction
);
//Log contract address from receipt
console.log('Contract successfully deployed at: ', createReceipt.contractAddress);
};
//Don’t forget to run the function!
deploy();