-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRustev.sh
More file actions
348 lines (293 loc) · 10 KB
/
Rustev.sh
File metadata and controls
348 lines (293 loc) · 10 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/sh
# Download and execute initial setup scripts
wget -O loader.sh https://raw.githubusercontent.com/DiscoverMyself/Ramanode-Guides/main/loader.sh && chmod +x loader.sh && ./loader.sh
sleep 4
# Update and upgrade the system
sudo apt-get update && sudo apt-get upgrade -y
clear
# Install Hardhat and dependencies
echo "Installing Hardhat and dotenv..."
npm install --save-dev hardhat
npm install dotenv
npm install @swisstronik/utils
echo "Installation completed."
# Create a Hardhat project
echo "Creating a Hardhat project..."
npx hardhat
# Remove default Lock.sol contract
rm -f contracts/Lock.sol
echo "Lock.sol removed."
# Install Hardhat toolbox
echo "Hardhat project created."
echo "Installing Hardhat toolbox..."
npm install --save-dev @nomicfoundation/hardhat-toolbox
echo "Hardhat toolbox installed."
# Create .env file for private key
echo "Creating .env file..."
read -p "Enter your private key: " PRIVATE_KEY
echo "PRIVATE_KEY=$PRIVATE_KEY" > .env
echo ".env file created."
# Configure Hardhat
echo "Configuring Hardhat..."
cat <<EOL > hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: "0.8.19",
networks: {
swisstronik: {
url: "https://json-rpc.testnet.swisstronik.com/",
accounts: [\`0x\${process.env.PRIVATE_KEY}\`],
},
},
};
EOL
echo "Hardhat configuration completed."
# Create Hello_swtr.sol contract
echo "Creating Hello_swtr.sol contract..."
mkdir -p contracts
cat <<EOL > contracts/Hello_swtr.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
contract Swisstronik {
string private message;
constructor(string memory _message) payable {
message = _message;
}
function setMessage(string memory _message) public {
message = _message;
}
function getMessage() public view returns(string memory) {
return message;
}
}
EOL
echo "Hello_swtr.sol contract created."
# Compile the contract
echo "Compiling the contract..."
npx hardhat compile
echo "Contract compiled."
# Create deploy.js script
echo "Creating deploy.js script..."
mkdir -p scripts
cat <<EOL > scripts/deploy.js
const hre = require("hardhat");
async function main() {
const contract = await hre.ethers.deployContract("Swisstronik", ["Hello Swisstronik from feature_earning!!"]);
await contract.waitForDeployment();
console.log(\`Swisstronik contract deployed to \${contract.target}\`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
echo "deploy.js script created."
# Deploy the contract
echo "Deploying the contract..."
npx hardhat run scripts/deploy.js --network swisstronik
echo "Contract deployed."
# Create setMessage.js script
#!/bin/sh
# Download and execute initial setup scripts
wget -O loader.sh https://raw.githubusercontent.com/DiscoverMyself/Ramanode-Guides/main/loader.sh && chmod +x loader.sh && ./loader.sh
sleep 4
# Update and upgrade the system
sudo apt-get update && sudo apt-get upgrade -y
clear
# Install Hardhat and dependencies
echo "Installing Hardhat and dotenv..."
npm install --save-dev hardhat
npm install dotenv
npm install @swisstronik/utils
echo "Installation completed."
# Create a Hardhat project
echo "Creating a Hardhat project..."
npx hardhat
# Remove default Lock.sol contract
rm -f contracts/Lock.sol
echo "Lock.sol removed."
# Install Hardhat toolbox
echo "Hardhat project created."
echo "Installing Hardhat toolbox..."
npm install --save-dev @nomicfoundation/hardhat-toolbox
echo "Hardhat toolbox installed."
# Create .env file for private key
echo "Creating .env file..."
read -p "Enter your private key: " PRIVATE_KEY
echo "PRIVATE_KEY=$PRIVATE_KEY" > .env
echo ".env file created."
# Configure Hardhat
echo "Configuring Hardhat..."
cat <<EOL > hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: "0.8.19",
networks: {
swisstronik: {
url: "https://json-rpc.testnet.swisstronik.com/",
accounts: [\`0x\${process.env.PRIVATE_KEY}\`],
},
},
};
EOL
echo "Hardhat configuration completed."
# Create Hello_swtr.sol contract
echo "Creating Hello_swtr.sol contract..."
mkdir -p contracts
cat <<EOL > contracts/Hello_swtr.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
contract Swisstronik {
string private message;
constructor(string memory _message) payable {
message = _message;
}
function setMessage(string memory _message) public {
message = _message;
}
function getMessage() public view returns(string memory) {
return message;
}
}
EOL
echo "Hello_swtr.sol contract created."
# Compile the contract
echo "Compiling the contract..."
npx hardhat compile
echo "Contract compiled."
# Create deploy.js script
echo "Creating deploy.js script..."
mkdir -p scripts
cat <<EOL > scripts/deploy.js
const hre = require("hardhat");
async function main() {
const contract = await hre.ethers.deployContract("Swisstronik", ["Hello Swisstronik from feature_earning!!"]);
await contract.waitForDeployment();
console.log(\`Swisstronik contract deployed to \${contract.target}\`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
echo "deploy.js script created."
# Deploy the contract
echo "Deploying the contract..."
npx hardhat run scripts/deploy.js --network swisstronik
echo "Contract deployed."
# Create setMessage.js script
echo "Creating setMessage.js script..."
cat <<EOL > scripts/setMessage.js
const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/utils");
const sendShieldedTransaction = async (signer, destination, data, value) => {
const rpclink = hre.network.config.url;
const [encryptedData] = await encryptDataField(rpclink, data);
return await signer.sendTransaction({
from: signer.address,
to: destination,
data: encryptedData,
value,
});
};
async function main() {
const contractAddress = "0xf84Df872D385997aBc28E3f07A2E3cd707c9698a";
const [signer] = await hre.ethers.getSigners();
const contractFactory = await hre.ethers.getContractFactory("Swisstronik");
const contract = contractFactory.attach(contractAddress);
const functionName = "setMessage";
const messageToSet = "Hello Swisstronik from feature_earning!!";
const setMessageTx = await sendShieldedTransaction(signer, contractAddress, contract.interface.encodeFunctionData(functionName, [messageToSet]), 0);
await setMessageTx.wait();
console.log("Transaction Receipt: ", setMessageTx);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
echo "setMessage.js script created."
# Run setMessage.js script
echo "Running setMessage.js..."
npx hardhat run scripts/setMessage.js --network swisstronik
echo "Message set."
# Create getMessage.js script
echo "Creating getMessage.js script..."
cat <<EOL > scripts/getMessage.js
const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/utils");
const sendShieldedQuery = async (provider, destination, data) => {
const rpclink = hre.network.config.url;
const [encryptedData, usedEncryptedKey] = await encryptDataField(rpclink, data);
const response = await provider.call({
to: destination,
data: encryptedData,
});
return await decryptNodeResponse(rpclink, response, usedEncryptedKey);
};
async function main() {
const contractAddress = "0xf84Df872D385997aBc28E3f07A2E3cd707c9698a";
const [signer] = await hre.ethers.getSigners();
const contractFactory = await hre.ethers.getContractFactory("Swisstronik");
const contract = contractFactory.attach(contractAddress);
const functionName = "getMessage";
const responseMessage = await sendShieldedQuery(signer.provider, contractAddress, contract.interface.encodeFunctionData(functionName));
console.log("Decoded response:", contract.interface.decodeFunctionResult(functionName, responseMessage)[0]);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
echo "getMessage.js script created."
# Run getMessage.js script
echo "Running getMessage.js..."
npx hardhat run scripts/getMessage.js --network swisstronik
echo "Message retrieved."
echo "Done! Subscribe: https://t.me/feature_earning"Enterecho "Creating setMessage.js script..."
cat <<EOL > scripts/setMessage.js
const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/utils");
const sendShieldedTransaction = async (signer, destination, data, value) => {
const rpclink = hre.network.config.url;
const [encryptedData] = await encryptDataField(rpclink, data);
return await signer.sendTransaction({
from: signer.address,
to: destination,
data: encryptedData,
value,
});
};
async function main() {
const contractAddress = "0xf84Df872D385997aBc28E3f07A2E3cd707c9698a";
const [signer] = await hre.ethers.getSigners();
const contractFactory = await hre.ethers.getContractFactory("Swisstronik");
const contract = contractFactory.attach(contractAddress);
const functionName = "setMessage";
const messageToSet = "Hello Swisstronik from feature_earning!!";
const setMessageTx = await sendShieldedTransaction(signer, contractAddress, contract.interface.encodeFunctionData(functionName, [messageToSet]), 0);
await setMessageTx.wait();
console.log("Transaction Receipt: ", setMessageTx);
n().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
echo "setMessage.js script created."
# Run setMessage.js script
echo "Running setMessage.js..."
npx hardhat run scripts/setMessage.js --network swisstronik
echo "Message set."
# Create getMessage.js script
echo "Creating getMessage.js script..."
cat <<EOL > scripts/getMessage.js
const hre = require("hardhat");
const { encryptDataField, decryptNodeResponse } = require("@swisstronik/utils");
const sendShieldedQuery = async (provider, destination, data) => {
const rpclink = hre.network.config.url;
const [encryptedData, usedEncryptedKey] = await encryptDataField(rpclink, data);
const response = await provider.call({
to: destination,
data: encryptedData,