-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunchaine.sh
109 lines (87 loc) · 2.84 KB
/
unchaine.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
#!/bin/bash
curl -s https://raw.githubusercontent.com/macfly-base/logo/main/logo.sh | bash
sleep 5
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
PINK='\033[1;35m'
show() {
case $2 in
"error")
echo -e "${PINK}${BOLD}❌ $1${NORMAL}"
;;
"progress")
echo -e "${PINK}${BOLD}⏳ $1${NORMAL}"
;;
*)
echo -e "${PINK}${BOLD}✅ $1${NORMAL}"
;;
esac
}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR" || exit
read -p "Enter your Private Key: " PRIVATE_KEY
read -p "Enter the token name (e.g., macfly Token): " TOKEN_NAME
read -p "Enter the token symbol (e.g., macfly): " TOKEN_SYMBOL
mkdir -p "$SCRIPT_DIR/token_deployment"
cat <<EOL > "$SCRIPT_DIR/token_deployment/.env"
PRIVATE_KEY="$PRIVATE_KEY"
TOKEN_NAME="$TOKEN_NAME"
TOKEN_SYMBOL="$TOKEN_SYMBOL"
EOL
source "$SCRIPT_DIR/token_deployment/.env"
CONTRACT_NAME="macfly"
if [ ! -d ".git" ]; then
show "Initializing Git repository..." "progress"
git init
fi
if ! command -v forge &> /dev/null; then
show "Foundry is not installed. Installing now..." "progress"
source <(wget -O - https://raw.githubusercontent.com/macfly-base/installation/main/foundry.sh)
fi
if [ ! -d "$SCRIPT_DIR/lib/openzeppelin-contracts" ]; then
show "Installing OpenZeppelin Contracts..." "progress"
git clone https://github.com/OpenZeppelin/openzeppelin-contracts.git "$SCRIPT_DIR/lib/openzeppelin-contracts"
else
show "OpenZeppelin Contracts already installed."
fi
if [ ! -f "$SCRIPT_DIR/foundry.toml" ]; then
show "Creating foundry.toml and adding Unichain RPC..." "progress"
cat <<EOL > "$SCRIPT_DIR/foundry.toml"
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
[rpc_endpoints]
unichain = "https://sepolia.unichain.org"
EOL
else
show "foundry.toml already exists."
fi
show "Creating ERC-20 token contract using OpenZeppelin..." "progress"
mkdir -p "$SCRIPT_DIR/src"
cat <<EOL > "$SCRIPT_DIR/src/$CONTRACT_NAME.sol"
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract $CONTRACT_NAME is ERC20 {
constructor() ERC20("$TOKEN_NAME", "$TOKEN_SYMBOL") {
_mint(msg.sender, 100000 * (10 ** decimals()));
}
}
EOL
show "Compiling the contract..." "progress"
forge build
if [[ $? -ne 0 ]]; then
show "Contract compilation failed." "error"
exit 1
fi
show "Deploying the contract to Unichain..." "progress"
DEPLOY_OUTPUT=$(forge create "$SCRIPT_DIR/src/$CONTRACT_NAME.sol:$CONTRACT_NAME" \
--rpc-url unichain \
--private-key "$PRIVATE_KEY")
if [[ $? -ne 0 ]]; then
show "Deployment failed." "error"
exit 1
fi
CONTRACT_ADDRESS=$(echo "$DEPLOY_OUTPUT" | grep -oP 'Deployed to: \K(0x[a-fA-F0-9]{40})')
show "Token deployed successfully at address: https://sepolia.uniscan.xyz/address/$CONTRACT_ADDRESS"