Created
June 2, 2021 07:33
-
-
Save tzhenghao/2f86e4d0a41d2bfedb1cd02943d644fd to your computer and use it in GitHub Desktop.
A Python script that creates a SOL stake account and delegates it to a given validator
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
"""A Python script that creates a SOL stake account and delegates it to a given validator""" | |
import subprocess | |
LEDGER_PRIVATE_ADDR = "usb://ledger" | |
def main(): | |
stake_account_json_file = input( | |
"Please enter the name for this new stake account: " | |
) | |
stake_account_json_file = "{}.json".format(stake_account_json_file) | |
print("Creating stake account with name: {}".format(stake_account_json_file)) | |
result = subprocess.run( | |
[ | |
"solana-keygen", | |
"new", | |
"--no-passphrase", | |
"-o", | |
stake_account_json_file, | |
] | |
) | |
amount = input("How many SOLs do you want to stake? ") | |
print("Creating stake account with {} SOL".format(amount)) | |
result = subprocess.run( | |
[ | |
"solana", | |
"create-stake-account", | |
stake_account_json_file, | |
amount, | |
"--from", | |
LEDGER_PRIVATE_ADDR, | |
"--stake-authority", | |
LEDGER_PRIVATE_ADDR, | |
"--withdraw-authority", | |
LEDGER_PRIVATE_ADDR, | |
"--fee-payer", | |
LEDGER_PRIVATE_ADDR, | |
] | |
) | |
validator_account_addr = input( | |
"Please enter the SOL validator address you plan to stake with: " | |
) | |
print("Staking account with validator address: {}".format(validator_account_addr)) | |
result = subprocess.run( | |
[ | |
"solana", | |
"delegate-stake", | |
stake_account_json_file, | |
validator_account_addr, | |
"--stake-authority", | |
LEDGER_PRIVATE_ADDR, | |
"--fee-payer", | |
LEDGER_PRIVATE_ADDR, | |
] | |
) | |
print("Done!") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment