A complete, end-to-end walkthrough of the StellarTip contract on Stellar testnet. By the end you will have:
- Deployed the contract
- Initialized it as admin
- Registered a creator profile
- Sent a tip from a supporter to the creator
- Withdrawn the tip to the creator's wallet
Every command is paste-able into your terminal. Expected outputs are shown in fenced blocks.
| Tool | Install |
|---|---|
| Rust (nightly) | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh then rustup toolchain install nightly --target wasm32-unknown-unknown |
| Stellar CLI | cargo install --locked stellar-cli@22.8.2 (or latest 22.x) |
Tip: The
rust-toolchain.tomlin the repo root pins nightly and the wasm32 target automatically when you runcargo buildinside the repo.
Verify both tools are installed:
rustc --version
stellar --versiongit clone https://github.com/StellarTips/StellarTip-Contract.git
cd StellarTip-ContractBuild the WASM artifact:
make wasm-build Compiling stellar-tip v0.1.0
Finished release [optimized] target(s) in 12.34s
Confirm the artifact exists:
ls -lh target/wasm32-unknown-unknown/release/stellar_tip.wasm-rwxr-xr-x 1 user staff 18K Jul 18 12:00 target/wasm32-unknown-unknown/release/stellar_tip.wasm
We need two identities: one for the admin (deploys and configures the contract) and one for the supporter (sends tips).
# Generate keys (skip if you already have identities)
stellar keys generate admin --network testnet --fund
stellar keys generate supporter --network testnet --fundThe --fund flag automatically requests testnet XLM from the friendbot.
Verify both accounts are funded:
stellar keys fund admin --network testnet
stellar keys fund supporter --network testnetYou can also check balances:
stellar keys address admin
# → e.g. GA6QYEZ...admin...address
stellar keys address supporter
# → e.g. GB3KJET...supporter...addressDeploy using the included script (or manually with stellar contract deploy):
./scripts/deploy.sh testnet adminDeploying StellarTip contract to 'testnet' using identity 'admin'...
WASM: target/wasm32-unknown-unknown/release/stellar_tip.wasm (18K)
CCONTRACT_ID: CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Deploy complete. Copy the contract ID printed above for use in your application.
Important: Copy the contract ID (
CXXX...) printed by the deploy command. Every subsequent command uses it. Export it as a shell variable for convenience:
export CONTRACT_ID="CXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"The contract must be initialized once by the admin. This sets the admin address, fee recipient, platform fee, and storage caps.
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
init \
--caller "$(stellar keys address admin)" \
--fee_recipient "$(stellar keys address admin)" \
--fee_bps 250 \
--max_creators 0 \
--max_tips_per_creator 0 \
--min_tip_amount 1| Parameter | Meaning |
|---|---|
fee_bps 250 |
2.5 % platform fee (250 basis points). Use 0 for no fee. |
max_creators 0 |
Unlimited creator registrations (0 = no cap). |
max_tips_per_creator 0 |
Unlimited tip history per creator. |
min_tip_amount 1 |
Minimum tip is 1 stroop (the smallest XLM unit). |
Verify initialization:
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
get_admin"GA6QYEZ...admin...address"
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
get_fee_percentage250
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
get_contract_version3
We'll register a creator profile. For this tutorial, the admin account also acts as the creator (you could use a separate identity).
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
register \
--caller "$(stellar keys address admin)" \
--username "alice" \
--display_name "Alice" \
--bio "Digital artist"No output means success. Verify the profile was created:
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
get_profile \
--address "$(stellar keys address admin)"{
"username": "alice",
"display_name": "Alice",
"bio": "Digital artist",
"registered_at": 1234567890
}You can also look up by username:
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
is_username_taken \
--username "alice"true
To tip in XLM we need the address of the Stellar Asset Contract (SAC) for the native asset on testnet.
export XLM_TOKEN="CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA"Note: The native XLM SAC address above is for testnet. On mainnet the address is different. Check the Stellar docs for the correct SAC address for your network.
The supporter sends 10 XLM (10 000 000 stroops) to the creator "alice":
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source supporter \
-- \
tip \
--from "$(stellar keys address supporter)" \
--creator "$(stellar keys address admin)" \
--token "$XLM_TOKEN" \
--amount 10000000 \
--message "Love your art!"The return value is the tip's index in the creator's tip history:
0
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
get_balance \
--creator "$(stellar keys address admin)" \
--token "$XLM_TOKEN"9750000
The balance is 9 750 000 stroops (9.75 XLM) because the contract deducts the 2.5 % platform fee (250 bps) from every tip:
- Tip amount: 10 000 000 stroops
- Fee (2.5 %): 250 000 stroops → sent to fee recipient
- Creator credit: 9 750 000 stroops
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
get_tip_count \
--creator "$(stellar keys address admin)"1
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
get_tip \
--creator "$(stellar keys address admin)" \
--index 0{
"from": "GB3KJET...supporter...address",
"token": "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA",
"amount": "10000000",
"message": "Love your art!",
"timestamp": 1234567890
}The creator withdraws their accumulated XLM balance to their own wallet:
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
withdraw \
--caller "$(stellar keys address admin)" \
--token "$XLM_TOKEN" \
--amount 9750000No output means success. Verify the internal balance is now zero:
stellar contract invoke \
--id "$CONTRACT_ID" \
--network testnet \
--source admin \
-- \
get_balance \
--creator "$(stellar keys address admin)" \
--token "$XLM_TOKEN"0
Check the creator's wallet balance on the network:
stellar account show --network testnet --source adminYou should see that the native XLM balance reflects the withdrawn amount (minus any base reserves and transaction fees).
Admin (deployer) Supporter StellarTip Contract
│ │ │
│── deploy ──────────────────│────────────────────────────>│
│── init(admin, fee 2.5%) ──>│ │
│── register(alice) ────────>│ │
│ │ │
│ │── tip(10 XLM, "Love!") ──>│
│ │ │── fee → admin
│ │ │── credit alice
│ │ │
│<── withdraw(9.75 XLM) ────│ │
│ │ │── send XLM → alice
- Multi-token tipping: Tip with USDC or any Stellar asset by passing
its SAC address as the
--tokenargument. - Multiple creators: Register additional addresses with unique usernames.
- Admin tuning: Adjust fees, caps, and minimums with
set_fee_percentage,set_max_creators,set_max_tips_per_creator, andset_min_tip_amount. - Read the full API: See the Contract Interface table in the README for every available function.
| Error | Cause | Fix |
|---|---|---|
#9 AlreadyInitialized |
Contract was already initialized | You can only call init once. Redeploy the contract if you need a fresh start. |
#1 CreatorAlreadyExists |
Address already registered | Each address can only register once. Use unregister first (requires zero balances). |
#3 UsernameTaken |
Username already claimed | Choose a different username. |
#14 CapExceeded |
Creator or tip cap reached | Ask the admin to raise the cap with set_max_creators / set_max_tips_per_creator, or pass 0 to disable. |
#10 Paused |
Contract is paused | Wait for the admin to call unpause. |
#4 InsufficientBalance |
Withdrawal exceeds internal balance | Check get_balance before withdrawing. |
#16 BelowMinimum |
Tip amount below configured minimum | Increase the tip amount or ask the admin to lower set_min_tip_amount. |