fetch-logo
ConceptsConceptsGuidesGuidesExamplesExamplesReferencesReferencesAPIsAPIs
GitHub (opens in a new tab)
  • Guides
      • Quickstart
        • What's an Agent?
        • uAgents Framework installation
        • Create your first agent
        • Agents address
        • Communicating with other agents
        • Agent Handlers (on_...)
        • Agents storage functions
        • Public and private Agents
        • Send tokens with Agents
        • Agents Mailboxes
        • Agent Functions
        • Make agents AI Engine compatible
        • Multi-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline
        • Options for running local agents
        • Hosted agent
        • Introducing dialogues
        • Almanac Contract
        • Verify messages with Agents
        • Multi-file agent pipeline for AI Engine: Network of Primary and Secondary functions in Agentverse
        • Localwallet
        • Agentverse: Hosted Agents
        • Agentverse: Dice Roll agent
        • Agentverse: Allowed Imports
        • Agentverse: Mailbox
        • Register Agentverse Functions
        • Agentverse Functions: coin toss agent
        • Field descriptions for DeltaV
        • Agentverse Command Line Interface (AVCTL)
        • AVCTL Hosting commands
      • Agents and Functions creation APIs
      • Secret Management APIs
      • How to convert native FET to and from ERC-20 FET
      • How to stake FET tokens
      • Different ways of staking FET
      • Re-delegating staked FET token
      • Reconciliation service
      • How to setup a Multisig Wallet
        • Getting started
        • How to use the Fetch wallet
        • How to stake and claim rewards
        • Address book
        • Connections
        • Fetch Wallet Hardware Connection Guide
        • Installation
        • Connecting to a blockchain
        • Querying balances
        • Wallets and private keys
        • Sending funds
        • Staking
        • Smart contracts
          • Stake auto-compounder
          • Stake optimizer
          • Oracles
          • Wallet top-up
          • Liquidity pool
          • Swap automation
        • Installation️
        • Getting started
        • Keys
          • How to add profiles
          • How to add contract templates
          • How to compile contracts
          • How to deploy contracts
          • Contract interaction
        • Installation
        • How to use chain state snapshots
        • State-synchronization (state-sync)
        • How to set up a validator node
        • How to join a testnet
        • How to run a single node test network
        • Governance
        • How to get testnet tokens via the Token Faucet
          • CLI - Introduction
          • CLI - Managing keys
          • CLI - Managing tokens
          • CLI - Multisig keys
          • CLI - Delegation
          • Governance proposals
      • Agents 101
      • Agents 101 for AI Engine
  • Guides
      • Quickstart
        • What's an Agent?
        • uAgents Framework installation
        • Create your first agent
        • Agents address
          • Introduction
          • Print uAgent address
          • Print Fetch network address
          • Print agent name and address using name and address methods
        • Communicating with other agents
        • Agent Handlers (on_...)
        • Agents storage functions
        • Public and private Agents
        • Send tokens with Agents
        • Agents Mailboxes
        • Agent Functions
        • Make agents AI Engine compatible
        • Multi-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline
        • Options for running local agents
        • Hosted agent
        • Introducing dialogues
        • Almanac Contract
        • Verify messages with Agents
        • Multi-file agent pipeline for AI Engine: Network of Primary and Secondary functions in Agentverse
        • Localwallet
        • Agentverse: Hosted Agents
        • Agentverse: Dice Roll agent
        • Agentverse: Allowed Imports
        • Agentverse: Mailbox
        • Register Agentverse Functions
        • Agentverse Functions: coin toss agent
        • Field descriptions for DeltaV
        • Agentverse Command Line Interface (AVCTL)
        • AVCTL Hosting commands
      • Agents and Functions creation APIs
      • Secret Management APIs
      • How to convert native FET to and from ERC-20 FET
      • How to stake FET tokens
      • Different ways of staking FET
      • Re-delegating staked FET token
      • Reconciliation service
      • How to setup a Multisig Wallet
        • Getting started
        • How to use the Fetch wallet
        • How to stake and claim rewards
        • Address book
        • Connections
        • Fetch Wallet Hardware Connection Guide
        • Installation
        • Connecting to a blockchain
        • Querying balances
        • Wallets and private keys
        • Sending funds
        • Staking
        • Smart contracts
          • Stake auto-compounder
          • Stake optimizer
          • Oracles
          • Wallet top-up
          • Liquidity pool
          • Swap automation
        • Installation️
        • Getting started
        • Keys
          • How to add profiles
          • How to add contract templates
          • How to compile contracts
          • How to deploy contracts
          • Contract interaction
        • Installation
        • How to use chain state snapshots
        • State-synchronization (state-sync)
        • How to set up a validator node
        • How to join a testnet
        • How to run a single node test network
        • Governance
        • How to get testnet tokens via the Token Faucet
          • CLI - Introduction
          • CLI - Managing keys
          • CLI - Managing tokens
          • CLI - Multisig keys
          • CLI - Delegation
          • Governance proposals
      • Agents 101
      • Agents 101 for AI Engine
Guides
AI Agents
Getting Started
Agents address

Agents address

Introduction

