1 | const fs = require('fs');
|
2 | const Browseth = require('browseth').default;
|
3 | const {XMLHttpRequest} = require('xmlhttprequest');
|
4 | const subabi = require('../build/NFTSubscription.json');
|
5 | const curveabi = require('../build/EthPriceCurve.json');
|
6 | const config = require('./config.json');
|
7 |
|
8 | const subbin = fs.readFileSync('../build/NFTSubscription.bin', 'utf8');
|
9 | const curvebin = fs.readFileSync('../build/EthPriceCurve.bin', 'utf8');
|
10 |
|
11 | global.XMLHttpRequest = XMLHttpRequest;
|
12 |
|
13 | const subscriptionPrice = config.paidPrice;
|
14 | const SECONDS_PER_YEAR = 31540000;
|
15 | const COST_PER_SECOND = config.costPerSecond;
|
16 |
|
17 | const b = new Browseth();
|
18 |
|
19 | b.wallet = new Browseth.Wallets.Online(b.rpc);
|
20 |
|
21 | const a = async () => {
|
22 | const transactionListener = new Browseth.Apis.TransactionListener(b.wallet);
|
23 | transactionListener.startPolling();
|
24 |
|
25 | b.addContract('priceCurve', curveabi, {bytecode: curvebin});
|
26 | b.addContract('subscription', subabi, {bytecode: subbin});
|
27 |
|
28 | const transactionHash1 = await b.contract.priceCurve
|
29 | .deploy(SECONDS_PER_YEAR, COST_PER_SECOND)
|
30 | .send();
|
31 | console.log('transaction hash for paid price curve', transactionHash1);
|
32 | const transaction1 = await transactionListener.resolveTransaction(
|
33 | transactionHash1,
|
34 | );
|
35 | console.log('transaction for paid price curve', transaction1);
|
36 |
|
37 | const transactionHash2 = await b.contract.priceCurve
|
38 | .deploy(3154000000, 0)
|
39 | .send();
|
40 | console.log('transaction hash for free price curve', transactionHash2);
|
41 | const transaction2 = await transactionListener.resolveTransaction(
|
42 | transactionHash2,
|
43 | );
|
44 | console.log('transaction for free price curve', transaction1);
|
45 |
|
46 | const transactionHash3 = await b.contract.subscription
|
47 | .deploy(transaction1.contractAddress)
|
48 | .send();
|
49 | console.log('transaction hash for token', transactionHash3);
|
50 | const transaction3 = await transactionListener.resolveTransaction(
|
51 | transactionHash3,
|
52 | );
|
53 |
|
54 | const transactionHash4 = await b.contract.subscription
|
55 | .deploy(transaction2.contractAddress)
|
56 | .send();
|
57 | console.log('transaction hash for token', transactionHash4);
|
58 | const transaction4 = await transactionListener.resolveTransaction(
|
59 | transactionHash4,
|
60 | );
|
61 |
|
62 | console.log('address for paid token', transaction3.contractAddress);
|
63 | console.log('address for free token', transaction4.contractAddress);
|
64 |
|
65 | const json = `{
|
66 | "paidAddress": "${transaction3.contractAddress}",
|
67 | "freeAddress": "${transaction4.contractAddress}",
|
68 | "paidPrice": "${subscriptionPrice}",
|
69 | "costPerSecond": ${COST_PER_SECOND}
|
70 | }`;
|
71 |
|
72 | fs.writeFileSync('./config.json', json);
|
73 | fs.writeFileSync('./components/NFTSubscription.json', JSON.stringify(subabi));
|
74 | };
|
75 |
|
76 | a();
|