Stader
Prerequisites
Install the required packages:
pip install web3
pip install eth_account
Set up environment variables:
export PRIVATE_KEY=<YourPrivateKey>
export RPC_URL=<YourEthereumNodeURL>
export NODE_OPERATOR_CONTRACT_ADDRESS=<StaderNodeOperatorContractAddress>
1. Node Registration
from web3 import Web3
import os
# Load environment variables
private_key = os.getenv("PRIVATE_KEY")
rpc_url = os.getenv("RPC_URL")
contract_address = os.getenv("NODE_OPERATOR_CONTRACT_ADDRESS")
# Connect to Ethereum node
web3 = Web3(Web3.HTTPProvider(rpc_url))
# ABI for Node Operator Contract (replace with your contract's ABI)
contract_abi = '[{"constant":false,"inputs":[{"name":"_operatorId","type":"uint256"}],"name":"registerNodeOperator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]'
# Initialize contract
contract = web3.eth.contract(address=contract_address, abi=contract_abi)
# Create transaction to register node operator
tx = contract.functions.registerNodeOperator(operator_id).buildTransaction({
'chainId': 1,
'gas': 3000000,
'gasPrice': web3.toWei('100', 'gwei'),
'nonce': web3.eth.getTransactionCount(web3.eth.account.privateKeyToAccount(private_key).address)
})
# Sign and send the transaction
signed_tx = web3.eth.account.signTransaction(tx, private_key=private_key)
tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction)
print(f"Node Registration Transaction Hash: {web3.toHex(tx_hash)}")
2. Adding Validators
# ABI for Validator Management Contract (replace with your contract's ABI)
validator_contract_abi = '[{"constant":false,"inputs":[{"name":"_validatorPubKey","type":"bytes"},{"name":"_depositDataRoot","type":"bytes32"}],"name":"addValidator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]'
# Initialize contract for validator management
validator_contract_address = "<ValidatorContractAddress>"
validator_contract = web3.eth.contract(address=validator_contract_address, abi=validator_contract_abi)
# Validator data
validator_pub_key = b'\x00' * 48 # Replace with actual validator public key
deposit_data_root = b'\x00' * 32 # Replace with actual deposit data root
# Build transaction to add a validator
tx_add_validator = validator_contract.functions.addValidator(validator_pub_key, deposit_data_root).buildTransaction({
'chainId': 1,
'gas': 3000000,
'gasPrice': web3.toWei('100', 'gwei'),
'nonce': web3.eth.getTransactionCount(web3.eth.account.privateKeyToAccount(private_key).address)
})
# Sign and send the transaction
signed_add_validator_tx = web3.eth.account.signTransaction(tx_add_validator, private_key=private_key)
add_validator_tx_hash = web3.eth.sendRawTransaction(signed_add_validator_tx.rawTransaction)
print(f"Add Validator Transaction Hash: {web3.toHex(add_validator_tx_hash)}")
Additional Considerations:
Replace the ABI strings with the actual ABI of your contracts.
Customize
gasPrice
andgas
as needed.Ensure that you have sufficient ETH balance to cover gas fees.
Last updated