-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from push-protocol/feat/deploy-scripts
Feat/deploy scripts
- Loading branch information
Showing
6 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# RPC URLs | ||
# Sepolia testnet URL | ||
TESTNET_RPC_URL="" | ||
# Mainnet URL | ||
MAINNET_RPC_URL="" | ||
|
||
# Default fee token (eth or strk) | ||
DEFAULT_FEE_TOKEN="eth" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
target | ||
.snfoundry_cache/ | ||
accounts/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,36 @@ | ||
# push-cairo-smart-contracts | ||
This is a Cario implementation for Push Comm Contract. | ||
|
||
This is a Cairo implementation for the Push Comm Contract. | ||
|
||
## Configuration | ||
|
||
Before running the deployment or declaration scripts, ensure you have the following configuration: | ||
|
||
1. **Create an `.env` File** | ||
|
||
Copy the `env.sample` file to create the `.env` file with the following command: | ||
|
||
```bash | ||
cp .env.sample .env | ||
|
||
Make sure to update the `.env` file with the correct RPC URLs and fee token. | ||
|
||
2. **Account Files** | ||
|
||
Create an account using `starkli` and place the account file and keystore file in the accounts directory. | ||
|
||
## Deployment Guide | ||
1. **Declare the Contract Class** | ||
|
||
First, you need to declare the contract class to upload the Cairo contract code to the blockchain. This step will provide you with a class_hash that is used in the deployment step. | ||
|
||
```bash | ||
bash sh/declare.sh -n <network> -k <keystore> -a <account> -c <contract_name> | ||
2. **Deploy the Contract** | ||
After declaring the contract class, you need to deploy the contract. Update the class_hash in ./deploy/2_deploy.sh with the value obtained from the declaration step. | ||
```bash | ||
bash sh/deploy.sh -n <network> -a <account> -k <keystore> -c <class_hash> -d "<constructor_calldata>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# Load environment variables from .env file | ||
export $(grep -v '^#' ../.env | xargs) | ||
|
||
# Function to print usage information | ||
print_usage() { | ||
echo "Usage: $0 [-n <network>] [-a <account>] [-k <keystore>] [-t <fee_token>] [-c <contract_name>] [-h]" | ||
echo "" | ||
echo "Arguments:" | ||
echo " -n <network> Network (testnet or mainnet, required)" | ||
echo " -a <account> Account file path (required)" | ||
echo " -k <keystore> Keystore file path (required)" | ||
echo " -t <fee_token> Fee token ('eth' or 'strk', default: $DEFAULT_FEE_TOKEN)" | ||
echo " -c <contract_name> Contract name (required)" | ||
echo " -h Display this help message" | ||
exit 1 | ||
} | ||
|
||
# Parse command-line options | ||
while getopts ":n:a:k:t:c:h" opt; do | ||
case $opt in | ||
n) network="$OPTARG" ;; | ||
a) account="$OPTARG" ;; | ||
k) keystore="$OPTARG" ;; | ||
t) fee_token="$OPTARG" ;; | ||
c) contract_name="$OPTARG" ;; | ||
h) print_usage ;; # Call print_usage when -h is passed | ||
\?) echo "Invalid option -$OPTARG" >&2 | ||
print_usage ;; | ||
esac | ||
done | ||
|
||
# Use default value for fee_token if not provided | ||
fee_token=${fee_token:-$DEFAULT_FEE_TOKEN} | ||
|
||
# Validate the fee_token value | ||
if [[ "$fee_token" != "eth" && "$fee_token" != "strk" ]]; then | ||
echo "Error: fee_token (-t) must be either 'eth' or 'strk'." | ||
exit 1 | ||
fi | ||
|
||
# Determine the URL based on the selected network | ||
if [ "$network" == "testnet" ]; then | ||
url="$TESTNET_RPC_URL" | ||
elif [ "$network" == "mainnet" ]; then | ||
url="$MAINNET_RPC_URL" | ||
else | ||
echo "Error: Network (-n) must be 'testnet' or 'mainnet'." | ||
print_usage | ||
fi | ||
|
||
# Check for required arguments | ||
if [ -z "$account" ] || [ -z "$keystore" ] || [ -z "$contract_name" ]; then | ||
echo "Error: account (-a), keystore (-k), and contract_name (-c) are required." | ||
print_usage | ||
fi | ||
|
||
# Declare the contract using sncast | ||
sncast --url "$url" \ | ||
--account "$account" \ | ||
--keystore "$keystore" \ | ||
declare \ | ||
--fee-token "$fee_token" \ | ||
--contract-name "$contract_name" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/bash | ||
|
||
# Load environment variables from .env file | ||
export $(grep -v '^#' ../.env | xargs) | ||
|
||
# Function to print usage information | ||
print_usage() { | ||
echo "Usage: $0 [-n <network>] [-a <account>] [-k <keystore>] [-c <class_hash>] [-t <fee_token>] [-d <constructor_calldata>] [-h]" | ||
echo "" | ||
echo "Arguments:" | ||
echo " -n <network> Network (testnet or mainnet, required)" | ||
echo " -a <account> Account file path (required)" | ||
echo " -k <keystore> Keystore file path (required)" | ||
echo " -c <class_hash> Deployed class hash (required)" | ||
echo " -t <fee_token> Fee token ('eth' or 'strk', default: $DEFAULT_FEE_TOKEN)" | ||
echo " -d <constructor_calldata> Constructor calldata (required)" | ||
echo " -h Display this help message" | ||
exit 1 | ||
} | ||
|
||
# Parse command-line options | ||
while getopts ":n:a:k:c:t:d:h" opt; do | ||
case $opt in | ||
n) network="$OPTARG" ;; | ||
a) account="$OPTARG" ;; | ||
k) keystore="$OPTARG" ;; | ||
c) class_hash="$OPTARG" ;; | ||
t) fee_token="$OPTARG" ;; | ||
d) constructor_calldata="$OPTARG" ;; | ||
h) print_usage ;; # Call print_usage when -h is passed | ||
\?) echo "Invalid option -$OPTARG" >&2 | ||
print_usage ;; | ||
esac | ||
done | ||
|
||
# Use default value for fee_token if not provided | ||
fee_token=${fee_token:-$DEFAULT_FEE_TOKEN} | ||
|
||
# Validate the fee_token value | ||
if [[ "$fee_token" != "eth" && "$fee_token" != "strk" ]]; then | ||
echo "Error: fee_token (-t) must be either 'eth' or 'strk'." | ||
exit 1 | ||
fi | ||
|
||
# Determine the URL based on the selected network | ||
if [ "$network" == "testnet" ]; then | ||
url="$TESTNET_RPC_URL" | ||
elif [ "$network" == "mainnet" ]; then | ||
url="$MAINNET_RPC_URL" | ||
else | ||
echo "Error: Network (-n) must be 'testnet' or 'mainnet'." | ||
print_usage | ||
fi | ||
|
||
# Check for required arguments | ||
if [ -z "$account" ] || [ -z "$keystore" ] || [ -z "$class_hash" ] || [ -z "$constructor_calldata" ]; then | ||
echo "Error: account (-a), keystore (-k), class_hash (-c), and constructor_calldata (-d) are required." | ||
print_usage | ||
fi | ||
|
||
# Deploy the contract using sncast | ||
sncast --url "$url" \ | ||
--account "$account" \ | ||
--keystore "$keystore" \ | ||
deploy \ | ||
--fee-token "$fee_token" \ | ||
--class-hash "$class_hash" \ | ||
--constructor-calldata "$constructor_calldata" |