forked from flare-foundation/developer-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_contract_flare.js
31 lines (24 loc) · 978 Bytes
/
deploy_contract_flare.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
// THIS IS EXAMPLE CODE. DO NOT USE THIS CODE IN PRODUCTION.
import { Web3 } from "web3";
import fs from "fs";
const web3 = new Web3(
new Web3.providers.HttpProvider("https://flare-api.flare.network/ext/C/rpc"),
);
const bytecode = fs.readFileSync("./build/FtsoV2FeedConsumer.bin", "utf8");
import abi from "./build/FtsoV2FeedConsumer.json" assert { type: "json" };
const FtsoV2FeedConsumer = new web3.eth.Contract(abi);
FtsoV2FeedConsumer.handleRevert = true;
async function deploy() {
const privateKey = process.env.ACCOUNT_PRIVATE_KEY.toString();
const wallet = web3.eth.accounts.wallet.add(privateKey);
const contractDeployer = FtsoV2FeedConsumer.deploy({
data: "0x" + bytecode,
});
const tx = await contractDeployer.send({
from: wallet[0].address,
nonce: await web3.eth.getTransactionCount(wallet[0].address),
gasPrice: await web3.eth.getGasPrice(),
});
console.log("Contract deployed at address: " + tx.options.address);
}
deploy();