Usage
Copy
Ask AI
from chipi_sdk import TransferParams, ChainToken
tx_hash = sdk.transfer(
params=TransferParams(
encrypt_key="user-secure-pin",
wallet=wallet_data, # WalletData object
token=ChainToken.USDC,
recipient="0x1234567890abcdef...",
amount="1.5", # Amount in USDC
)
)
Parameters
encrypt_key(str): PIN used to decrypt the private keywallet(WalletData): Wallet object withpublic_keyandencrypted_private_keytoken(ChainToken): Token type to transfer (e.g.,ChainToken.USDC,ChainToken.ETH)recipient(str): Destination wallet address (must start with0x)amount(str): Transfer amount (in token units, not wei)other_token(dict, optional): Custom token info forChainToken.OTHERtypeuse_passkey(bool, optional): Whether to use passkey authentication. Defaults toFalse
Return Value
Returns a transaction hash string.Example Implementation
Copy
Ask AI
from chipi_sdk import ChipiSDK, ChipiSDKConfig, TransferParams, ChainToken, WalletData
# Initialize SDK
sdk = ChipiSDK(
config=ChipiSDKConfig(
api_public_key="pk_prod_your_public_key",
api_secret_key="sk_prod_your_secret_key",
)
)
def transfer_usdc(
wallet: WalletData,
recipient_address: str,
amount: str,
user_pin: str
):
"""Transfer USDC tokens."""
try:
tx_hash = sdk.transfer(
params=TransferParams(
encrypt_key=user_pin,
wallet=wallet,
token=ChainToken.USDC,
recipient=recipient_address,
amount=amount,
)
)
print(f"✅ Transfer completed successfully!")
print(f" Transaction hash: {tx_hash}")
print(f" View on Starkscan: https://starkscan.co/tx/{tx_hash}")
return tx_hash
except Exception as error:
print(f"❌ Transfer failed: {error}")
raise
# Usage
def send_payment(sender_user_id: str, recipient_address: str, amount: str, pin: str):
"""Send USDC payment from user wallet."""
# Get sender's wallet
wallet = sdk.get_wallet(
params=GetWalletParams(external_user_id=sender_user_id)
)
if not wallet:
raise ValueError(f"Wallet not found for user: {sender_user_id}")
# Perform transfer
tx_hash = transfer_usdc(
wallet=wallet.wallet,
recipient_address=recipient_address,
amount=amount,
user_pin=pin
)
print(f"Sent {amount} USDC to {recipient_address}")
return tx_hash
# Send 10 USDC
tx = send_payment(
sender_user_id="user-123",
recipient_address="0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
amount="10.0",
pin="secure-pin-1234"
)
Async Version
For async applications, useatransfer:
Copy
Ask AI
import asyncio
async def transfer_usdc_async(wallet: WalletData, recipient: str, amount: str, pin: str):
"""Transfer USDC asynchronously."""
tx_hash = await sdk.atransfer(
params=TransferParams(
encrypt_key=pin,
wallet=wallet,
token=ChainToken.USDC,
recipient=recipient,
amount=amount,
)
)
return tx_hash
# Run async
tx_hash = asyncio.run(transfer_usdc_async(wallet, recipient, "5.0", "pin"))
Supported Tokens
The SDK supports multiple token types:Copy
Ask AI
from chipi_sdk import ChainToken
# Available tokens
ChainToken.USDC # USDC (Native)
ChainToken.USDC_E # USDC (Bridged)
ChainToken.USDT # Tether USD
ChainToken.ETH # Ethereum
ChainToken.STRK # Starknet token
ChainToken.DAI # DAI stablecoin
ChainToken.WBTC # Wrapped Bitcoin
ChainToken.OTHER # Custom token (requires other_token param)
Transferring Different Tokens
- USDC
- ETH
- STRK
- Custom Token
Copy
Ask AI
tx_hash = sdk.transfer(
params=TransferParams(
encrypt_key="user-pin",
wallet=wallet_data,
token=ChainToken.USDC,
recipient="0x...",
amount="100.5", # 100.5 USDC
)
)
Copy
Ask AI
tx_hash = sdk.transfer(
params=TransferParams(
encrypt_key="user-pin",
wallet=wallet_data,
token=ChainToken.ETH,
recipient="0x...",
amount="0.01", # 0.01 ETH
)
)
Copy
Ask AI
tx_hash = sdk.transfer(
params=TransferParams(
encrypt_key="user-pin",
wallet=wallet_data,
token=ChainToken.STRK,
recipient="0x...",
amount="50", # 50 STRK
)
)
Copy
Ask AI
tx_hash = sdk.transfer(
params=TransferParams(
encrypt_key="user-pin",
wallet=wallet_data,
token=ChainToken.OTHER,
other_token={
"contractAddress": "0x...",
"decimals": 18,
},
recipient="0x...",
amount="1000",
)
)
Complete Example with Error Handling
Copy
Ask AI
from chipi_sdk import (
ChipiSDK,
ChipiSDKConfig,
TransferParams,
ChainToken,
GetWalletParams,
ChipiTransactionError,
ChipiApiError
)
# Initialize SDK
sdk = ChipiSDK(
config=ChipiSDKConfig(
api_public_key="pk_prod_your_public_key",
api_secret_key="sk_prod_your_secret_key",
)
)
def safe_transfer(
sender_user_id: str,
recipient_address: str,
amount: str,
user_pin: str
):
"""Safely transfer USDC with comprehensive error handling."""
try:
# Validate recipient address
if not recipient_address.startswith("0x") or len(recipient_address) != 66:
raise ValueError("Invalid recipient address format")
# Get sender wallet
wallet_response = sdk.get_wallet(
params=GetWalletParams(external_user_id=sender_user_id)
)
if not wallet_response:
raise ValueError(f"Wallet not found for user: {sender_user_id}")
# Check balance (optional - add your balance check logic)
# balance = sdk.get_token_balance(...)
# Execute transfer
print(f"Initiating transfer of {amount} USDC...")
tx_hash = sdk.transfer(
params=TransferParams(
encrypt_key=user_pin,
wallet=wallet_response.wallet,
token=ChainToken.USDC,
recipient=recipient_address,
amount=amount,
)
)
print(f"✅ Transfer successful!")
print(f" TX Hash: {tx_hash}")
print(f" Starkscan: https://starkscan.co/tx/{tx_hash}")
# Log transaction to database
log_transaction(sender_user_id, recipient_address, amount, tx_hash)
return {
"success": True,
"tx_hash": tx_hash,
"amount": amount,
"token": "USDC",
"recipient": recipient_address
}
except ChipiTransactionError as e:
print(f"❌ Transaction error: {e.message}")
print(f" Error code: {e.code}")
return {"success": False, "error": str(e)}
except ChipiApiError as e:
print(f"❌ API error: {e.message}")
print(f" Status: {e.status}")
return {"success": False, "error": str(e)}
except ValueError as e:
print(f"❌ Validation error: {e}")
return {"success": False, "error": str(e)}
except Exception as e:
print(f"❌ Unexpected error: {e}")
return {"success": False, "error": str(e)}
# Usage
result = safe_transfer(
sender_user_id="user-123",
recipient_address="0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
amount="25.50",
user_pin="secure-pin-1234"
)
if result["success"]:
print(f"Payment of {result['amount']} USDC sent successfully!")
else:
print(f"Payment failed: {result['error']}")
Batch Transfers
Transfer to multiple recipients:Copy
Ask AI
def batch_transfer(sender_user_id: str, recipients: list, amount_per_recipient: str, pin: str):
"""Send USDC to multiple recipients."""
# Get sender wallet once
wallet_response = sdk.get_wallet(
params=GetWalletParams(external_user_id=sender_user_id)
)
results = []
for recipient in recipients:
try:
tx_hash = sdk.transfer(
params=TransferParams(
encrypt_key=pin,
wallet=wallet_response.wallet,
token=ChainToken.USDC,
recipient=recipient,
amount=amount_per_recipient,
)
)
results.append({"recipient": recipient, "tx_hash": tx_hash, "success": True})
print(f"✅ Sent {amount_per_recipient} USDC to {recipient[:10]}...")
except Exception as e:
results.append({"recipient": recipient, "error": str(e), "success": False})
print(f"❌ Failed to send to {recipient[:10]}...: {e}")
return results
# Send 10 USDC to 3 recipients
results = batch_transfer(
sender_user_id="user-123",
recipients=[
"0x1111111111111111111111111111111111111111111111111111111111111111",
"0x2222222222222222222222222222222222222222222222222222222222222222",
"0x3333333333333333333333333333333333333333333333333333333333333333",
],
amount_per_recipient="10.0",
pin="secure-pin-1234"
)
# Summary
successful = sum(1 for r in results if r["success"])
print(f"\n📊 Batch transfer complete: {successful}/{len(results)} successful")
Security Considerations
Transaction Security
- Always validate recipient addresses before transferring
- Implement transfer limits for security
- Log all transactions for audit purposes
- Use rate limiting to prevent abuse
- Never expose encryption keys in logs or error messages
Gas FeesAll transfers use Chipi’s gasless paymaster - users don’t need ETH for gas!
Related Methods
- get_wallet - Get wallet information before transfers
- call_any_contract - For custom contract interactions
- execute_transaction - Backend SDK equivalent
