-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarknet_build.sh
147 lines (123 loc) · 4.88 KB
/
starknet_build.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
######################################################
# #
# Starknet Build. A basic shell for Starknet compile,#
# declare and deploy. #
# Version: 0.1 may 2023 #
# By : devnet0x #
# #
######################################################
#!/bin/bash
if [[ ($# -lt 3) || ($1 != "devnet" && $1 != "testnet" && $1 != "testnet2") ]]
then
echo "Usage: starknet_build.sh <devnet|testnet|testnet2> <account_name> <cairo file> [constructor parameters as felt252]"
exit
fi
# Set environment parameters
if [ $1 == "devnet" ]
then
export STARKNET_NETWORK=alpha-goerli
export STARKNET_WALLET=starkware.starknet.wallets.open_zeppelin.OpenZeppelinAccount
ENVIRONMENT1="--gateway_url http://127.0.0.1:5050 --feeder_gateway_url http://127.0.0.1:5050"
fi
if [ $1 == "testnet" ]
then
export STARKNET_NETWORK=alpha-goerli
export STARKNET_WALLET=starkware.starknet.wallets.open_zeppelin.OpenZeppelinAccount
fi
if [ $1 == "testnet2" ]
then
export STARKNET_NETWORK=alpha-goerli2
export STARKNET_WALLET=starkware.starknet.wallets.open_zeppelin.OpenZeppelinAccount
fi
# Set keys parameters
#PUBLIC_KEY=`cat ${2} | awk 'FNR == 1 {print $1}'`
#export PROTOSTAR_ACCOUNT_PRIVATE_KEY=`cat ${2} | awk 'FNR == 2 {print $1}'`
# Set contructor inputs
if [ $# -gt 3 ]
then
INPUTS="--inputs ${@:4}"
fi
###################################################
# #
# Compile #
# #
###################################################
# Start process
echo -e "\033[1;32mCompiling...\033[0m"
FILENAME=`basename $3 .cairo`
cargo run --bin starknet-compile ./${3} ./${FILENAME}.sierra
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFAILED COMPILE.\033[0m"
exit
fi
###################################################
# #
# Declare #
# #
###################################################
echo -e "\033[1;32mDeclaring...\033[0m"
DECLARE_STATEMENT="starknet ${ENVIRONMENT1} --account ${2} declare --contract ${FILENAME}.sierra > build.tmp"
echo ${DECLARE_STATEMENT}
eval ${DECLARE_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed declare:\033[0m\n"${DECLARE_STATEMENT}
exit
fi
CLASS_HASH=`cat build.tmp | awk 'FNR == 3 {print $4}'`
TX_HASH=`cat build.tmp | awk 'FNR == 4 {print $3}'`
echo "Class Hash:" ${CLASS_HASH}
echo "Tx.Hash:" ${TX_HASH}
TX_STATUS=`starknet ${ENVIRONMENT1} tx_status --hash ${TX_HASH} | grep tx_status | awk 'FNR == 1 {print $2}'`
start=$SECONDS
while [[ (${TX_STATUS} == "\"RECEIVED\"") || (${TX_STATUS} == "\"PENDING\"") ]]
do
echo -ne "${TX_STATUS} $(( SECONDS - start )) secs.\r"
sleep 1
TX_STATUS=`starknet ${ENVIRONMENT1} tx_status --hash ${TX_HASH} | grep tx_status | awk 'FNR == 1 {print $2}'`
done
TX_STATUS=`starknet ${ENVIRONMENT1} tx_status --hash ${TX_HASH} | grep tx_status | awk 'FNR == 1 {print $2}'`
echo -ne "${TX_STATUS} $(( SECONDS - start )) secs.\n"
if [ ${TX_STATUS} != "\"ACCEPTED_ON_L2\"" ]
then
echo -e '\033[0;41mFAILED DECLARE.\033[0m'
TX_STATUS=`starknet ${ENVIRONMENT1} tx_status --hash ${TX_HASH}`
exit
fi
###################################################
# #
# Deploy #
# #
###################################################
echo -e "\033[1;32mDeploying...\033[0m"
DEPLOY_STATEMENT="starknet ${ENVIRONMENT1} --account ${2} deploy --max_fee 10000000000000 --class_hash ${CLASS_HASH} ${INPUTS} > build.tmp"
echo ${DEPLOY_STATEMENT}
eval ${DEPLOY_STATEMENT}
if [ $? -ne 0 ]
then
echo -e "\n\033[0;41mFailed command:\033[0m\n"${DEPLOY_STATEMENT}
exit
fi
CONTRACT_ADDRESS=`cat build.tmp | awk 'FNR == 2 {print $3}'`
TX_HASH=`cat build.tmp | awk 'FNR == 3 {print $3}'`
TX_STATUS=`starknet ${ENVIRONMENT1} tx_status --hash ${TX_HASH} | grep tx_status | awk 'FNR == 1 {print $2}'`
echo "Tx.Hash:" ${TX_HASH}
start=$SECONDS
while [[ (${TX_STATUS} == "\"RECEIVED\"") || (${TX_STATUS} == "\"PENDING\"") ]]
do
echo -ne "${TX_STATUS} $(( SECONDS - start )) secs.\r"
sleep 1
TX_STATUS=`starknet ${ENVIRONMENT1} tx_status --hash ${TX_HASH} | grep tx_status | awk 'FNR == 1 {print $2}'`
done
TX_STATUS=`starknet ${ENVIRONMENT1} tx_status --hash ${TX_HASH} | grep tx_status | awk 'FNR == 1 {print $2}'`
echo -ne "${TX_STATUS} $(( SECONDS - start )) secs.\n"
if [ ${TX_STATUS} != "\"ACCEPTED_ON_L2\"" ]
then
cat build.tmp
echo -e '\033[0;41mFAILED DEPLOY.\033[0m'
starknet ${ENVIRONMENT1} tx_status --hash ${TX_HASH}
exit
fi
echo "Contract Address:" ${CONTRACT_ADDRESS}
rm build.tmp