DEV Community

EgorMajj
EgorMajj

Posted on

Aleo Testnet - Deploy a Smart Contract

Step 1: Create a new Aleo wallet in seconds:

• Already have a wallet? Skip this step ✅
• Visit https://aleo.tools/ and click "Generate" to create a secure wallet. Save the output 🔒

Finally, use your keys to add variables to your server with these commands

Image description

Step 2: Get tokens for your wallet

Simply text +1-867-888-5688 with the format below and receive 50 credits instantly.

Send: "50 credits to aleo1jjjnu3xk05h239ak5w2x5ejfh6del0whpe7pgya0pu00cp4pn5yq40ykus"

Step 3: Grab packages and start a slick tmux session.

sudo apt update && \
sudo apt install make clang pkg-config libssl-dev build-essential gcc xz-utils git curl vim tmux ntp jq llvm ufw -y && \
tmux new -s deploy
Enter fullscreen mode Exit fullscreen mode

Building a binary requires creating a tmux session, which may take some time. But don't worry - if your ssh connection is lost, you won't have to rebuild everything. Just reconnect to your existing tmux session and pick up where you left off.

Step 4: Add your wallet and private key as a variable.

echo Enter your Private Key: && read PK && \
echo Enter your View Key: && read VK && \
echo Enter your Address: && read ADDRESS
Enter fullscreen mode Exit fullscreen mode

Step 5: Make sure the data is correct. If not, you can do step 4 again.

echo Private Key: $PK && \
echo View Key: $VK && \
echo Address: $ADDRESS
Enter fullscreen mode Exit fullscreen mode

Once you get a message from the bot confirming your wallet has been replenished, head to https://faucet.aleo.org/ and double-check the transaction went through.

Use the Transaction ID as the answer when using the following command.

echo Enter your Transaction ID: && read TI
Enter fullscreen mode Exit fullscreen mode
CIPHERTEXT=$(curl -s https://vm.aleo.org/api/testnet3/transaction/$TI | jq -r '.execution.transitions[0].outputs[0].value')
Enter fullscreen mode Exit fullscreen mode

Step 6: Install required software

cd $HOME
git clone https://github.com/AleoHQ/snarkOS.git --depth 1
cd snarkOS
bash ./build_ubuntu.sh
source $HOME/.bashrc
source $HOME/.cargo/env
Enter fullscreen mode Exit fullscreen mode
cd $HOME
git clone https://github.com/AleoHQ/leo.git
cd leo
cargo install --path .
Enter fullscreen mode Exit fullscreen mode

Step 7: Deploy a contract

NAME=helloworld_"${ADDRESS:4:6}"
mkdir $HOME/leo_deploy
cd $HOME/leo_deploy
leo new $NAME
Enter fullscreen mode Exit fullscreen mode
RECORD=$(snarkos developer decrypt --ciphertext $CIPHERTEXT --view-key $VK)
Enter fullscreen mode Exit fullscreen mode
snarkos developer deploy "$NAME.aleo" \
--private-key "$PK" \
--query "https://vm.aleo.org/api" \
--path "$HOME/leo_deploy/$NAME/build/" \
--broadcast "https://vm.aleo.org/api/testnet3/transaction/broadcast" \
--fee 4000000 \
--record "$RECORD"
Enter fullscreen mode Exit fullscreen mode

After executing the command, you should see a similar result.

root@DS-A-1:~/Leo_deploy# snarkos developer deploy "$NAME.aleo" --private-key "$PK" --query "https://vm.aleo.org/api" --path "$HOME/Leo_deploy/SNAME/build/" --broadcast "https://vm.aleo.org/api/testn
et3/transaction/broadcast" --fee 4000000 --record "$RECORD"
Creating deployment transaction for 'helloworld_1m3y73.aleo'...
Created deployment transaction for 'helloworld_1m3y73.aleo'
Successfully deployed helloworld_1m3y73.aleo' to https: //vm.aleo.org/api/testnet3/transaction/broadcast.

Use the resulting transaction hash to find your contract in Explorer: https://explorer.hamp.app/
If your contract shows up in Explorer, you can go to the next step.

Step 8: Execute a contract

Use the transaction hash as the answer for the following command.

echo Enter your Deploy hash: && read DH
Enter fullscreen mode Exit fullscreen mode
CIPHERTEXT=$(curl -s https://vm.aleo.org/api/testnet3/transaction/$DH | jq -r '.fee.transition.outputs[].value')
Enter fullscreen mode Exit fullscreen mode
RECORD=$(snarkos developer decrypt --ciphertext $CIPHERTEXT --view-key $VK)
Enter fullscreen mode Exit fullscreen mode
snarkos developer execute "$NAME.aleo" "hello" "1u32" "2u32" \
--private-key $PK \
--query "https://vm.aleo.org/api" \
--broadcast "https://vm.aleo.org/api/testnet3/transaction/broadcast" \
--fee 1000000 \
--record "$RECORD"
Enter fullscreen mode Exit fullscreen mode

After execution, you should see the following output

root@DS-A-1:~/leo_deploy# snarkos developer execute "$NAME.aleo" "hello" "1u32" "2u32" --private-key $PK --query "https://vm.aleo.org/api" --broadcast "https://vm.aleo.org/api/testnet3/transaction/br
oadcast"
--fee 1000000 --record "$RECORD"
w Creating execution transaction for 'helloworld_1m3y73.aleo'
© Created execution transaction for 'helloworld_1m3y73.aleo/hello'
© Successfully broadcast execution 'helloworld_1m3y73.aleo/hello' to the https://vm.aleo.org/api/testnet3/transaction/broadcast.

Use the resulting transaction hash to find your contract in Explorer: https://explorer.hamp.app/

Congratulations you have deployed the contract to Aleo!

Top comments (1)

Collapse
 
apexdev profile image
Ashish

Great