Registering in the Almanac Contract
Introduction
The Almanac contract requires uAgents to register using their Agent Address and pay a fee for registration to be found by other agents on the network. Therefore, it is essential for uAgents to have enough funds available in their Fetch Network Address.
For further information on uAgents addresses, have a look at our addresses guide βοΈ.
As highlighted in Registration and Endpoints Weighting βοΈ, uAgents can communicate by querying the Almanac and retrieving an endpoint
from the recipient uAgent. Therefore, we need to specify the service endpoints when defining our uAgent.
Walk-through
-
First of all, create a Python script and name it:
touch registration.py
-
Then, import the Agent class from the
uagents
library to create our uAgent, and thefund_agent_if_low
class from theuagents.setup
module, which we can use on the Fetch.ai testnet to run the functionfund_agent_if_low
. This function will check if you have enough tokens to register in the Almanac contract. If not it will add tokens to yourFetch Network address
. Then, create a agent, alice, providingname
,port
,seed
, andendpoint
.registration.pyfrom uagents.setup import fund_agent_if_low from uagents import Agent alice = Agent( name="alice", port=8000, seed="alice secret phrase", endpoint=["http://127.0.0.1:8000/submit"], ) fund_agent_if_low(alice.wallet.address())
Here we defined a local http address, but you can also define a remote address to allow agent communication over different machines through the internet. Once you run your script, your uAgent will start the registration process, the balance of the uAgent's wallet will be checked and be funded if needed. Then, we will be ready to start to a remote communication with other uAgents registered within the Almanac contract.
For further information on how to set up your uAgents and register them into the Almanac to allow for remote communication, visit the Communicating with other uAgents π±π€ βοΈ guide.