Usage
Install:
pip3 install pypact-lang
note: secrets used in this example is for demo purpose only
Make pact expression:
from pypact.pact import Pact
pact = Pact()
# without namespace
print(pact.lang.mk_exp(module_and_function="coin.details",
account="k:10375651f1ca0110468152bb8f47b7b8a469e36dfab1c83adf60cab84b5726d3"))
# with namespace
print(pact.lang.mk_exp(module_and_function="flux.get-balance", namespace="runonflux",
account="k:10375651f1ca0110468152bb8f47b7b8a469e36dfab1c83adf60cab84b5726d3"))
Make caps:
from pypact.pact import Pact
pact = Pact()
cap = pact.lang.mk_cap("Coin Transfer", "Capability to transfer designated amount of coin from sender to receiver",
"coin.TRANSFER", ["sender_account", "receiver_account", 10.0])
print(cap)
Listen:
from pypact.pact import Pact
pact = Pact()
print(pact.fetch.listen({"listen": "bTRFmTts8VVNGMVvzKfztoTFwVSrCAiTgakH-PG_LLI"}, "https://kadena2.app.runonflux.io/chainweb/0.0/mainnet01/chain/1/pact"))
Poll:
from pypact.pact import Pact
api_host = "https://kadena2.app.runonflux.io/chainweb/0.0/mainnet01/chain/1/pact"
pact = Pact()
print(pact.fetch.poll({"requestKeys": ["bTRFmTts8VVNGMVvzKfztoTFwVSrCAiTgakH-PG_LLI"]}, api_host))
Generate keypair:
from pypact.pact import Pact
pact = Pact()
key_pair = pact.crypto.gen_key_pair()
print(key_pair)
Restore public key from secret key:
from pypact.pact import Pact
pact = Pact()
key_pair = pact.crypto.restore_key_from_secret("18d3a823139cf60cab0b738e7605bb9e4a2f3ff245c270fa55d197f9b3c4c004")
print(key_pair)
Sign:
from pypact.pact import Pact
pact = Pact()
key_pair = {'publicKey': '10375651f1ca0110468152bb8f47b7b8a469e36dfab1c83adf60cab84b5726d3', 'secretKey': '18d3a823139cf60cab0b738e7605bb9e4a2f3ff245c270fa55d197f9b3c4c004'}
sig = pact.crypto.sign("message to be signed", key_pair)
print(sig)
Verify:
from pypact.pact import Pact
pact = Pact()
result = pact.verify("message", "public key", "signature")
print(result)
Local Read:
from pypact.pact import Pact
import time
from datetime import datetime
api_host = "https://kadena2.app.runonflux.io/chainweb/0.0/mainnet01/chain/1/pact"
pact = Pact()
cmd = {
"pactCode": '(coin.details "k:99cb7008d7d70c94f138cc366a825f0d9c83a8a2f4ba82c86c666e0ab6fecf3a")',
"envData": {},
"meta": pact.lang.mk_meta("not real", chain_id="1", gas_price=0.0000001, gas_limit=60000,
creation_time=time.time().__round__(), ttl=5000),
"networkId": "mainnet01",
"nonce": datetime.now().isoformat(),
"keyPairs": []
}
result = pact.fetch.local(cmd, api_host)
print(result)
Make transaction:
from pypact.pact import Pact
import time
from datetime import datetime
test_net = "https://api.testnet.chainweb.com/chainweb/0.0/testnet04/chain/1/pact"
pact = Pact()
amount = 10.0
key_pair = {'publicKey': '10375651f1ca0110468152bb8f47b7b8a469e36dfab1c83adf60cab84b5726d3',
'secretKey': '18d3a823139cf60cab0b738e7605bb9e4a2f3ff245c270fa55d197f9b3c4c004',
'clist': [{'name': 'coin.GAS', 'args': []},
{"name": "coin.TRANSFER",
'args': ['k:10375651f1ca0110468152bb8f47b7b8a469e36dfab1c83adf60cab84b5726d3',
'k:03df480e0b300c52901fdff265f0460913fea495f39972321698740536cc38e3', amount]}]}
cmd = {
"pactCode": '(coin.transfer-create "k:10375651f1ca0110468152bb8f47b7b8a469e36dfab1c83adf60cab84b5726d3" "k:03df480e0b300c52901fdff265f0460913fea495f39972321698740536cc38e3" (read-keyset "ks") 10.0)',
"envData": {
"ks": {
"pred": "keys-all",
"keys": ["03df480e0b300c52901fdff265f0460913fea495f39972321698740536cc38e3"]
}
},
"meta": pact.lang.mk_meta("k:"+key_pair.get('publicKey'), chain_id="1", gas_price=0.0000001, gas_limit=60000,
creation_time=time.time().__round__()-100, ttl=15000),
"networkId": "testnet04",
"nonce": datetime.now().isoformat(),
"keyPairs": [key_pair]
}
result = pact.fetch.send(cmd, test_net)
print(result)
tools token transfer example:
from pypact import tools
key_pair = {'publicKey': '10375651f1ca0110468152bb8f47b7b8a469e36dfab1c83adf60cab84b5726d3',
'secretKey': '18d3a823139cf60cab0b738e7605bb9e4a2f3ff245c270fa55d197f9b3c4c004',
}
result = tools.token_transfer("coin", "k:10375651f1ca0110468152bb8f47b7b8a469e36dfab1c83adf60cab84b5726d3",
"k:03df480e0b300c52901fdff265f0460913fea495f39972321698740536cc38e3",
"03df480e0b300c52901fdff265f0460913fea495f39972321698740536cc38e3", 2.0, key_pair, "1",
"testnet04")
print(result)
Metadata
Release files for pypact-lang 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypact-lang-0.3.5.tar.gz | 7.1 kB | Without provenance | Details for pypact-lang-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypact_lang-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for pypact_lang-0.3.5-py3-none-any.whl |
Total release size: 14.1 kB
Release files / pypact-lang-0.3.5.tar.gz
| Download URL | pypact-lang-0.3.5.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31dc0e932c98c3e5be1957f6aadde0e8481f43f5e65555a07ec6aced2c22678a
|
|
BLAKE2b-256 checksum How to use checksums |
c4330f8da94aaf501aa4002ca3f7732fac2161d7227ef6803eb09c32275cc30d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.9
|
Release files / pypact_lang-0.3.5-py3-none-any.whl
| Download URL | pypact_lang-0.3.5-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28a1a8de6d5b9382141e25e3d049c4a5a2c9385803d3f0e39bdc657d7ea6ed2c
|
|
BLAKE2b-256 checksum How to use checksums |
40ab877b0635e9e2664a84f0d8cc045c0b50e6508e46518a10b3d4f766d99a13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.9
|
Security for pypact-lang 0.3.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.