/bera_bgt.sh Secret
Last active
February 9, 2025 02:22
Berachain Reward Distribution
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
# Set RPC URL for bartio | |
export ETH_RPC_URL="https://bartio.rpc.berachain.com" | |
# Set contract address (this is a dummy demo contract - change to the network equivalent) | |
CONTRACT="0xe7a54F63f45796fBE066474A582A137c67696a6f" | |
# Get recent finalized block's number from Exec Layer -> Get timestamp of its parent block | |
# Example: 1730756547 | |
cast block finalized | |
TARGET_BLOCK=`cast block finalized|grep number|awk '{print $2}'` | |
PARENT_BLOCK=`expr $TARGET_BLOCK + 1` | |
echo "$TARGET_BLOCK / $PARENT_BLOCK" | |
cast block $PARENT_BLOCK | |
# Get the next timestamp - we will generate the rewards by referencing the parent block | |
# NOTE: Each second identifies a specific block - there are no two blocks with the same timestamp. | |
# In this example, we will use the timestamp from above. You can also use any other timestamp in the past 8191 blocks. | |
TIMESTAMP=`cast block $PARENT_BLOCK|grep timestamp|awk '{print $2}'` | |
# Sanity check - isTimestampActionable? Returns true if rewards have not yet been distributed for this block. | |
cast call "$CONTRACT" "isTimestampActionable(uint64 timestamp) returns (bool success)" "$TIMESTAMP" | |
# Generate proof and extract attributes for contract call | |
# Example: | |
# {"beacon_block_header":{"slot":"0x6a929b","proposer_index":"0x3b","parent_block_root":"0x082ef694 … | |
PROOF_JSON=`curl http://beacond-host:3500/bkit/v1/proof/block_proposer/t$TIMESTAMP` | |
echo $PROOF_JSON|jq | |
# Parse values required for reward dist tx. There are four required attributes | |
# The host will be your respective local beacond instance, or any public beacond node permitting API calls. | |
PROOF_JSON=`curl http://beacond-host:3500/bkit/v1/proof/block_proposer/t$TIMESTAMP` | |
proposer_index=`echo $PROOF_JSON|jq -r '.beacon_block_header.proposer_index'` | |
pubkey=`echo $PROOF_JSON|jq -r '.validator_pubkey'` | |
proposer_proof=`echo $PROOF_JSON|jq -j '.proposer_index_proof'|sed 's/"//g'|tr -d '\\n'` | |
val_pubkey_proof=`echo $PROOF_JSON|jq -j '.validator_pubkey_proof'|sed 's/"//g'|tr -d '\\n'` | |
echo "Proposer Idx: $proposer_index" | |
echo "Val Public Key: $pubkey" | |
echo "Proposer Proof: $proposer_proof" | |
echo "Validator Pubkey Proof: $val_pubkey_proof" | |
# Execute tx after setting PK of wallet sending tx (or use --ledger if not using raw PK) | |
# Example: Transaction successfully executed. Gas used: 104467 | |
PK=`cat privatekey.txt` | |
cast send "$CONTRACT" "distributeFor(uint64 nextTimestamp, uint64 proposerIndex, bytes calldata pubkey, bytes32[] calldata proposerIndexProof, bytes32[] calldata pubkeyProof)" "$TIMESTAMP" "$proposer_index" "$pubkey" "$proposer_proof" "$val_pubkey_proof" --private-key $PK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment