Skip to content

Commit

Permalink
Merge pull request #11 from push-protocol/feat/deploy-scripts
Browse files Browse the repository at this point in the history
Feat/deploy scripts
  • Loading branch information
0xNilesh authored Sep 6, 2024
2 parents 5b7e4b1 + 7bbac2e commit 6555487
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .env.sample
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"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target
.snfoundry_cache/
accounts/
.env
36 changes: 35 additions & 1 deletion README.md
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>"

65 changes: 65 additions & 0 deletions sh/declare.sh
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"
68 changes: 68 additions & 0 deletions sh/deploy.sh
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"

0 comments on commit 6555487

Please sign in to comment.