Skip to content

Instantly share code, notes, and snippets.

@tzhenghao
Created June 2, 2021 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzhenghao/2f86e4d0a41d2bfedb1cd02943d644fd to your computer and use it in GitHub Desktop.
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
"""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