Test Accounts
Localnet provides pre-funded test accounts for immediate use.
Available Accounts
| Name | Address | Initial Balance |
|---|
alice | xyz1alice… | 1,000,000 XYZ (1,000,000,000,000 uxyz) |
bob | xyz1bob… | 500,000 XYZ (500,000,000,000 uxyz) |
These accounts are automatically available when localnet is running.
Using Test Accounts
Check Balance
Output:
Balances for alice (xyz1alice...)
DENOM AMOUNT
uxyz 1,000,000,000,000 (1,000,000 XYZ)
Send Tokens
# Alice sends to Bob
xyz tx send xyz1bob... 100000uxyz --from alice
Deploy Contracts
xyz program deploy artifacts/my_contract.wasm --from alice --label "My Contract"
Execute Contracts
xyz program execute xyz1contract... '{"increment":{}}' --from bob
Account Details
Alice
Primary test account, typically used for deployments.
# View full account info
xyz keys show alice
# Get address
xyz keys show alice --address
Bob
Secondary test account, useful for testing transfers.
Mnemonics
Test accounts use deterministic mnemonics for reproducibility. Query the actual mnemonics from your localnet keyring:
These mnemonics are public and for testing only. NEVER use them for real funds.
# Export a test account mnemonic
xyz keys export alice --unsafe --unarmored-hex
Creating Additional Accounts
Generate New Account
xyz keys generate dev-test
Fund from Alice
xyz tx send $(xyz keys show dev-test --address) 100000uxyz --from alice
Import Existing
xyz keys import my-test --mnemonic "your twelve word mnemonic phrase here"
Multi-Account Workflows
Token Transfer
# Alice → Bob
xyz tx send $(xyz keys show bob --address) 50000uxyz --from alice
Contract Ownership Transfer
# Alice deploys
CONTRACT=$(xyz program deploy artifacts/my_contract.wasm --from alice --label "Shared Contract" | grep "Contract:" | awk '{print $2}')
# Bob executes
xyz program execute $CONTRACT '{"increment":{}}' --from bob
# Query result
xyz program query $CONTRACT '{"get_count":{}}'
Checking Balances
Single Account
All Test Accounts
for key in alice bob; do
echo "=== $key ==="
xyz balance --key $key
done
JSON Output
xyz balance --key alice --output json
{
"address": "xyz1alice...",
"balances": [
{"denom": "uxyz", "amount": "1000000000000"}
]
}
Reset Account Balances
To restore accounts to initial state:
# Reset entire localnet
xyz localnet stop --clean
xyz localnet start
Accounts return to their initial balances (alice: 1,000,000 XYZ, bob: 500,000 XYZ).
Scripting with Test Accounts
Bash Script
#!/bin/bash
# Deploy and test with multiple accounts
CONTRACT=$(xyz program deploy artifacts/counter.wasm \
--from alice \
--label "Counter" \
--msg '{"count":0}' | grep "Contract:" | awk '{print $2}')
echo "Contract: $CONTRACT"
# Alice increments
xyz program execute $CONTRACT '{"increment":{}}' --from alice
# Bob increments
xyz program execute $CONTRACT '{"increment":{}}' --from bob
# Check count
xyz program query $CONTRACT '{"get_count":{}}'
# Expected: {"count": 2}
Test Script
#!/bin/bash
set -e
echo "Testing token transfer..."
# Get initial balances
ALICE_BEFORE=$(xyz balance --key alice --output json | jq -r '.balances[0].amount')
BOB_BEFORE=$(xyz balance --key bob --output json | jq -r '.balances[0].amount')
# Transfer
xyz tx send $(xyz keys show bob --address) 1000uxyz --from alice
# Get final balances
ALICE_AFTER=$(xyz balance --key alice --output json | jq -r '.balances[0].amount')
BOB_AFTER=$(xyz balance --key bob --output json | jq -r '.balances[0].amount')
# Verify
if [ "$BOB_AFTER" -gt "$BOB_BEFORE" ]; then
echo "✓ Transfer successful"
else
echo "✗ Transfer failed"
exit 1
fi
Troubleshooting
Test accounts are only available when localnet is running:xyz localnet status
xyz localnet start # if not running
Account may have spent its balance. Reset localnet:xyz localnet stop --clean
xyz localnet start
Localnet uses the test keyring backend:xyz keys list --keyring-backend test
Best Practices
- Use alice for deployments - Keep bob for testing interactions
- Reset often - Start fresh to avoid state confusion
- Script everything - Make tests reproducible
- Check balances - Verify before complex operations
- Use JSON output - Easier parsing in scripts