Skip to content

Commit 7ef67a3

Browse files
committed
Update Readme
1 parent ab5d5f8 commit 7ef67a3

3 files changed

Lines changed: 107 additions & 11 deletions

File tree

README.md

Lines changed: 102 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
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
```
611
pip install soroban
@@ -12,17 +17,106 @@ Rust SDK and is a higher level interface compared to using the Python SDK.
1217
```python
1318
import soroban
1419

15-
soroban.invoke("AAAA...", "increment")
20+
soroban.invoke(contract_id="AAAA...", function_name="increment")
1621
```
1722

1823
Identity and Network configurations are automatically pulled from the global
1924
or local configuration.
2025

2126
It 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!

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ build-backend = "hatchling.build"
55
[project]
66
name = "soroban"
77
dynamic = ["version"]
8-
description = "CLI for Soroban contracts in Python"
8+
description = "API and CLI for Soroban contracts in Python"
99
readme = "README.md"
1010
requires-python = ">=3.11"
1111
license = "BSD-3-Clause"
1212
authors = [
1313
{ name = "Pamphile Roy" },
1414
]
1515
maintainers = [
16-
{ name = "Soroban CLI contributors" },
16+
{ name = "Soroban API/CLI contributors" },
1717
]
1818

1919
keywords = [

tests/test_create.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from decimal import Decimal
2+
13
import pytest
24

35
import soroban
@@ -14,4 +16,4 @@ def test_create_account():
1416
def test_create_asset():
1517
source_account = "SDEUQZ7PMHT7VDP3TYZMBKUVES3W6CTXT5L2ZR5NROWQJIDE4QFUXW6Q"
1618

17-
soroban.create_account(name="BOB", source_account=source_account)
19+
soroban.create_asset(name="BOBI", mint=Decimal(10), source_account=source_account)

0 commit comments

Comments
 (0)