Skip to content

Commit 9423c2b

Browse files
committed
fix readme
1 parent 95873f0 commit 9423c2b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

readme.md

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
## Python Agent Library for the IC
1+
## Python Agent Library for the Internet Computer
22

33
`ic-py` provides basic modules to interact with canisters on the DFINITY Internet Computer. Its still under active development.
44

5+
### Install
6+
7+
```
8+
pip3 install ic-py
9+
```
10+
511
### Modules & Usage
612

713
#### 1. Principal
814

915
Create an instance:
1016

11-
```js
17+
```python
18+
from ic.principal import Principal
1219
p = Principal() # default is management canister id `aaaaa-aa`
1320
p1 = Principal(bytes=xxx) # create an instance from bytes
1421
p2 = Principal.anonymous() # create anonymous principal
@@ -19,7 +26,7 @@ p5 = Principal.from_hex('xxx') # create an instance from hex
1926

2027
Class methods:
2128

22-
```js
29+
```python
2330
p.bytes # principal bytes
2431
p.len # byte array length
2532
p.to_str() # convert to string
@@ -29,14 +36,15 @@ p.to_str() # convert to string
2936

3037
Create an instance:
3138

32-
```js
39+
```python
40+
from ic.identity import Identity
3341
i = Identity() # create an identity instance, key is randomly generated
3442
i1 = Identity(privkey = "833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42") # create an instance from private key
3543
```
3644

3745
Sign a message:
3846

39-
```js
47+
```python
4048
msg = b”ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f“
4149
sig = i.sign(msg) # sig = (der_encoded_pubkey, signature)
4250
```
@@ -45,23 +53,25 @@ sig = i.sign(msg) # sig = (der_encoded_pubkey, signature)
4553

4654
Create an instance:
4755

48-
```js
56+
```python
57+
from ic.client import Client
4958
client = Client(url = "https://ic0.app")
5059
```
5160

5261
#### 4. Candid
5362

5463
Encode parameters:
5564

56-
```js
65+
```python
66+
from ic.candid import encode, decode
5767
# params is an array, return value is encoded bytes
5868
params = [{'type': Types.Nat, 'value': 10}]
5969
data = encode(params)
6070
```
6171

6272
Decode parameters:
6373

64-
```js
74+
```python
6575
# data is bytes, return value is an parameter array
6676
params = decode(data)
6777
```
@@ -70,7 +80,10 @@ params = decode(data)
7080

7181
Create an instance:
7282

73-
```js
83+
```python
84+
from ic.client import Client
85+
from ic.identity import Identity
86+
from ic.Agent import Agent
7487
# Identity and Client are dependencies of Agent
7588
iden = Identity()
7689
client = Client()
@@ -79,14 +92,14 @@ agent = Agent(iden, client)
7992

8093
Query call:
8194

82-
```js
95+
```python
8396
# query the name of token canister `gvbup-jyaaa-aaaah-qcdwa-cai`
8497
name = agent.query_raw("gvbup-jyaaa-aaaah-qcdwa-cai", "name", encode([]))
8598
```
8699

87100
Update call:
88101

89-
```js
102+
```python
90103
# transfer 100 token to blackhole address `aaaaa-aa`
91104
params = [
92105
{'type': Types.Principal, 'value': 'aaaaa-aa'},

0 commit comments

Comments
 (0)