home / skills / multiversx / mx-ai-skills / mvx_sdk_py_contracts
This skill helps you manage MultiversX smart contracts with ABI loading, deployment, calls, and queries from the Python SDK.
npx playbooks add skill multiversx/mx-ai-skills --skill mvx_sdk_py_contractsReview the files below or copy the command above to add this skill to your agents.
---
name: mvx_sdk_py_contracts
description: Smart contract operations for MultiversX Python SDK.
---
# MultiversX SDK-Py Smart Contracts
This skill covers ABI loading, deployments, calls, and queries.
## ABI Loading
```python
from multiversx_sdk import Abi
from pathlib import Path
# Load from file
abi = Abi.load("contract.abi.json")
```
## Smart Contract Controller
```python
# Create controller with loaded ABI
controller = entrypoint.create_smart_contract_controller(abi=abi)
```
## Deployment
```python
bytecode = Path("contract.wasm").read_bytes()
tx = controller.create_transaction_for_deploy(
sender=account,
nonce=account.get_nonce_then_increment(),
bytecode=bytecode,
gas_limit=60000000,
arguments=[42] # Typed automatically via ABI
)
tx_hash = entrypoint.send_transaction(tx)
parsed_outcome = controller.await_completed_deploy(tx_hash)
contract_address = parsed_outcome[0].contract_address
```
## Contract Calls
```python
# Call endpoint
tx = controller.create_transaction_for_execute(
sender=account,
nonce=account.get_nonce_then_increment(),
contract=contract_address,
function="add",
arguments=[10],
gas_limit=5000000
)
# Call with token transfer (Transfer & Execute)
tx = controller.create_transaction_for_execute(
sender=account,
nonce=account.get_nonce_then_increment(),
contract=contract_address,
function="deposit",
gas_limit=10000000,
native_amount=1000000000000000000
)
```
## VM Queries
Read-only calls to the contract state.
```python
# Using controller (parsed output)
result = controller.query_contract(
contract=contract_address,
function="getSum",
arguments=[]
)
print(result[0]) # Typed output
```
## Without ABI (Manual Typing)
If ABI is not available, use manual type hinting (less recommended).
```python
from multiversx_sdk import SmartContractTransactionsFactory
factory = entrypoint.create_smart_contract_transactions_factory()
tx = factory.create_transaction_for_execute(
sender=account.address,
contract=contract_address,
function="add",
gas_limit=5000000,
arguments=[42] # Basic types inferred
)
```
## Upgrades
```python
new_bytecode = Path("contract_v2.wasm").read_bytes()
tx = controller.create_transaction_for_upgrade(
sender=account,
nonce=account.get_nonce_then_increment(),
contract=contract_address,
bytecode=new_bytecode,
gas_limit=60000000,
arguments=[]
)
```
## Best Practices
1. **Always use ABI**: Ensures correct argument encoding/decoding
2. **Query for reads**: Free (no gas), instant response
3. **Wait for completion**: Use controller methods to get parsed results
4. **Gas limit**: Ensure enough gas for computation + storage
This skill provides Python tools for working with MultiversX smart contracts: loading ABIs, preparing and sending deploys, upgrades, execute calls, and VM queries. It wraps low-level transaction construction with typed encoding when an ABI is available and offers fallbacks for manual typing. The skill focuses on reliable transaction lifecycle handling and parsed outcomes for easier integration.
Load a contract ABI to get a smart contract controller that builds typed transactions and decodes responses. Use controller methods to create deploy, execute, upgrade, or query requests, then send transactions and await parsed completion results. If no ABI is available, a transactions factory can build basic, manually typed calls but without automatic encoding/decoding.
Do I need an ABI to interact with contracts?
No, but using an ABI is strongly recommended. ABI enables correct encoding/decoding and typed results; without it you must manually manage types.
Are VM queries free and safe to use?
Yes. VM queries are read-only calls that do not consume gas and return instant, typed results when using the controller.