Skip to content

Instantly share code, notes, and snippets.

@overcat
Created March 1, 2023 11:12
Show Gist options
  • Save overcat/f0be1d87a18caa22d5b48a3c9394d349 to your computer and use it in GitHub Desktop.
Save overcat/f0be1d87a18caa22d5b48a3c9394d349 to your computer and use it in GitHub Desktop.
"""
pip install git+https://github.com/StellarCN/py-stellar-base.git@soroban
"""
import binascii
from stellar_sdk import xdr as stellar_xdr
from stellar_sdk.soroban import SorobanServer
from stellar_sdk.soroban.exceptions import RequestException
rpc_server_url = "https://horizon-futurenet.stellar.cash:443/soroban/rpc"
soroban_server = SorobanServer(rpc_server_url)
def check_contract_deployed(contract_id) -> bool:
contract_id_bytes = binascii.unhexlify(contract_id)
ledger_key = stellar_xdr.LedgerKey(
type=stellar_xdr.LedgerEntryType.CONTRACT_DATA,
contract_data=stellar_xdr.LedgerKeyContractData(
contract_id=stellar_xdr.Hash(contract_id_bytes),
key=stellar_xdr.SCVal(
type=stellar_xdr.SCValType.SCV_STATIC,
ic=stellar_xdr.SCStatic.SCS_LEDGER_KEY_CONTRACT_CODE
)
),
)
try:
soroban_server.get_ledger_entry(ledger_key)
return True
except RequestException:
return False
if __name__ == '__main__':
contract_id = "8542841a633aafc771f07bc472b7a799fa2e82cced417356505f569daaaedc47"
print("contract deployed?", check_contract_deployed(contract_id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment