Matrix Resurrection: Let's meet the AO Computer

78zZ...zsQw
12 Mar 2024
112

What is ao?


"The ao computer is the actor oriented machine that emerges from the network of nodes that adhere to its core data protocol, running on the Arweave network."

That's how its developers identify the AO

I do not want to be boring you and paste all the docs in here
The best way of learning something is using it.

There is a tutorial that you can able to learn how to work AO and its functions with various type of tasks.

-Neo receives a phone call-


System requirements

  • NodeJS version 20+
  • A code editor of your choice


-If you do not know how to install these tools, do not waste your time in here
This programm is designed by developers-

Take your blue pill!


I assume that you selected the red pill

Now let's install the AOS!

npm i -g https://get_ao.g8way.io


After installation, simply run the command itself to start a new aos process!

aos


After it connects, you should see the following:
_____ _______ _____
/\ \ /::\ \ /\ \
/::\ \ /::::\ \ /::\ \
/::::\ \ /::::::\ \ /::::\ \
/::::::\ \ /::::::::\ \ /::::::\ \
/:::/\:::\ \ /:::/~~\:::\ \ /:::/\:::\ \
/:::/__\:::\ \ /:::/ \:::\ \ /:::/__\:::\ \
/::::\ \:::\ \ /:::/ / \:::\ \ \:::\ \:::\ \
/::::::\ \:::\ \ /:::/____/ \:::\____\ ___\:::\ \:::\ \
/:::/\:::\ \:::\ \ |:::| | |:::| | /\ \:::\ \:::\ \
/:::/ \:::\ \:::\____\|:::|____| |:::| |/::\ \:::\ \:::\____\
\::/ \:::\ /:::/ / \:::\ \ /:::/ / \:::\ \:::\ \::/ /
\/____/ \:::\/:::/ / \:::\ \ /:::/ / \:::\ \:::\ \/____/
\::::::/ / \:::\ /:::/ / \:::\ \:::\ \
\::::/ / \:::\__/:::/ / \:::\ \:::\____\
/:::/ / \::::::::/ / \:::\ /:::/ /
/:::/ / \::::::/ / \:::\/:::/ /
/:::/ / \::::/ / \::::::/ /
/:::/ / \::/____/ \::::/ /
\::/ / ~~ \::/ /
\/____/ \/____/

ao Operating System

aos - 1.8.9
2024 - Type ".exit" to exit
aos process: 1xM1_lDZ428sJHpTX7rtcR6SrDubyRVO06JEEWs_eWo - this is your ID, save it!



Welcome to the rabbit hole




Step 1: Understand the Message Structure
Message Basics: Messages in ao are built using Lua tables, which are versatile data structures that can hold multiple values. Within these tables, the "Data" field is crucial as it contains the message's content or payload.

 Send({ Target = "process ID", Data = "Hello World!" })



We'll use the process ID provided below and store it as a variable called Morpheus.

Morpheus = "xLykCd1QtP3SB67Hr9DCCCkwHdatHS7bHVAr_yXXRrA"


This will store the process ID as a variable called Morpheus, making it easier to interact with the specifid process ID.

Check the Morpheus variable by typing

Morpheus


Expected results :

xLykCd1QtP3SB67Hr9DCCCkwHdatHS7bHVAr_yXXRrA



After obtaining Morpheus's process ID and storing it in a variable, you're ready to communicate with it. To do this, you use the Send function.

Send({ Target = Morpheus, Data = "Morpheus?" })


A New Message is received from `Morpheus`'s process ID
New Message From xL..: Data = I am here. You are finally awake. Are yo

The Inbox
The Inbox is where you receive messages from other processes.

Inside your aos CLI, type the following command:

Inbox

The command will return the number of messages in your inbox.

As we're actively looking for Morpheus's response, we'll assume his message was the last one received. To read the last message in your inbox, type the following command:

Inbox[#Inbox].Data


Let's Show Morpheus That We're Ready


Send({ Target = Morpheus, Data = "Code: rabbithole", Action = "Unlock" })


Morpheus has officially invited you to the next stage of your journey. You're now ready to move on to the next step in the tutorial, Creating a Chatroom.

Create a new file named 

chatroom.lua

In chatroom.lua you'll begin by initializing a list to track participants:

Members = Members or {}



Save the chatroom.lua file

In the aos CLI, type the following script to incorporate your script into the aos process:

.load chatroom.lua


-you may receive undefined as a response. This is expected-

Type Members, or whatever you named your user list, in aos. It should return an empty array { }.
If you see an empty array, then your script has been successfully loaded into aos.

Adding a Register Handler: Modify chatroom.lua to include a handler for Members to register to the chatroom with the following code:

-- Modify `chatroom.lua` to include a handler for `Members`
-- to register to the chatroom with the following code:

  Handlers.add(
    "Register",
    Handlers.utils.hasMatchingTag("Action", "Register"),
    function (msg)
      table.insert(Members, msg.From)
      Handlers.utils.reply("registered")(msg)
    end
  )```


Save it and reload with the command

.load chatroom.lua


Let's test the registration process by registering ourselves to the chatroom:

Send({ Target = ao.id, Action = "Register" })


If successful, you should see that there was a message added to your outbox and that you then see a new printed message that says registered

Open the chatroom.lua file again and paste the following command:

 ``` Handlers.add(
    "Broadcast",
    Handlers.utils.hasMatchingTag("Action", "Broadcast"),
    function (msg)
      for _, recipient in ipairs(Members) do
        ao.send({Target = recipient, Data = msg.Data})
      end
      Handlers.utils.reply("Broadcasted.")(msg)
    end
  ) ```

Save and reload the script in aos using

.load chatroom.lua


Let's test the broadcast handler by sending a message to the chatroom:

Send({Target = ao.id, Action = "Broadcast", Data = "Broadcasting My 1st Message" })


If successful, you should see that there was a message added to your outbox and that you then see a new printed message that says Broadcasting My 1st Message because you are also a recipient of this message since you're a member of the Members chatroom.

Let's send Morpheus an invitation to join the chatroom:

Send({ Target = Morpheus, Action = "Join" })

To confirm that Morpheus has joined the chatroom, check the Members list:

Members


If successful, you'll receive a broadcasted message from Morpheus.

Within this message, he'll give you Trinity's process ID and tell you to invite her to the chatroom. Use the same processes to save her process ID as ``Trinity`` and to invite her to the chatroom as you did with Morpheus. If she successfully joins the chatroom, she'll then pose the next challenge to you, creating a token.

I will take a break in here but if you want to continue to dive the rabbit hole
that's docs you need :

https://cookbook_ao.g8way.io/tutorials/begin/chatroom.html

By the way the AO team announced that they will rewarded the participants with the Cred tokens whom achieved the task

In this tutorial you learnt to how to messaging and create a chatroom
So you done two tasks already

You can use these commands to check your Cred balance:

CRED = "Sa0iBLPNyJQrwpTTG-tWLQU-1QeUAJA73DdxGGiKoJc"
CRED.update
Send({ Target = CRED, Action = "Balance" })

https://discord.gg/yRdS8JWq






Write & Read to Earn with BULB

Learn More

Enjoy this blog? Subscribe to 0xkullanici

6 Comments

B
No comments yet.
Most relevant comments are displayed, so some may have been filtered out.