1- # Soroban CLI
1+ # API and CLI for Soroban contracts in Python
22
3- CLI and functions to call Soroban contracts with Python.
3+ This package provide tools to interact with Soroban contracts in Python. The
4+ goal is to provide a simple feature set while not depending on the Rust SDK.
5+ This can be useful in environment where Rust and the SDK might be more
6+ difficult to get working (like a Raspberry Pi).
7+
8+ ## Getting started
49
510```
611pip install soroban
@@ -12,17 +17,106 @@ Rust SDK and is a higher level interface compared to using the Python SDK.
1217``` python
1318import soroban
1419
15- soroban.invoke(" AAAA..." , " increment" )
20+ soroban.invoke(contract_id = " AAAA..." , function_name = " increment" )
1621```
1722
1823Identity and Network configurations are automatically pulled from the global
1924or local configuration.
2025
2126It also provides a CLI
22- ``` bash
23- soroban invoke CC22IAGPHR4DXI73WSI4L65TTB3F5A2DF7FP5PPNIOLVX5NQWSVR4TID version --source-account=...
27+ ``` shell
28+ soroban invoke C... version --source-account=...
2429```
2530
26- > Note: this repository has no affiliation with the Stellar Developer Foundation.
27- > The official CLI can be found here https://github.com/stellar/soroban-cli
28- > Should this become useful, I am happy to transfer it as well!
31+ ## Usage
32+
33+ The main feature is to be able to call a Soroban contract function: ` soroban.invoke ` .
34+
35+ ``` python
36+ import soroban
37+
38+ soroban.invoke(contract_id = " AAAA..." , function_name = " increment" )
39+ ```
40+
41+ It also supports passing arguments as a list of ` stellar_sdk.SCVal ` . This list
42+ can be easily generated
43+
44+ ``` python
45+ import json
46+ import soroban
47+
48+ args = json.load(... )
49+ args = soroban.Parameters(args = args).model_dump()
50+ soroban.invoke(contract_id = " AAAA..." , function_name = " init" , args = args)
51+ ```
52+
53+ The following JSON syntax is supported. Note that vectors are also supported:
54+ ``` json
55+ [
56+ {
57+ "name" : " issuer" ,
58+ "type" : " address" ,
59+ "value" : " C..."
60+ },
61+ {
62+ "name" : " distributor" ,
63+ "type" : " int128" ,
64+ "value" : 10
65+ },
66+ {
67+ "name" : " claimants" ,
68+ "type" : " vec" ,
69+ "value" : [
70+ {
71+ "type" : " uint32" ,
72+ "value" : 12
73+ },
74+ {
75+ "type" : " int64" ,
76+ "value" : 20
77+ }
78+ ]
79+ }
80+ ]
81+ ```
82+
83+ A few helper functions are also provided:
84+
85+ - ` soroban.create_account ` : create and fund an account from a source account;
86+ - ` soroban.create_asset ` : create an asset using the classical issuer/distributor model.
87+
88+ ## Configuration
89+
90+ The source account and the network to use are set by instantiating ` soroban.Identity `
91+ and ` soroban.NetworkConfig ` , respectively:
92+
93+ ``` python
94+ import soroban
95+
96+ identity = soroban.Identity()
97+ network = soroban.NetworkConfig()
98+ ```
99+
100+ In both cases, the configuration can be set by either adjusting init arguments,
101+ setting up environment variables or using configuration files in toml.
102+
103+ The default path for ` soroban.Identity ` is ` identity.toml ` and for ` soroban.NetworkConfig ` it
104+ is ` testnet.toml ` . Here are examples of these files:
105+
106+ ``` toml
107+ secret_key = " S..."
108+ ```
109+
110+ ``` toml
111+ horizon_url = " https://horizon-testnet.stellar.org"
112+ rpc_url = " https://soroban-testnet.stellar.org"
113+ network_passphrase = " Test SDF Network ; September 2015"
114+ ```
115+
116+ Any of these fields can be set as an environment variable.
117+
118+ ## Acknowledgements
119+
120+ This repository has no affiliation with the Stellar Developer Foundation.
121+ The official CLI can be found here https://github.com/stellar/soroban-cli
122+ Should this become useful, I am happy to transfer it as well to the SDF org!
0 commit comments