-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
106 additions
and
0 deletions.
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,62 @@ | ||
#!/bin/bash | ||
|
||
# This script compares the attributes of two ZRC20 contracts on a blockchain. | ||
# It takes two contract addresses and an RPC URL, fetches their values, and compares them. | ||
# | ||
# Usage: | ||
# ./compare_zrc20_info.sh <contract_address_1> <contract_address_2> <rpc_url> | ||
|
||
|
||
# Check if cast is installed | ||
if ! command -v cast &> /dev/null | ||
then | ||
echo "cast CLI could not be found. Please install it first." | ||
exit 1 | ||
fi | ||
|
||
# Check if the correct number of arguments is provided | ||
if [ "$#" -ne 3 ]; then | ||
echo "Usage: $0 <contract_address_1> <contract_address_2> <rpc_url>" | ||
exit 1 | ||
fi | ||
|
||
# Get the contract addresses and RPC URL from the script arguments | ||
CONTRACT_ADDRESS_1=$1 | ||
CONTRACT_ADDRESS_2=$2 | ||
RPC_URL=$3 | ||
|
||
# Function to fetch ZRC20 attributes | ||
fetch_zrc20_info() { | ||
local CONTRACT_ADDRESS=$1 | ||
local RPC_URL=$2 | ||
|
||
SYSTEM_CONTRACT=$(cast call "$CONTRACT_ADDRESS" "SYSTEM_CONTRACT_ADDRESS()(address)" --rpc-url "$RPC_URL" | tr -d '\n') | ||
ZRC20_NAME=$(cast call "$CONTRACT_ADDRESS" "name()(string)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/"//g') | ||
ZRC20_SYMBOL=$(cast call "$CONTRACT_ADDRESS" "symbol()(string)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/"//g') | ||
ZRC20_DECIMALS=$(cast call "$CONTRACT_ADDRESS" "decimals()(uint8)" --rpc-url "$RPC_URL" | tr -d '\n') | ||
ZRC20_CHAIN_ID=$(cast call "$CONTRACT_ADDRESS" "CHAIN_ID()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n') | ||
ZRC20_COIN_TYPE=$(cast call "$CONTRACT_ADDRESS" "COIN_TYPE()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n') | ||
ZRC20_GAS_LIMIT=$(cast call "$CONTRACT_ADDRESS" "GAS_LIMIT()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/\[.*\]//g') | ||
|
||
echo "$SYSTEM_CONTRACT,$ZRC20_NAME,$ZRC20_SYMBOL,$ZRC20_DECIMALS,$ZRC20_CHAIN_ID,$ZRC20_COIN_TYPE,$ZRC20_GAS_LIMIT" | ||
} | ||
|
||
# Fetch attributes for both contracts | ||
INFO_1=$(fetch_zrc20_info $CONTRACT_ADDRESS_1 $RPC_URL) | ||
INFO_2=$(fetch_zrc20_info $CONTRACT_ADDRESS_2 $RPC_URL) | ||
|
||
# Split the results into arrays | ||
IFS=',' read -r -a VALUES_1 <<< "$INFO_1" | ||
IFS=',' read -r -a VALUES_2 <<< "$INFO_2" | ||
|
||
# Attribute names for clarity | ||
ATTRIBUTES=("SYSTEM_CONTRACT" "ZRC20_NAME" "ZRC20_SYMBOL" "ZRC20_DECIMALS" "ZRC20_CHAIN_ID" "ZRC20_COIN_TYPE" "ZRC20_GAS_LIMIT") | ||
|
||
# Compare values and output the result | ||
for i in "${!ATTRIBUTES[@]}"; do | ||
if [ "${VALUES_1[i]}" == "${VALUES_2[i]}" ]; then | ||
echo -e "✓ ${ATTRIBUTES[i]} is the same: ${VALUES_1[i]}" | ||
else | ||
echo -e "✗ ${ATTRIBUTES[i]} is different: ${VALUES_1[i]} (Contract 1) vs ${VALUES_2[i]} (Contract 2)" | ||
fi | ||
done |
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,44 @@ | ||
#!/bin/bash | ||
|
||
# This script retrieves various attributes of a ZRC20 contract on a blockchain. | ||
# It takes the contract address and an RPC URL as inputs and calls several | ||
# functions on the contract to obtain key information. These attributes | ||
# are typically required when a clone of the contract is to be deployed. | ||
# | ||
# Usage: | ||
# ./get_zrc20_info.sh <contract_address> <rpc_url> | ||
|
||
# Check if cast is installed | ||
if ! command -v cast &> /dev/null | ||
then | ||
echo "cast CLI could not be found. Please install it first." | ||
exit 1 | ||
fi | ||
|
||
# Check if the correct number of arguments is provided | ||
if [ "$#" -ne 2 ]; then | ||
echo "Usage: $0 <contract_address> <rpc_url>" | ||
exit 1 | ||
fi | ||
|
||
# Get the contract address and RPC URL from the script arguments | ||
CONTRACT_ADDRESS=$1 | ||
RPC_URL=$2 | ||
|
||
# Run the cast commands and capture the outputs | ||
SYSTEM_CONTRACT=$(cast call "$CONTRACT_ADDRESS" "SYSTEM_CONTRACT_ADDRESS()(address)" --rpc-url "$RPC_URL" | tr -d '\n') | ||
ZRC20_NAME=$(cast call "$CONTRACT_ADDRESS" "name()(string)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/"//g') | ||
ZRC20_SYMBOL=$(cast call "$CONTRACT_ADDRESS" "symbol()(string)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/"//g') | ||
ZRC20_DECIMALS=$(cast call "$CONTRACT_ADDRESS" "decimals()(uint8)" --rpc-url "$RPC_URL" | tr -d '\n') | ||
ZRC20_CHAIN_ID=$(cast call "$CONTRACT_ADDRESS" "CHAIN_ID()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/\[.*\]//g') | ||
ZRC20_COIN_TYPE=$(cast call "$CONTRACT_ADDRESS" "COIN_TYPE()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n') | ||
ZRC20_GAS_LIMIT=$(cast call "$CONTRACT_ADDRESS" "GAS_LIMIT()(uint256)" --rpc-url "$RPC_URL" | tr -d '\n' | sed 's/\[.*\]//g') | ||
|
||
# Output the final result string | ||
echo "SYSTEM_CONTRACT=$SYSTEM_CONTRACT" | ||
echo "ZRC20_NAME=$ZRC20_NAME" | ||
echo "ZRC20_SYMBOL=$ZRC20_SYMBOL" | ||
echo "ZRC20_DECIMALS=$ZRC20_DECIMALS" | ||
echo "ZRC20_CHAIN_ID=$ZRC20_CHAIN_ID" | ||
echo "ZRC20_COIN_TYPE=$ZRC20_COIN_TYPE" | ||
echo "ZRC20_GAS_LIMIT=$ZRC20_GAS_LIMIT" |