diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..92fbbac Binary files /dev/null and b/.DS_Store differ diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..bea5967 --- /dev/null +++ b/.env.sample @@ -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" diff --git a/.gitignore b/.gitignore index 73aa31e..31a83f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ target .snfoundry_cache/ +accounts/ +.env \ No newline at end of file diff --git a/README.md b/README.md index 9df459e..cb92dc0 100644 --- a/README.md +++ b/README.md @@ -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 -k -a -c + +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 -a -k -c -d "" + \ No newline at end of file diff --git a/sh/declare.sh b/sh/declare.sh new file mode 100644 index 0000000..69dff2a --- /dev/null +++ b/sh/declare.sh @@ -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 ] [-a ] [-k ] [-t ] [-c ] [-h]" + echo "" + echo "Arguments:" + echo " -n Network (testnet or mainnet, required)" + echo " -a Account file path (required)" + echo " -k Keystore file path (required)" + echo " -t Fee token ('eth' or 'strk', default: $DEFAULT_FEE_TOKEN)" + echo " -c 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" diff --git a/sh/deploy.sh b/sh/deploy.sh new file mode 100644 index 0000000..9e11d55 --- /dev/null +++ b/sh/deploy.sh @@ -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 ] [-a ] [-k ] [-c ] [-t ] [-d ] [-h]" + echo "" + echo "Arguments:" + echo " -n Network (testnet or mainnet, required)" + echo " -a Account file path (required)" + echo " -k Keystore file path (required)" + echo " -c Deployed class hash (required)" + echo " -t Fee token ('eth' or 'strk', default: $DEFAULT_FEE_TOKEN)" + echo " -d 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"