forked from stellar/soroban-example-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize.sh
More file actions
executable file
·91 lines (74 loc) · 2.67 KB
/
initialize.sh
File metadata and controls
executable file
·91 lines (74 loc) · 2.67 KB
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
#!/bin/bash
set -e
NETWORK="$1"
# If soroban-cli is called inside the soroban-preview docker containter,
# it can call the stellar standalone container just using its name "stellar"
if [[ "$IS_USING_DOCKER" == "true" ]]; then
SOROBAN_RPC_HOST="http://stellar:8000"
else
SOROBAN_RPC_HOST="http://localhost:8000"
fi
SOROBAN_RPC_URL="$SOROBAN_RPC_HOST/soroban/rpc"
case "$1" in
standalone)
echo "Using standalone network"
SOROBAN_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
FRIENDBOT_URL="$SOROBAN_RPC_HOST/friendbot"
;;
futurenet)
echo "Using Futurenet network"
SOROBAN_NETWORK_PASSPHRASE="Test SDF Future Network ; October 2022"
FRIENDBOT_URL="https://friendbot-futurenet.stellar.org/"
;;
*)
echo "Usage: $0 standalone|futurenet"
exit 1
;;
esac
#if !(soroban config network ls | grep "$NETWORK" 2>&1 >/dev/null); then
# Always set a net configuration
echo Add the $NETWORK network to cli client
soroban config network add "$NETWORK" \
--rpc-url "$SOROBAN_RPC_URL" \
--network-passphrase "$SOROBAN_NETWORK_PASSPHRASE"
#fi
if !(soroban config identity ls | grep token-admin 2>&1 >/dev/null); then
echo Create the token-admin identity
soroban config identity generate token-admin
fi
TOKEN_ADMIN_SECRET="$(soroban config identity show token-admin)"
TOKEN_ADMIN_ADDRESS="$(soroban config identity address token-admin)"
# TODO: Remove this once we can use `soroban config identity` from webpack.
echo "$TOKEN_ADMIN_SECRET" > .soroban/token_admin_secret
echo "$TOKEN_ADMIN_ADDRESS" > .soroban/token_admin_address
# This will fail if the account already exists, but it'll still be fine.
echo Fund token-admin account from friendbot
curl --silent -X POST "$FRIENDBOT_URL?addr=$TOKEN_ADMIN_ADDRESS" >/dev/null
ARGS="--network $NETWORK --source token-admin"
echo Wrap the Stellar asset
mkdir -p .soroban
TOKEN_ID=$(soroban lab token wrap $ARGS --asset "EXT:$TOKEN_ADMIN_ADDRESS")
echo "Token wrapped succesfully with TOKEN_ID: $TOKEN_ID"
echo -n "$TOKEN_ID" > .soroban/token_id
echo Build the crowdfund contract
make build
echo Deploy the crowdfund contract
CROWDFUND_ID="$(
soroban contract deploy $ARGS \
--wasm target/wasm32-unknown-unknown/release/soroban_crowdfund_contract.wasm
)"
echo "$CROWDFUND_ID" > .soroban/crowdfund_id
echo "Contract deployed succesfully with ID: $CROWDFUND_ID"
echo "Initialize the crowdfund contract"
deadline="$(($(date +"%s") + 86400))"
soroban contract invoke \
$ARGS \
--wasm target/wasm32-unknown-unknown/release/soroban_crowdfund_contract.wasm \
--id "$CROWDFUND_ID" \
-- \
initialize \
--recipient "$TOKEN_ADMIN_ADDRESS" \
--deadline "$deadline" \
--target_amount "1000000000" \
--token "$TOKEN_ID"
echo "Done"