Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Learn-Level-1/Challenge-2/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Challenge 2: Pay a Stellar Account
"""
from stellar_sdk import Asset, Server, Keypair, TransactionBuilder, Network
import requests

# 1. Load Keys
server = Server("https://horizon-testnet.stellar.org")
stellar_quest_keypair = Keypair.from_secret("Secret")
quest_account_pub_key = stellar_quest_keypair.public_key
quest_account_priv_key = stellar_quest_keypair.secret

# 2. Create Another account
print("Loading Accounts...")

random_keypair = Keypair.random()
random_keypair_pub_key = random_keypair.public_key
random_keypair_priv_key = random_keypair.secret

# 3. Fund Another account using TestBot
print("Funding Random Account...")

url = 'https://friendbot.stellar.org'
response = requests.get(url, params={'addr': random_keypair.public_key})
print(f"Friendbot responded with {response}")


# 4. Payment
print("Building Transaction...")

base_fee = server.fetch_base_fee()
stellar_account = server.load_account(quest_account_pub_key)

transaction = (
TransactionBuilder(
source_account=stellar_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=base_fee,
)
.append_payment_op(
random_keypair_pub_key,
Asset.native(),
"10"
)
.set_timeout(30)
.build()
)
print('Signing Transaction...')
transaction.sign(quest_account_priv_key)
response = server.submit_transaction(transaction)

print(f"This is the final response: {response}")
47 changes: 47 additions & 0 deletions Learn-Level-1/Challenge-3/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Challenge 3: Change Trust
"""
from stellar_sdk import Asset, Server, Keypair, TransactionBuilder, Network
import requests

# 1. Load Keys
server = Server("https://horizon-testnet.stellar.org")
stellar_quest_keypair = Keypair.from_secret("SECRET")
quest_account_pub_key = stellar_quest_keypair.public_key
quest_account_priv_key = stellar_quest_keypair.secret

# 2. Random key and asset
random_keypair = Keypair.random()
random_keypair_pub_key = random_keypair.public_key
random_keypair_priv_key = random_keypair.secret

url = 'https://friendbot.stellar.org'
response = requests.get(url, params={'addr': random_keypair.public_key})
asset_quest = Asset("BRLT", random_keypair_pub_key)
print(asset_quest)

# 3. Transaction
print("Building Transaction...")

base_fee = server.fetch_base_fee()
stellar_account = server.load_account(quest_account_pub_key)

transaction = (
TransactionBuilder(
source_account=stellar_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=base_fee,
)
.append_change_trust_op(
asset=asset_quest
)
.set_timeout(30)
.build()
)

print('Signing Transaction...')
transaction.sign(quest_account_priv_key)
response = server.submit_transaction(transaction)

print(f"This is the response from trusting the Issuer: {response}")

41 changes: 41 additions & 0 deletions Learn-Level-1/Challenge-4/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Challenge 4: Manage Offers
"""
from stellar_sdk import Asset, Server, Keypair, TransactionBuilder, Network
import requests

# 1. Load Keys
server = Server("https://horizon-testnet.stellar.org")
stellar_quest_keypair = Keypair.from_secret("SECRET")
quest_account_pub_key = stellar_quest_keypair.public_key
quest_account_priv_key = stellar_quest_keypair.secret

# 2. Random asset
asset_quest = Asset("BRLT", quest_account_pub_key)
print(asset_quest)

# 3. Transaction

print("Building Transaction...")

base_fee = server.fetch_base_fee()
stellar_account = server.load_account(quest_account_pub_key)

transaction = (
TransactionBuilder(
source_account=stellar_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=base_fee,
)
.append_manage_sell_offer_op(
selling=asset_quest, buying=Asset.native(), amount="10", price="0.5"
)
.set_timeout(30)
.build()
)

print('Signing Transaction...')
transaction.sign(quest_account_priv_key)
response = server.submit_transaction(transaction)

print(f"This is the response from selling the token: {response}")
50 changes: 50 additions & 0 deletions Learn-Level-1/Challenge-5/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Challenge 5: Path Payment
"""
from stellar_sdk import Asset, Server, Keypair, TransactionBuilder, Network
import requests

# 1. Load Keys
server = Server("https://horizon-testnet.stellar.org")
stellar_quest_keypair = Keypair.from_secret("SECRET")
quest_account_pub_key = stellar_quest_keypair.public_key
quest_account_priv_key = stellar_quest_keypair.secret

# 2. Path
path = [
Asset("USDT", "GDMUX3LEQ2HBJDMHTYNSR23YC3JZWTWY63KRMZ7B4Z5II6X5BGB73UWS"),
Asset("BTC", "GDMUX3LEQ2HBJDMHTYNSR23YC3JZWTWY63KRMZ7B4Z5II6X5BGB73UWS"),
]

# 3. Transaction

print("Building Transaction...")

base_fee = server.fetch_base_fee()
stellar_account = server.load_account(quest_account_pub_key)
print('IF IT FAILS CHECK THE TESTNET ORDERBOOK AND CHANGE DEST ASSET')
transaction = (
TransactionBuilder(
source_account=stellar_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=base_fee,
)
.append_path_payment_strict_receive_op(
destination="GDMUX3LEQ2HBJDMHTYNSR23YC3JZWTWY63KRMZ7B4Z5II6X5BGB73UWS",
send_asset=Asset.native(),
send_max="1000",
dest_asset=Asset(
"1INCH", "GDMUX3LEQ2HBJDMHTYNSR23YC3JZWTWY63KRMZ7B4Z5II6X5BGB73UWS"
),
dest_amount=".1",
path=path,
)
.set_timeout(30)
.build()
)

print('Signing Transaction...')
transaction.sign(quest_account_priv_key)
response = server.submit_transaction(transaction)

print(f"This is the response from selling the token: {response}")
Loading