In this guide, we will learn how to build an end-to-end "onchain bio" dApp. We'll start with the the Move contract. Then we'll build a React frontend and let wallets connect and register a bio.
Create a new file named onchain_bio.move within the sources directory and add the following to that file:
Writing our onchain bio module
Here is the completed onchain bio Move module:
module onchain_bio_addr::onchain_bio {use std::string::{String};use std::signer;structBio has key, store, drop { name:String, bio:String, } public entry fun register(account:&signer, name:String, bio:String) acquires Bio {// Check if an Bio already exists for the accountif (exists<Bio>(signer::address_of(account))) {// Remove the existing Biolet _old_Bio = move_from<Bio>(signer::address_of(account)); };// Create the new Biolet bio =Bio { name, bio, };// Store the new Bio under the account move_to<Bio>(account, bio); }}
Next, let's deploy to M1!
Deploying the Module to Movement's M1 Blockchain
First, from within the move directory, initialize your Movement Aptos configuration:
movementaptosinit
When propted to choose a network, enter custom.
Then enter the following REST endpoint:
https://aptos.devnet.m1.movementlabs.xyz
And the same URL for faucet endpoint.
When asked for a private key, press Enter to generate a new keypair.
Upon successful initialization, you'll see the success message (with your account address instead of 0x39883cbc29500a8bf79911ea1469e1c3b58104547a88fb0fbdf17470f80b2a91):
No key given, generating key...Account 0x39883cbc29500a8bf79911ea1469e1c3b58104547a88fb0fbdf17470f80b2a91 doesn't exist, creating it and funding it with 100000000 Octas
Account 0x39883cbc29500a8bf79911ea1469e1c3b58104547a88fb0fbdf17470f80b2a91 funded successfully---Aptos CLI is now set up for account 0x39883cbc29500a8bf79911ea1469e1c3b58104547a88fb0fbdf17470f80b2a91 as profile default! Run `aptos --help` for more information about commands
{"Result":"Success"}
Now your move directory will contain a hidden .aptos folder containing a config.yaml file. You can view the contents of that file to see your private and public keys.
In the the line under [addresses] in Move.toml, add your account address:
onchain_bio_addr ="<your-account-address>"
After compiling, you'll see a result message formatted like this:
This wraps our app in the <AptosWalletAdapterProvider /> tag so we can connect a wallet. To add support for more wallets, see the Aptos Wallet Adapter README.
Your locally-running app should now look like this:
Feel free to style the app however you prefer.
Using Your App
To use the dApp, first configure an Aptos wallet to M1.
Head over to the Movement Faucet and fund your M1 devnet wallet.
Enter a name and bio. Click the Register Bio button. The wallet should pop up for you to sign. After the transaction has been submitted to the blockchain, you'll see your onchain bio information updated:
What dApps will you build on Movement?
Now you know how to deploy an Aptos dApp for M1.
Check out onchain_bio.move logic, try a redeployment by tinkering with it. As a challenge, try modifying the Front End to better display your name and bio!
We can't wait to see what dApps you build and deploy to Movement Network!