forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_create2.sh
77 lines (69 loc) · 2.35 KB
/
deploy_create2.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
#!/bin/sh
set -ex
# Deploys create2 proxy according to https://github.com/primev/deterministic-deployment-proxy
PROXY_ADDRESS="0x4e59b44847b379578588920ca78fbf26c0b4956c"
SIGNER_ADDRESS="0x3fab184622dc19b6109349b94811493bf2a45362"
# The following transaction string contains fixed from address corresponding to the signer address: 0x3fab184622dc19b6109349b94811493bf2a45362
TRANSACTION="0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222"
help() {
echo "Usage: $0 <RPC_URL>"
echo " RPC_URL: URL of the JSON RPC endpoint"
exit 1
}
RPC_URL="${1:-$RPC_URL}"
if [ -z "${RPC_URL}" ]; then
help
fi
RESPONSE=$(
curl \
--silent \
--request POST \
--header "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": ["'"${PROXY_ADDRESS}"'", "latest"],
"id": 1
}' \
"${RPC_URL}")
if [ -z "${RESPONSE}" ] || [ "${RESPONSE}" = "null" ]; then
echo "Error: No response from JSON RPC at ${RPC_URL}"
exit 1
fi
if [ "$(echo "${RESPONSE}" | jq -r '.result')" != "0x" ]; then
echo "Contract already deployed at ${PROXY_ADDRESS}"
exit 0
fi
echo "No contract deployed at ${PROXY_ADDRESS}, deploying..."
curl \
--silent "${RPC_URL}" \
--request 'POST' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_sendRawTransaction",
"params": ["'"${TRANSACTION}"'"]
}'
sleep 5
# For prod we'll have to set gas params s.t. no ether is leftover here. For now we warn
RESPONSE=$(
curl \
--silent \
--request POST \
--header "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["'"${SIGNER_ADDRESS}"'", "latest"],
"id": 1
}' \
"${RPC_URL}")
if [ -z "${RESPONSE}" ] || [ "${RESPONSE}" = "null" ]; then
echo "Error: No response from JSON RPC at ${RPC_URL}"
exit 1
fi
RESULT="$(echo "${RESPONSE}" | jq -r '.result')"
if [ "${RESULT}" != "0x0" ]; then
echo "WARNING: Deployment signer (${SIGNER_ADDRESS}) has leftover balance of ${RESULT} wei."
fi