-
-
Save 0xBXIII/682df7c45068ca08153a26fa2d18d1eb to your computer and use it in GitHub Desktop.
SPS Auto Compounder script for Splinterlands
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
beem | |
cryptography | |
requests |
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
from beem import Hive | |
from beem.account import Account | |
from time import sleep | |
from datetime import datetime | |
import requests | |
import os | |
# Read posting key and hive account from environment variables | |
posting_key = os.environ['POSTING_KEY'] | |
hive_account = os.environ['HIVE_ACCOUNT'] | |
# These can be modified as you see fit, you might have a preferred node to use | |
APP_NAME = 'sps-autocompounder-v0.1' | |
NODE = 'https://api.hive.blog' | |
# Wallet Setup | |
hive = Hive(keys=[posting_key],node=NODE ) | |
account = Account(hive_account, blockchain_instance=hive) | |
# Infinite loop, rough - will likely re-write this for cron based execution in a Docker image | |
while True: | |
# Find how much SPS is claimable | |
# This does NOT include airdrops | |
balances = requests.get(f'https://api.splinterlands.io/players/balances?username={hive_account}').json() | |
sps = 0 # Defaulting to 0 to claim only | |
for balance in balances: | |
if balance['token'] == 'SPS': | |
sps = balance['balance'] | |
break | |
# Execute transaction | |
hive.custom_json("sm_stake_tokens", required_posting_auths=[hive_account], | |
json_data=f"{{\"token\":\"SPS\",\"qty\":{sps},\"app\":\"{APP_NAME}\"}}") | |
# Log amount staked | |
timestamp = datetime.now() | |
print(str(timestamp) + ' | Staked ' + str(sps)) | |
# Wait ~15 minutes | |
# Technically, you could run this every minute or every 5 minutes | |
# It does impact your RC balance though, 15 minutes with enough Hive | |
# showed little to no practical impact for my usage | |
sleep(900) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment