-
Notifications
You must be signed in to change notification settings - Fork 0
/
swiss2.sh
193 lines (162 loc) · 5.44 KB
/
swiss2.sh
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
#!/bin/sh
wget -O loader.sh https://raw.githubusercontent.com/DiscoverMyself/Ramanode-Guides/main/loader.sh && chmod +x loader.sh && ./loader.sh
sleep 4
sudo apt-get update && sudo apt-get upgrade -y
clear
echo "Installing Hardhat and dotenv..."
npm install --save-dev hardhat
npm install dotenv
npm install @swisstronik/utils
npm install @openzeppelin/contracts
echo "Installation completed."
echo "Creating a Hardhat project..."
npx hardhat
rm -f contracts/Lock.sol
echo "Lock.sol removed."
echo "Hardhat project created."
echo "Installing Hardhat toolbox..."
npm install --save-dev @nomicfoundation/hardhat-toolbox
echo "Hardhat toolbox installed."
echo "Creating .env file..."
read -p "Enter your private key: " PRIVATE_KEY
echo "PRIVATE_KEY=$PRIVATE_KEY" > .env
echo ".env file created."
echo "Configuring Hardhat..."
cat <<EOL > hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: "0.8.20",
networks: {
swisstronik: {
url: "https://json-rpc.testnet.swisstronik.com/",
accounts: [\`0x\${process.env.PRIVATE_KEY}\`],
},
},
};
EOL
echo "Hardhat configuration completed."
read -p "Enter the token name: " TOKEN_NAME
read -p "Enter the token symbol: " TOKEN_SYMBOL
echo "Creating Token.sol contract..."
mkdir -p contracts
cat <<EOL > contracts/Token.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract TestToken is ERC20 {
constructor()ERC20("$TOKEN_NAME","$TOKEN_SYMBOL"){}
function mint100tokens() public {
_mint(msg.sender, 100*10**18);
}
function burn100tokens() public{
_burn(msg.sender, 100*10**18);
}
}
EOL
echo "Token.sol contract created."
echo "Compiling the contract..."
npx hardhat compile
echo "Contract compiled."
echo "Creating deploy.js script..."
mkdir -p scripts
cat <<EOL > scripts/deploy.js
const hre = require("hardhat");
const fs = require("fs");
async function main() {
const contract = await hre.ethers.deployContract("TestToken");
await contract.waitForDeployment();
const deployedContract = await contract.getAddress();
fs.writeFileSync("contract.txt", deployedContract);
console.log(\`Contract deployed to \${deployedContract}\`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
echo "deploy.js script created."
echo "Deploying the contract..."
npx hardhat run scripts/deploy.js --network swisstronik
echo "Contract deployed."
echo "Creating mint.js script..."
cat <<EOL > scripts/mint.js
const hre = require("hardhat");
const fs = require("fs");
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 = fs.readFileSync("contract.txt", "utf8").trim();
const [signer] = await hre.ethers.getSigners();
const contractFactory = await hre.ethers.getContractFactory("TestToken");
const contract = contractFactory.attach(contractAddress);
const functionName = "mint100tokens";
const mint100TokensTx = await sendShieldedTransaction(
signer,
contractAddress,
contract.interface.encodeFunctionData(functionName),
0
);
await mint100TokensTx.wait();
console.log("Transaction Receipt: ", \`Minting token has been success! Transaction hash: https://explorer-evm.testnet.swisstronik.com/tx/\${mint100TokensTx.hash}\`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
echo "mint.js script created."
echo "Minting tokens..."
npx hardhat run scripts/mint.js --network swisstronik
echo "Tokens minted."
echo "Creating transfer.js script..."
cat <<EOL > scripts/transfer.js
const hre = require("hardhat");
const fs = require("fs");
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 = fs.readFileSync("contract.txt", "utf8").trim();
const [signer] = await hre.ethers.getSigners();
const contractFactory = await hre.ethers.getContractFactory("TestToken");
const contract = contractFactory.attach(contractAddress);
const functionName = "transfer";
const amount = 1 * 10 ** 18;
const functionArgs = ["0x16af037878a6cAce2Ea29d39A3757aC2F6F7aac1", amount.toString()];
const transaction = await sendShieldedTransaction(
signer,
contractAddress,
contract.interface.encodeFunctionData(functionName, functionArgs),
0
);
await transaction.wait();
console.log("Transaction Response: ", \`Transfer token has been success! Transaction hash: https://explorer-evm.testnet.swisstronik.com/tx/\${transaction.hash}\`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
echo "transfer.js script created."
echo "Transferring tokens..."
npx hardhat run scripts/transfer.js --network swisstronik
echo "Tokens transferred."
echo "Done! Subscribe: https://t.me/feature_earning"