-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.mjs
69 lines (52 loc) · 1.91 KB
/
deploy.mjs
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
"use strict";
// import required libs
import { readFileSync } from "fs";
import Web3 from "web3";
async function deploy() {
// Replace with the node connection to Artela
let node = "https://betanet-rpc1.artela.network/";
// Replace with the path to your smart contract abi file
let abiPath = "./build/contract/Storage.abi";
// Replace with the path to your smart contract byte code file
let byteCodePath = "./build/contract/Storage.bin";
// Replace with your private key
let privateKey =
"0x653348a7b2e4c1d06ea0482fb5d7e63c33f5ef79361fc1515db2b72f3274d9a9";
const web3 = new Web3(node);
const deployParams = {
data: null,
arguments: null,
};
let byteTxt = readFileSync(byteCodePath, "utf-8").toString().trim();
if (byteTxt.startsWith("0x")) {
byteTxt = byteTxt.slice(2);
}
deployParams.data = byteTxt.trim();
let abiTxt = readFileSync(abiPath, "utf-8").toString().trim();
const contractAbi = JSON.parse(abiTxt);
let account = web3.eth.accounts.privateKeyToAccount(privateKey.trim());
web3.eth.accounts.wallet.add(account.privateKey);
// instantiate an instance of demo contract
let tokenContract = new web3.eth.Contract(contractAbi);
// deploy contract
let tokenDeploy = tokenContract.deploy(deployParams);
let nonceVal = await web3.eth.getTransactionCount(account.address);
let tokenTx = {
from: account.address,
data: tokenDeploy.encodeABI(),
nonce: nonceVal,
gasPrice: 1000,
gas: 7000000,
};
let signedTokenTx = await web3.eth.accounts.signTransaction(
tokenTx,
account.privateKey
);
await web3.eth
.sendSignedTransaction(signedTokenTx.rawTransaction)
.on("receipt", (receipt) => {
console.log(receipt);
console.log("contract address: ", receipt.contractAddress);
});
}
deploy().then();