Skip to content

Instantly share code, notes, and snippets.

@pcaversaccio
Last active April 30, 2025 18:58
Show Gist options
  • Save pcaversaccio/621142f38232f1ca28d11fa180d632a0 to your computer and use it in GitHub Desktop.
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.
#!/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"
@pcaversaccio
Copy link
Author

pcaversaccio commented Apr 1, 2025

Example

./jsonify.sh --network arbitrum --address 0x111CEEee040739fD91D29C34C33E6B3E112F2177 --nonce 234

will save a JSON file called result.json with the following content:

{
  "network": "arbitrum",
  "chain_id": 42161,
  "transaction_data": {
    "multisig_address": "0x111CEEee040739fD91D29C34C33E6B3E112F2177",
    "to": "0x111CEEee040739fD91D29C34C33E6B3E112F2177",
    "value": 0,
    "data": "0x0d582f130000000000000000000000000c75fa5a5f1c0997e3eea425cfa13184ed0ec9e50000000000000000000000000000000000000000000000000000000000000003",
    "operation": "Call",
    "safe_transaction_gas": 0,
    "base_gas": 0,
    "gas_price": 0,
    "gas_token": "0x0000000000000000000000000000000000000000",
    "refund_receiver": "0x0000000000000000000000000000000000000000",
    "nonce": 234,
    "encoded_message": "0xbb8310d486368db6bd6f849402fdd73ad53d316b5a4b2644ad6efe0f941286d8000000000000000000000000111ceeee040739fd91d29c34c33e6b3e112f21770000000000000000000000000000000000000000000000000000000000000000b34f85cea7c4d9f384d502fc86474cd71ff27a674d785ebd23a4387871b8cbfe00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ea",
    "method": "addOwnerWithThreshold"
  },
  "hashes": {
    "domain_hash": "0x1CF7F9B1EFE3BC47FE02FD27C649FEA19E79D66040683A1C86C7490C80BF7291",
    "message_hash": "0xD9109EA63C50ECD3B80B6B27ED5C5A9FD3D546C2169DFB69BFA7BA24CD14C7A5",
    "safe_transaction_hash": "0x0cb7250b8becd7069223c54e2839feaed4cee156363fbfe5dd0a48e75c4e25b3"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment