Skip to content

Python SDK - Examples

For sample code which explains the core concepts of how to use the SDK, see:

Below are additional resources which may be more suited for your individual use case.

The v2/examples folder in the SDK repo has many code snippets you can customize to your needs. When you install aptos-sdk from PyPI, import the same APIs from aptos_sdk.v2 instead of aptos_sdk_v2.

ExampleDescription
transfer_apt.pyBasic APT transfer between two accounts
different_key_types.pyEd25519 vs Secp256k1 accounts
multi_agent_transfer.pyMulti-agent transaction with two signers
sponsored_transaction.pyFee-payer sponsored transaction
orderless_transfer.pyOrderless transaction with a replay-protection nonce
batch_orderless_transfers.pyParallel orderless transfers
simulate_transaction.pySimulate a transaction before submitting
fetch_on_chain_data.pyLedger info, blocks, resources, and view functions
mnemonic_key_recovery.pyBIP-39 mnemonic generation and key derivation
custom_coin_fungible_asset.pyCoin API vs Fungible Asset API
script_transaction.pyScript payload construction

v1 examples such as transfer_coin.py and fee_payer_transfer_coin.py live in the top-level examples folder.

To run one of the v2 example scripts:

  1. Clone the repository.

    Terminal window
    git clone https://github.com/aptos-labs/aptos-python-sdk.git
    cd aptos-python-sdk
  2. Install the package and dependencies.

    Terminal window
    pip install .
  3. Run an example. From the v2/ directory the examples import aptos_sdk_v2:

    Terminal window
    cd v2
    python examples/transfer_apt.py