Each agent within the Fetch ecosystem is characterized by different addresses. These can allow the agent to perform different actions, including sending messages or interacting with the Almanac contract ↗️.

It is possible to distinguish between two different types of addresses:

  • uAgent address: this address identifies the agent within the Fetch Network. It's similar to a username within a chat platform, allowing other agents to discover and communicate with that specific agent by querying that agent's information from the Almanac contract.

  • Fetch network address: this address is linked to the agent's wallet on the Fetch.ai network. It is essential to perform multiple functionalities like holding cryptocurrency, interacting with the Fetch Ledger ↗️ , but also performing secure transactions. This address is also essential to register an agent on the Almanac ↗️ contract to ensure the agents has enough funds available to perform operations in the network.

If you want to retrieve the address of an agent, you can either use the print() function and specify which of the above addresses you wish to print out, or by calling the .address() and .wallet.address() methods using the agent object to retrieve specific information.

Let's now check how these ways of retrieving addresses look like!

Print uAgent address

You can print the uAgent address related to your agent in the following way:

  1. First of all, create a Python script and name it: touch uagent-address.py

  2. We then need to import the Agent class from the uagents library to create an agent, alice. Then, using the print() function, we will print the related uAgent address. Importantly, remember that the seed parameter is used, when creating an agent, to set fixed addresses, otherwise a random address will be generated every time you run the agent:

    uagent-address.py
    from uagents import Agent
     
    agent = Agent(name="alice", seed="alice recovery phrase")
     
    print("uAgent address: ", agent.address)
     
    if __name__ == "__main__":
        agent.run()
  3. Save the script.

The output would be as follows:

uAgent address: agent1qww3ju3h6kfcuqf54gkghvt2pqe8qp97a7nzm2vp8plflc0epzcjsv79t

Print Fetch network address

You can print the Fetch network address related to your agent in the following way:

  1. Let's create a Python script, and name it: touch fetch-address.py

  2. As before, we first need to import the Agent class from the uagents library to create an Agent, alice. Then, using the print() function, we will print the related Fetch Network address:

    fetch-address.py
    from uagents import Agent
     
    agent = Agent(name="alice", seed="alice recovery phrase")
     
    print("Fetch network address: ", agent.wallet.address())
     
    if __name__ == "__main__":
        agent.run()
  3. Save the script.

The output would be as follows:

Fetch network address: fetch1454hu0n9eszzg8p7mvan3ep7484jxl5mkf9phg

Print agent name and address using name and address methods

In this guide, we aim at showing how to create an agent being able to say hello and printing its name and address using the uagents library tools. Indeed, it is possible to retrieve the name and address of any agent directly from the agent object representing the agent you create and initialise. More specifically, we refer to the following methods:

  • .name(): this returns the provided name of the agent, if specified, otherwise, if the agent's name is not explicitly set, then it will use the first ten characters of the agent's address as its name.

  • .address(): this returns the unique address of the agent in the form agent1.... This address is essential for other agents to interact with your agent.

Let's get started and use the agent object to make our agent print its name and address!

Walk-through

  1. First of all, you need to create a Python script and name it: touch my_agent.py

  2. We then need to import the necessary classes Agent and Context from the uagents library, and then create an instance of the Agent class, alice. Below you can see the agent object being initialised:

    from uagents import Agent, Context
     
    agent = Agent(name="alice", seed="alice recovery phrase")
  3. We would then need to assign the agent the behavior to be executed. In this case, agent could send a message when it is being run saying hello and printing its name and address using the agent object:

    @agent.on_event("startup")
    async def introduce_agent(ctx: Context):
        ctx.logger.info(f"Hello, I'm agent {agent.name} and my address is {agent.address}.")
     
     if __name__ == "__main__":
         agent.run()

    This introduce_agent() function takes a single argument ctx of type Context. The message is printed out using the ctx.logger.info() method, and includes the agent's name obtained from attribute name and retrieved using agent.name() method. The same for the agent's address, which is obtained from attribute address and retrieved using agent.address() method.

  4. Save the script.

The overall script should look as follows:

my_agent.py
from uagents import Agent, Context
 
agent = Agent(name="alice", seed="alice recovery phrase")
 
@agent.on_event("startup")
async def introduce_agent(ctx: Context):
    ctx.logger.info(f"Hello, I'm agent {agent.name} and my address is {agent.address}.")
 
if __name__ == "__main__":
    agent.run()

Run the script

If you are using a Poetry virtual environment, make sure that you have activated it.

On your terminal, run the script: python my_agent.py

The output should be as follows:

Hello, I'm agent alice and my address is agent1qww3ju3h6kfcuqf54gkghvt2pqe8qp97a7nzm2vp8plfxflc0epzcjsv79t.

Was this page helpful?

Create your first agentCommunicating with other agents
footer-logo

Main website

Integrations

Events

We’re hiring!

Twitter (opens in a new tab)Telegram (opens in a new tab)Discord (opens in a new tab)GitHub (opens in a new tab)Youtube (opens in a new tab)LinkedIn (opens in a new tab)Reddit (opens in a new tab)
Sign up for developer updates