Learn everything about Aptos
Deploying Smart Contract to the Aptos
Deploying and Testing a Smart Contract on Aptos with Well Done Studio
Welcome back! In the last lesson, we completed writing our smart contract. In this session, we will deploy that contract to the testnet and run a full set of tests to verify its functionality using Well Done Studio.
Step 1: Preparing for Deployment
Open your project directory. You'll see the typical structure:
- sources/ for your Move modules
- Move.toml file for package configuration
- build/ or output/ generated upon compilation (not essential to edit)
In your Move.toml, ensure your Vault module address is defined. This address corresponds to your test account in the Well Done Wallet and will be the owner of the deployed contract.
Step 2: Compile the Smart Contract
- Open Well Done Studio
- Select your Vault from the Appos folder.
- Click Compile.
- Once compiled, you will see your Vault module listed under the specified address.
Step 3: Deploy the Contract
- Ensure you're connected to the correct network (testnet or devnet) in your wallet.
- Click Deploy.
- When prompted, enter your wallet password and approve the transaction.
- Once successful, the module and associated resources will appear under your contract address in Well Done Studio.
Step 4: Testing the Contract
✅ Check Initial Balance
- Call get_balance with the admin address.
- Expected result: 0 (initial state).
✅ Deposit Tokens
- Call deposit_tokens with a value (e.g., 100).
- Note: Aptos uses a base unit of 10^8, so 100 is a very small fraction of one Aptos coin.
- Approve the transaction when prompted.
✅ Recheck Balance
- Call get_balance again using the admin address.
- Expected result: 100.
✅ Allocate Tokens
- Call allocate_tokens with:
- First parameter: the recipient address
- Second parameter: allocation amount (e.g., 20)
- Approve the transaction and verify allocation via get_allocation.
✅ Withdraw Tokens
- Call withdraw_tokens from the admin account (e.g., withdraw 50).
- After success, verify new balance is reduced accordingly (e.g., 50 remains).
Step 5: Switch Account & Claim Allocation
- Switch your active account in Well Done Wallet to the address that received an allocation (e.g., "Posidon").
- Reconnect Well Done Studio.
- Re-add the admin address to continue accessing the Vault.
- Use get_allocation to verify the current allocation.
- Call claim_tokens using the admin address as the parameter (this tells the contract which Vault the tokens came from).
- Check:
- get_allocation → should return 0.
- get_balance for the admin → should reflect the claimed reduction.
Tips
- Gas fees only apply to state-changing (execute) functions like deposit, allocate, withdraw, and claim.
- View functions like get_balance or get_allocation are read-only and don’t require wallet approval.
- If you switch wallets, your contract may disappear from view. Just re-add the original admin address to restore access to the Vault and resources.
Final Thoughts
Congratulations! You've:
- Written, compiled, and deployed a smart contract on Aptos
- Tested it end-to-end with deposits, withdrawals, allocations, and claims
- Learned to navigate Well Done Studio and handle wallet changes
Comments
You need to enroll in the course to be able to comment!