Last active
April 30, 2025 18:58
-
-
Save pcaversaccio/621142f38232f1ca28d11fa180d632a0 to your computer and use it in GitHub Desktop.
A Bash wrapper to save the output of `./safe_hashes.sh` as a JSON file.
This file contains hidden or 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
#!/usr/bin/env bash | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
--network) | |
network="$2" | |
shift | |
;; | |
--address) | |
address="$2" | |
shift | |
;; | |
--nonce) | |
nonce="$2" | |
shift | |
;; | |
*) | |
echo "Unknown parameter: $1" | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
result="result.json" | |
./safe_hashes.sh --network "$network" --address "$address" --nonce "$nonce" >result.txt | |
readonly NETWORK=$(grep "Network:" result.txt | awk '{print $2}') | |
readonly CHAIN_ID=$(grep "Chain ID:" result.txt | awk '{print $3}') | |
readonly MULTISIG=$(grep "Multisig address:" result.txt | awk '{print $3}') | |
readonly TO=$(grep "To:" result.txt | awk '{print $2}') | |
readonly VALUE=$(grep "Value:" result.txt | awk '{print $2}') | |
readonly DATA=$(grep "^Data:" result.txt | awk '{print $2}') | |
readonly OPERATION=$(grep "Operation:" result.txt | awk '{print $2}') | |
readonly SAFE_GAS=$(grep "Safe Transaction Gas:" result.txt | awk '{print $4}') | |
readonly BASE_GAS=$(grep "Base Gas:" result.txt | awk '{print $3}') | |
readonly GAS_PRICE=$(grep "Gas Price:" result.txt | awk '{print $3}') | |
readonly GAS_TOKEN=$(grep "Gas Token:" result.txt | awk '{print $3}') | |
readonly REFUND_RECEIVER=$(grep "Refund Receiver:" result.txt | awk '{print $3}') | |
readonly NONCE=$(grep "Nonce:" result.txt | awk '{print $2}') | |
readonly ENCODED_MESSAGE=$(grep "Encoded message:" result.txt | awk '{print $3}') | |
readonly METHOD=$(grep "Method:" result.txt | awk '{print $2}') | |
readonly DOMAIN_HASH=$(grep "Domain hash:" result.txt | awk '{print $3}') | |
readonly MESSAGE_HASH=$(grep "Message hash:" result.txt | awk '{print $3}') | |
readonly SAFE_HASH=$(grep "Safe transaction hash:" result.txt | awk '{print $4}') | |
cat <<EOF >$result | |
{ | |
"network": "$NETWORK", | |
"chain_id": $CHAIN_ID, | |
"transaction_data": { | |
"multisig_address": "$MULTISIG", | |
"to": "$TO", | |
"value": $VALUE, | |
"data": "$DATA", | |
"operation": "$OPERATION", | |
"safe_transaction_gas": $SAFE_GAS, | |
"base_gas": $BASE_GAS, | |
"gas_price": $GAS_PRICE, | |
"gas_token": "$GAS_TOKEN", | |
"refund_receiver": "$REFUND_RECEIVER", | |
"nonce": $NONCE, | |
"encoded_message": "$ENCODED_MESSAGE", | |
"method": "$METHOD" | |
}, | |
"hashes": { | |
"domain_hash": "$DOMAIN_HASH", | |
"message_hash": "$MESSAGE_HASH", | |
"safe_transaction_hash": "$SAFE_HASH" | |
} | |
} | |
EOF | |
rm result.txt | |
echo "JSON output saved to $result" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
will save a
JSON
file calledresult.json
with the following content: