Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating feat-2.0_docs with changes from dev #1480

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
fa6e104
Bump @babel/traverse in /src/plugins/docusaurus-plugin-cookiesbanner
dependabot[bot] Feb 16, 2024
e8f8cb6
Bump @babel/traverse from 7.22.8 to 7.23.9
dependabot[bot] Feb 16, 2024
97ced11
Bump @babel/traverse in /src/plugins/docusaurus-plugin-navdata
dependabot[bot] Feb 16, 2024
9b7672d
Bump follow-redirects from 1.15.2 to 1.15.5
dependabot[bot] Feb 16, 2024
f092d54
Create dependabot.yml
bradjohnl Feb 16, 2024
68a2e9a
Merge pull request #1387 from casper-network/bradjohnl-patch-1
bradjohnl Feb 16, 2024
7da7869
Merge pull request #1385 from casper-network/dependabot/npm_and_yarn/…
bradjohnl Feb 19, 2024
b8bdea1
Merge pull request #1384 from casper-network/dependabot/npm_and_yarn/…
bradjohnl Feb 19, 2024
2a9d2b6
Merge pull request #1382 from casper-network/dependabot/npm_and_yarn/…
bradjohnl Feb 19, 2024
f3f513f
Merge pull request #1386 from casper-network/dependabot/npm_and_yarn/…
bradjohnl Feb 19, 2024
2ace7cb
Fix incorrect link
ipopescu Mar 1, 2024
be4cdf2
Add the full NFT tutorial from the cep-78 repository
ipopescu Mar 1, 2024
80427ca
Fix links that don't fail locally
ipopescu Mar 6, 2024
10f8b07
add information about switching to bash shell
sczembor Mar 6, 2024
8b0c39b
remove unecesarry sentece
sczembor Mar 6, 2024
ad81360
Apply suggestions from code review
sczembor Mar 6, 2024
b026899
Merge pull request #1407 from sczembor/dev
sczembor Mar 6, 2024
cb260a9
add note about the port; fix wrong path
sczembor Mar 7, 2024
3a29fb3
Merge pull request #1410 from sczembor/testnet_tutorial
sczembor Mar 7, 2024
942acb3
fix directory structure + minor updates
sczembor Mar 8, 2024
9a19f81
Merge pull request #1411 from sczembor/cross-contract
sczembor Mar 8, 2024
9e9d52f
Review feedback and updated TOC
ipopescu Mar 11, 2024
2d1cad8
Merge branch '1299_NFT_tutorial' of https://github.com/ipopescu/docs …
ipopescu Mar 11, 2024
6dbe506
Add missing tag
ipopescu Mar 11, 2024
4c9215d
Add missing entrypoints; essential note; reduce crates intro
ipopescu Mar 12, 2024
c1b6d1f
Merge pull request #1404 from ipopescu/1299_NFT_tutorial
ipopescu Mar 20, 2024
da65a6b
update the dependencies in the code example; update the existing tuto…
sczembor Mar 20, 2024
b094810
cleanup
sczembor Mar 20, 2024
f782b2b
Update interacting-with-NFTs.md
ipopescu Mar 25, 2024
1e4ef57
Fix links and warnings
ipopescu Mar 26, 2024
7caad27
Merge pull request #1420 from casper-network/ipopescu-patch-1
ipopescu Mar 26, 2024
cebd0b3
1. Python SDK page updated.
asladeofgreen Apr 16, 2024
0d1d713
Update create-private.md
ipopescu Apr 16, 2024
a90f97d
Merge pull request #1418 from sczembor/testing_smart_contracts
sczembor Apr 16, 2024
f1d2a56
Merge pull request #1432 from casper-network/ipopescu-patch-1
ipopescu Apr 16, 2024
9e9477b
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
2f7757d
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
83505bd
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
f5fbe3c
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
95cbb6a
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
5bab2ff
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
e91632b
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
20f7e17
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
e1a58f7
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
c8f296f
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
4f30b5a
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
f1b5c53
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
7ea2e78
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
80ccd30
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
c040b5e
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
a45f24b
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
f381943
Update source/docs/casper/developers/dapps/sdk/python-sdk.md
asladeofgreen Apr 18, 2024
2db1a14
Merge pull request #1431 from casper-network/issues/1430
ipopescu Apr 18, 2024
2c084f0
Add details about the secret key file
ipopescu May 3, 2024
9858ff3
Clarify macOS commands & support
ipopescu May 3, 2024
880c4cb
Merge pull request #1441 from ipopescu/1435_add_warning
ipopescu May 3, 2024
eb747da
Merge pull request #1442 from casper-network/ipopescu-patch-1
ipopescu May 3, 2024
fd184f1
Including Condor for Exchanges in Github
ACStone-MTS May 30, 2024
4d79abb
Merge pull request #1453 from ACStoneCL/Exchange_Guide
ACStone-MTS Jun 3, 2024
31c3c19
Adding Quickstart to Navbar
ACStone-MTS Jun 14, 2024
5336db2
Merge pull request #1462 from ACStoneCL/Quickstart_Rising
ACStone-MTS Jun 14, 2024
aa31148
Promote Quickstart in nav bar
melpadden Jun 14, 2024
fdffe67
Merge pull request #1464 from casper-network/feat/promote-quickstart
melpadden Jun 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
commit-message:
prefix: "chore"
include: "scope"

5 changes: 5 additions & 0 deletions config/navbar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ module.exports = {
// label: "Documentation",
// position: "left",
// },
{
to: `${routePrefix}/resources/quick-start`,
label: "Quickstart",
position: "left",
},
{
to: `${routePrefix}/concepts`,
activeBasePath: `${routePrefix}/concepts`,
Expand Down
17 changes: 16 additions & 1 deletion config/sidebar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,22 @@ module.exports = {
},
items: [
"resources/tokens/cep78/modalities",
"resources/tokens/cep78/using-casper-client",
{
type: "category",
label: "On-chain Installation",
collapsible: true,
collapsed: true,
link: {
type: "doc",
id: "resources/tokens/cep78/using-casper-client/quickstart-guide",
},
items: [
"resources/tokens/cep78/using-casper-client/full-installation-tutorial",
"resources/tokens/cep78/using-casper-client/interacting-with-NFTs",
"resources/tokens/cep78/using-casper-client/querying-NFTs",
"resources/tokens/cep78/using-casper-client/testing-NFTs",
],
},
"resources/tokens/cep78/reverse-lookup",
"resources/tokens/cep78/js-tutorial",
],
Expand Down
4 changes: 3 additions & 1 deletion source/docs/casper/concepts/accounts-and-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You can also [generate an account hash](#generating-an-account-hash) from a publ

## Creating Accounts and Keys {#creating-accounts-and-keys}

When you create an account on the Casper blockchain, a cryptographic key-pair will be created when using either the [Casper command-line client](#option-1-key-generation-using-the-casper-client) or a block explorer.
When you create an account on the Casper blockchain, a cryptographic key-pair will be created when using either the [Casper command-line client](#option-1-key-generation-using-the-casper-client) or a block explorer. Developers must use the Casper command-line client as described below. Otherwise, they won't have access to the secret key file needed during development.

:::note

Expand Down Expand Up @@ -105,6 +105,8 @@ Start by creating an account using the [Casper Wallet](https://www.casperwallet.

:::caution

Developers must generate keys using the [Casper command-line client](#option-1-key-generation-using-the-casper-client) to access the `secret_key.pem` file.

The Casper Signer has been replaced with the Casper Wallet and will be deprecated. We recommend migrating all your Casper accounts to the Casper Wallet as outlined [here](https://www.casperwallet.io/user-guide/signer-user-start-here).

:::
Expand Down
2 changes: 1 addition & 1 deletion source/docs/casper/concepts/dictionaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The [Casper CEP-78 Enhanced NFT Standard](https://github.com/casper-ecosystem/ce

Simple examples for dictionary use within CEP-78 include the [`approve`](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/contract/src/main.rs#L772) dictionary.

More advanced dictionary functionality can be found in the [CEP-78 Page System](https://github.com/casper-ecosystem/cep-78-enhanced-nft#the-cep-78-page-system), which uses a series of dictionaries to keep track of token ownership. These dictionaries form the basis of the reverse lookup mode, which allows users to easily view a list of owned tokens by account or contract.
More advanced dictionary functionality can be found in the [CEP-78 Page System](https://github.com/casper-ecosystem/cep-78-enhanced-nft/blob/dev/docs/reverse-lookup.md#the-cep-78-page-system), which uses a series of dictionaries to keep track of token ownership. These dictionaries form the basis of the reverse lookup mode, which allows users to easily view a list of owned tokens by account or contract.

## Creating Dictionaries in a Contract's Context

Expand Down
231 changes: 24 additions & 207 deletions source/docs/casper/developers/dapps/sdk/python-sdk.md
Original file line number Diff line number Diff line change
@@ -1,236 +1,53 @@
# Python SDK

The [Python SDK](https://github.com/casper-network/casper-python-sdk) allows developers to interact with the Casper Node using Python 3.9+. This page covers various examples of using this SDK.
The [Python SDK](https://github.com/casper-network/casper-python-sdk) allows developers to interact with the Casper platform using Python 3.12+.

## Installation

To install the library, run:

```bash

pip3 install pycspr
```

## Tests

You can find examples of testing this library with python scripts in the `test` directory. To run the tests, we recommend the *pytest* library:

```bash
pytest ./tests
```

## Usage Examples

In this section, we outline a couple of essential tasks you can accomplish with the Python SDK:

* [Sending a transfer](#sending-a-transfer) between two purses
* [Staking](#staking) tokens with a validator

For further examples, take a look at the [How-tos](https://github.com/casper-network/casper-python-sdk/tree/main/how_tos).

### Sending a transfer

This example shows you how to define and transfer funds between purses on a Casper network. Replace the *path_to_cp2_account_key* in the code below with the receiver's account public key.

```python
import os
import pathlib
import random
import typing

import pycspr
from pycspr.client import NodeClient
from pycspr.client import NodeConnectionInfo
from pycspr.crypto import KeyAlgorithm
from pycspr.types import PrivateKey
from pycspr.types import Deploy
from pycspr.types import PublicKey

# path to cp1 secret key - defaults to NCTL user 1.
path_to_cp1_secret_key = pathlib.Path(os.getenv("NCTL")) / "assets" / "net-1" / "users" / "user-1" / "secret_key.pem"

# type of cp1 secret key - defaults to ED25519.
type_of_cp1_secret_key = KeyAlgorithm.ED25519.name,

# path to cp2 account key - defaults to NCTL user 2.
path_to_cp2_account_key = pathlib.Path(os.getenv("NCTL")) / "assets" / "net-1" / "users" / "user-2" / "public_key_hex"

# name of target chain - defaults to NCTL chain.
chain_name = "casper-net-1"

# host address of target node - defaults to NCTL node 1.
node_host = "localhost"

# Node API JSON-RPC port - defaults to 11101 @ NCTL node 1.
node_port_rpc = 11101

def _main(node_host, node_port_rpc, path_to_cp1_secret_key, type_of_cp1_secret_key,path_to_cp2_account_key, chain_name):
"""Main entry point.
:param args: Parsed command line arguments.
"""
# Set node client.
client = _get_client(node_host, node_port_rpc)

# Set counter-parties.
cp1, cp2 = _get_counter_parties(path_to_cp1_secret_key, type_of_cp1_secret_key,path_to_cp2_account_key)

# Set deploy.
deploy: Deploy = _get_deploy(chain_name, cp1, cp2)

# Approve deploy.
deploy.approve(cp1)

# Dispatch deploy to a node.
client.deploys.send(deploy)

#If deploy is successful send the indication
print(f"Deploy dispatched to node [{node_host}]: {deploy.hash.hex()}")


def _get_client(node_host, node_port_rpc) -> NodeClient:
"""Returns a pycspr client instance.
"""
return NodeClient(NodeConnectionInfo(
host=node_host,
port_rpc=node_port_rpc,
))


def _get_counter_parties(path_to_cp1_secret_key, type_of_cp1_secret_key,path_to_cp2_account_key) -> typing.Tuple[PrivateKey, PublicKey]:
"""Returns the 2 counter-parties participating in the transfer.
"""
cp1 = pycspr.parse_private_key(
path_to_cp1_secret_key,
type_of_cp1_secret_key,
)
cp2 = pycspr.parse_public_key(
path_to_cp2_account_key
)

return cp1, cp2


def _get_deploy(chain_name, cp1: PrivateKey, cp2: PublicKey) -> Deploy:
"""Returns transfer deploy to be dispatched to a node.
"""
# Set standard deploy parameters.
deploy_params = pycspr.create_deploy_parameters(
account = cp1,
chain_name = chain_name
)

# Set deploy.
deploy = pycspr.create_native_transfer(
params = deploy_params,
amount = int(2.5e9),
target = cp2.account_hash,
correlation_id = random.randint(1, 1e6)
)

return deploy


# Entry point.
if __name__ == '__main__':
_main(node_host, node_port_rpc, path_to_cp1_secret_key, type_of_cp1_secret_key, path_to_cp2_account_key, chain_name)
pip3 install pycspr
```

### Staking

This example shows you how to define and stake funds with a validator.
## How To's

```python
The following set of How To's cover the full SDK feature set and are designed to be run against a [CCTL](https://github.com/casper-network/cctl) network.

import os
import pathlib
### Cryptography

import pycspr
from pycspr.client import NodeClient
from pycspr.client import NodeConnectionInfo
from pycspr.crypto import KeyAlgorithm
from pycspr.types import Deploy
from pycspr.types import PrivateKey
* [How To: Apply a checksum](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/crypto/how_to_apply_a_checksum.py)

# path to cp1 secret key - defaults to NCTL user 1.
path_to_validator_secret_key = pathlib.Path(os.getenv("NCTL")) / "assets" / "net-1" / "users" / "user-1" / "secret_key.pem"
* [How To: Create Key Pairs](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/crypto/how_to_create_key_pairs.py)

# type of cp1 secret key - defaults to ED25519.
type_of_validator_secret_key = KeyAlgorithm.ED25519.name
* [How To: Hash data](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/crypto/how_to_hash_data.py)

# path to session code wasm binary - defaults to NCTL bin/eco/add_bid.wasm.
path_to_wasm = pathlib.Path(os.getenv("NCTL")) / "assets" / "net-1" / "bin" / "auction" / "add_bid.wasm"
* [How To: Sign data](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/crypto/how_to_sign_data.py)

# amount to stake, i.e. bond, into the network.
amount = int(2.5e9)
### Deploys

# amount to charge delegators for service provision.
delegation_rate = 2
* [How To: Transfer funds between 2 accounts](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/deploys/how_to_transfer.py)

# name of target chain - defaults to NCTL chain.
chain_name = "casper-net-1"
* [How To: Delegate funds to a validator](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/deploys/how_to_delegate.py)

# host address of target node - defaults to NCTL node 1.
node_host = "localhost"
* [How To: Undelegate funds from a validator](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/deploys/how_to_undelegate.py)

# Node API JSON-RPC port - defaults to 11101 @ NCTL node 1.
node_port_rpc = 11101
* [How To: Stake funds as a validator](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/deploys/how_to_stake.py)

def _main(node_host, node_port_rpc, path_to_validator_secret_key, type_of_validator_secret_key, chain_name, amount, delegation_rate, path_to_wasm):
"""Main entry point.
:param args: Parsed command line arguments.
"""
# Set node client.
client: NodeClient = _get_client(node_host, node_port_rpc)
* [How To: Unstake funds as a validator](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/deploys/how_to_unstake.py)

# Set validator key.
validator: PrivateKey = pycspr.parse_private_key(
path_to_validator_secret_key,
type_of_validator_secret_key,
)
### Smart Contracts

# Set deploy.
deploy: Deploy = _get_deploy(validator, chain_name, amount, delegation_rate, path_to_wasm)
* [How To: Install a smart contract](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/smart_contracts/how_to_install.py)

# Approve deploy.
deploy.approve(validator)
* [How To: Invoke a smart contract](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/smart_contracts/how_to_invoke.py)

# Dispatch deploy to a node.
client.deploys.send(deploy)
* [How To: Query a smart contract](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/smart_contracts/how_to_query.py)

print(f"Deploy dispatched to node [{node_host}]: {deploy.hash.hex()}")
### Node APIs

* [How To: Use REST API](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/node_apis/how_to_use_rest_client.py)

def _get_client(node_host, node_port_rpc) -> NodeClient:
"""Returns a pycspr client instance.
"""
return NodeClient(NodeConnectionInfo(
host = node_host,
port_rpc = node_port_rpc,
))
* [How To: Use RPC API](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/node_apis/how_to_use_rpc_client.py)

* [How To: Use Speculative RPC API](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/node_apis/how_to_use_speculative_rpc_client.py)

def _get_deploy(validator: PrivateKey, chain_name, amount, delegation_rate, path_to_wasm) -> Deploy:
"""Returns delegation deploy to be dispatched to a node.
"""
# Set standard deploy parameters.
deploy_params = pycspr.create_deploy_parameters(
account = validator,
chain_name = chain_name
)

# Set deploy.
deploy = pycspr.create_validator_auction_bid(
params = deploy_params,
amount = amount,
delegation_rate = delegation_rate,
public_key = validator.as_public_key(),
path_to_wasm = path_to_wasm
)

return deploy


# Entry point.
if __name__ == '__main__':
_main(node_host, node_port_rpc, path_to_validator_secret_key, type_of_validator_secret_key, chain_name, amount, delegation_rate, path_to_wasm)
```
* [How To: Use SSE API](https://github.com/casper-network/casper-python-sdk/blob/main/how_tos/node_apis/how_to_use_sse_client.py)
Loading
Loading