🥭 Mango Markets support is available at: Docs | Discord | Twitter | Github | Email
Run this code on Binder.
🏃♀️ To run this notebook press the ⏩ icon in the toolbar above.
This code will connect to the devnet cluster and deposit 0.1 SOL into a Mango Account
.
import decimal
import mango
from solana.publickey import PublicKey
# Use our hard-coded devnet wallet for DeekipCw5jz7UgQbtUbHQckTYGKXWaPQV4xY93DaiM6h.
# For real-world use you'd load the bytes from the environment or a file. This wallet
# has a Mango Account at HhepjyhSzvVP7kivdgJH9bj32tZFncqKUwWidS1ja4xL.
wallet = mango.Wallet(bytes([67,218,68,118,140,171,228,222,8,29,48,61,255,114,49,226,239,89,151,110,29,136,149,118,97,189,163,8,23,88,246,35,187,241,107,226,47,155,40,162,3,222,98,203,176,230,34,49,45,8,253,77,136,241,34,4,80,227,234,174,103,11,124,146]))
with mango.ContextBuilder.build(cluster_name="devnet") as context:
group = mango.Group.load(context)
account = mango.Account.load(context, PublicKey("HhepjyhSzvVP7kivdgJH9bj32tZFncqKUwWidS1ja4xL"), group)
sol_token = mango.token(context, "SOL")
print("Wrapped SOL in account", account.slot_by_instrument(sol_token).net_value)
deposit_value = mango.InstrumentValue(sol_token, decimal.Decimal("0.1"))
deposit_signatures = account.deposit(context, wallet, deposit_value)
print("Waiting for deposit transaction to confirm...", deposit_signatures)
mango.WebSocketTransactionMonitor.wait_for_all(
context.client.cluster_ws_url, deposit_signatures, commitment="processed"
)
account = mango.Account.load(context, account.address, group)
print("Wrapped SOL after deposit", account.slot_by_instrument(sol_token).net_value)
print("Example complete.")