|
| 1 | +""" |
| 2 | +Challenge 1: Create a Stellar Account |
| 3 | +""" |
| 4 | +from stellar_sdk import Server, Keypair, TransactionBuilder, Network |
| 5 | +import requests |
| 6 | + |
| 7 | +# 1. Load Keys |
| 8 | +server = Server("https://horizon-testnet.stellar.org") |
| 9 | +stellar_quest_keypair = Keypair.from_secret("Shhhhh") |
| 10 | +quest_account_pub_key = stellar_quest_keypair.public_key |
| 11 | +quest_account_priv_key = stellar_quest_keypair.secret |
| 12 | + |
| 13 | +# 2. Create Another account |
| 14 | +print("Loading Accounts...") |
| 15 | + |
| 16 | +random_keypair = Keypair.random() |
| 17 | +random_keypair_pub_key = random_keypair.public_key |
| 18 | +random_keypair_priv_key = random_keypair.secret |
| 19 | + |
| 20 | +# 3. Fund Another account using TestBot |
| 21 | +print("Funding Random Account...") |
| 22 | + |
| 23 | +url = 'https://friendbot.stellar.org' |
| 24 | +response = requests.get(url, params={'addr': quest_account_pub_key}) |
| 25 | +print(f"Friendbot responded with {response}") |
| 26 | + |
| 27 | + |
| 28 | +# 4. Use said account to fund my account |
| 29 | +print("Building Transaction...") |
| 30 | + |
| 31 | +base_fee = server.fetch_base_fee() |
| 32 | +account = server.load_account(quest_account_pub_key) |
| 33 | + |
| 34 | +transaction = ( |
| 35 | + TransactionBuilder( |
| 36 | + source_account=account, |
| 37 | + network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, |
| 38 | + base_fee=base_fee, |
| 39 | + ) |
| 40 | + .append_create_account_op( |
| 41 | + destination=random_keypair_pub_key, |
| 42 | + starting_balance="1000", |
| 43 | + ) |
| 44 | + .build() |
| 45 | +) |
| 46 | +print('Signing Transaction...') |
| 47 | +transaction.sign(stellar_quest_keypair) |
| 48 | +response = server.submit_transaction(transaction) |
| 49 | + |
| 50 | +print(f"This is the final response: {response}") |
| 51 | + |
0 commit comments