-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive_builders.js
77 lines (70 loc) · 3.2 KB
/
interactive_builders.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
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
70
71
72
73
74
75
76
77
```javascript
// Importing necessary libraries and tools
const readline = require('readline');
const axios = require('axios');
// Importing ControlPanel
const ControlPanel = require('./control_panel');
// Creating an instance of ControlPanel
const controlPanel = new ControlPanel();
// Interactive builders for conversational interactions
class InteractiveBuilders {
constructor() {
this.rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
}
// Function to deploy a smart contract
deploySmartContract() {
this.rl.question('Enter the blockchain: ', (blockchain) => {
this.rl.question('Enter the contract: ', (contract) => {
this.rl.question('Enter the account: ', (account) => {
this.rl.question('Enter the private key: ', (privateKey) => {
controlPanel.deploySmartContract(blockchain, contract, account, privateKey)
.then(receipt => {
console.log('Receipt: ', receipt);
this.rl.close();
})
.catch(error => {
console.error('Error: ', error);
this.rl.close();
});
});
});
});
});
}
// Function to interact with a smart contract
interactWithSmartContract() {
this.rl.question('Enter the blockchain: ', (blockchain) => {
this.rl.question('Enter the contract address: ', (contractAddress) => {
this.rl.question('Enter the contract: ', (contract) => {
this.rl.question('Enter the function name: ', (functionName) => {
this.rl.question('Enter the params (comma separated): ', (params) => {
this.rl.question('Enter the account: ', (account) => {
this.rl.question('Enter the private key: ', (privateKey) => {
const paramsArray = params.split(',').map(param => param.trim());
controlPanel.interactWithSmartContract(blockchain, contractAddress, contract, functionName, paramsArray, account, privateKey)
.then(result => {
console.log('Result: ', result);
this.rl.close();
})
.catch(error => {
console.error('Error: ', error);
this.rl.close();
});
});
});
});
});
});
});
});
}
}
// Creating an instance of InteractiveBuilders
const interactiveBuilders = new InteractiveBuilders();
// Starting the interactive builders
interactiveBuilders.deploySmartContract();
interactiveBuilders.interactWithSmartContract();
```