-
Notifications
You must be signed in to change notification settings - Fork 0
/
erc721-nft.sh
executable file
·180 lines (149 loc) · 4.2 KB
/
erc721-nft.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
#!/bin/bash
print_blue() {
echo -e "\033[34m$1\033[0m"
}
print_red() {
echo -e "\033[31m$1\033[0m"
}
print_green() {
echo -e "\033[32m$1\033[0m"
}
print_pink() {
echo -e "\033[95m$1\033[0m"
}
prompt_for_input() {
read -p "$1" input
echo $input
}
print_blue "Installing Hardhat and necessary dependencies..."
echo
npm i --save-dev hardhat
npm i @openzeppelin/contracts
npm i @swisstronik/utils
npm i ethers@6.4.0
echo
print_blue "Initializing Hardhat project..."
npx hardhat
echo
print_blue "Removing the default Hardhat configuration file..."
echo
rm hardhat.config.js
echo
read -p "Enter your wallet private key: " PRIVATE_KEY
if [[ $PRIVATE_KEY != 0x* ]]; then
PRIVATE_KEY="0x$PRIVATE_KEY"
fi
cat <<EOL > hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
module.exports = {
solidity: "0.8.20",
networks: {
swisstronik: {
url: "https://json-rpc.testnet.swisstronik.com/",
accounts: ["$PRIVATE_KEY"],
},
},
};
EOL
print_blue "Hardhat configuration file has been updated."
echo
rm -f contracts/Lock.sol
sleep 2
echo
print_pink "Enter NFT NAME:"
read -p "" NFT_NAME
echo
print_pink "Enter NFT SYMBOL:"
read -p "" NFT_SYMBOL
echo
cat <<EOL > contracts/ZunXBT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract ZunXBT is ERC721, Ownable {
constructor(address initialOwner) ERC721("$NFT_NAME", "$NFT_SYMBOL") Ownable(initialOwner) {}
function safeMint(address to, uint256 tokenId) public onlyOwner {
_safeMint(to, tokenId);
}
}
EOL
echo
print_blue "Compiling the contract..."
echo
npx hardhat compile
echo
print_blue "Creating scripts directory and the deployment script..."
echo
mkdir -p scripts
cat <<EOL > scripts/deploy.js
const hre = require("hardhat");
async function main() {
const [deployer] = await hre.ethers.getSigners();
const ContractFactory = await hre.ethers.getContractFactory("ZunXBT");
const contract = await ContractFactory.deploy(deployer.address);
await contract.waitForDeployment();
console.log(\`Your NFT Contract Address: \${contract.target}\`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
echo
npx hardhat run scripts/deploy.js --network swisstronik
echo
print_green "Contract deployment successful, Copy the above contract address and save it somewhere, you need to submit it in Testnet website"
echo
print_blue "Creating mint.js file..."
echo
read -p "Enter NFT Contract Address: " CONTRACT_ADDRESS
echo
cat <<EOL > scripts/mint.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 = "$CONTRACT_ADDRESS"
const [signer] = await hre.ethers.getSigners();
const contractFactory = await hre.ethers.getContractFactory("ZunXBT");
const contract = contractFactory.attach(contractAddress);
const functionName = "safeMint";
const safeMintTx = await sendShieldedTransaction(
signer,
contractAddress,
contract.interface.encodeFunctionData(functionName, [signer.address, 1]),
0
);
await safeMintTx.wait();
console.log(\`Transaction URL of Mint: https://explorer-evm.testnet.swisstronik.com/tx/\${safeMintTx.hash}\`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
EOL
print_blue "Minting Your NFT..."
echo
npx hardhat run scripts/mint.js --network swisstronik
echo
print_green "Copy the above Tx URL and save it somewhere, you need to submit it on Testnet page"
echo
sed -i 's/0x[0-9a-fA-F]*,\?\s*//g' hardhat.config.js
echo
print_blue "PRIVATE_KEY has been removed from hardhat.config.js."
echo
print_blue "Pushing these files to your github Repo link"
git add . && git commit -m "Initial commit" && git push origin main
echo
print_pink "Follow @ZunXBT on X for more one click guide like this"
echo