Registering in the Almanac Contract
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.
First of all, create a Python script and name it:
Then, import the Agent class from the
uagentslibrary to create our uAgent, and the
fund_agent_if_lowclass from the
uagents.setupmodule, which we can use on the Fetch.ai testnet to run the function
fund_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 your
Fetch Network address. Then, create a agent, alice, providing
from 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.