This documentation covers the implementation of vault creation in the Zarban Stablecoin System. The SDK provides functionality for creating vaults, handling transactions, and managing collateral using Web3 and the Zarban API.
- Python 3.x
- Web3.py
- Zarban SDK
- Ethereum node access (RPC URL)
- Private key with sufficient funds
- Required Python packages:
pip install zarban
Retrieves available collateral types from the system.
Parameters:
api (service.StableCoinSystemApi)
: The API client instance
Returns:
list
: Unique collateral type symbols
Example:
symbols = get_ilks_symbol(stable_coin_system_api)
Converts human-readable amounts to blockchain native format.
Parameters:
api (service.StableCoinSystemApi)
: The API client instancesymbol (str)
: Asset symbol (e.g., "ETH", "ZAR")amount (float)
: Human-readable amount
Returns:
str
: Amount in native blockchain format (wei)
Example:
native_amount = to_native(api, "ETH", 0.01)
Retrieves transaction steps for vault creation.
Parameters:
api (service.StableCoinSystemApi)
: The API client instanceilk_name (str)
: Collateral type namesymbol (str)
: Asset symbolwallet_address (str)
: User's wallet addresscollateral_amount (float)
: Collateral amountloan_amount (float)
: Loan amount in stablecoin
Returns:
dict
: (number_of_steps, step_number, steps)
Waits for transaction confirmation.
Parameters:
w3
: Web3 instancetx_hash
: Transaction hashmax_wait_time
: Maximum wait time in secondscheck_interval
: Check interval in seconds
Returns:
- Transaction receipt or None
Saves transaction details to a JSON file.
Parameters:
tx
: Transaction objecttx_hash
: Transaction hashvault_id
: Vault identifier (can be None)
# Configuration
HTTPS_RPC_URL = "your_ethereum_node_url"
PRIVATE_KEY = "your_private_key"
WALLET_ADDRESS = get_address_from_private_key(PRIVATE_KEY)
# Setup API client
cfg = service.Configuration(host="https://testapi.zarban.io")
api_client = service.ApiClient(cfg)
stable_coin_system_api = service.StableCoinSystemApi(api_client)
# Setup Web3
w3 = Web3(Web3.HTTPProvider(HTTPS_RPC_URL))
# Vault parameters
ILK_NAME = "ETHA"
SYMBOL = "ETH"
COLLATERAL_AMOUNT = 0.01
LOAN_AMOUNT = 1000
# Create vault
api_response = get_vault_tx_steps(
stable_coin_system_api,
ILK_NAME,
SYMBOL,
WALLET_ADDRESS,
COLLATERAL_AMOUNT,
LOAN_AMOUNT
)
-
Initialization
- Set up API client and Web3 connection
- Configure vault parameters
-
Transaction Steps
- Retrieve vault creation steps
- Process each step sequentially
- Handle transaction signing and submission
-
Transaction Monitoring
- Wait for transaction confirmation
- Log transaction details
- Verify vault creation
-
Result Verification
- Get transaction logs
- Extract vault ID
- Update transaction records
try:
# Vault creation code
except service.ApiException as e:
print(f"Response body: {beautify_json(e.body)}")
except Exception as e:
print(f"Unexpected error: {e}")
-
Security
- Never hardcode private keys
- Use environment variables for sensitive data
- Verify all transaction parameters before signing
-
Transaction Management
- Always wait for transaction confirmations
- Implement proper error handling
- Log all transactions for audit purposes
-
Gas Management
- Use appropriate gas limits
- Monitor gas prices
- Implement retry mechanisms for failed transactions
The system maintains a transaction log file (transaction_log.json
) with the following information:
- Timestamp
- Transaction details
- Transaction hash
- Vault ID (when available)
Example log entry:
{
"timestamp": "2024-03-13T10:00:00",
"tx": {
"from": "0x...",
"to": "0x...",
"value": "1000000000000000",
"gas": 200000
},
"tx_hash": "0x...",
"vault_id": "123"
}
-
Network Dependencies
- Requires stable network connection
- Dependent on Ethereum network status
- May be affected by network congestion
-
Resource Requirements
- Sufficient ETH for gas fees
- Adequate collateral for vault creation
- Valid API access
-
Transaction Timing
- Transaction confirmation times vary
- Maximum wait time configurable
- May require multiple steps
-
Connection Issues
if not w3.is_connected(): print(f"Failed to connect to {HTTPS_RPC_URL}") exit(1)
-
Transaction Failures
- Check gas prices and limits
- Verify account balance
- Confirm network status
-
API Errors
- Validate API credentials
- Check request parameters
- Review error responses
For additional support or bug reports, please contact the Zarban support team or refer to the API documentation.