# Retrieving Contract Addresses

> Learn how to retrieve contract addresses on Flare Networks

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.

Source: https://dev.flare.network/network/guides/flare-contracts-registry

## Overview[​](#overview "Direct link to Overview")

Flare provides a registry of enshrined protocol contracts such as `FtsoV2`, `FdcHub`, and `RandomNumberV2`.  
To ensure reliability, these contract addresses should **always be retrieved dynamically** via the **Flare Contract Registry** rather than hardcoding them. Using the registry ensures your contracts, and dApps are resistant to future upgrades and cannot be misled by offchain or unverified sources.

## Flare Contract Registry Address[​](#flare-contract-registry-address "Direct link to Flare Contract Registry Address")

The [`FlareContractRegistry`](/network/solidity-reference/IFlareContractRegistry) smart contract is the **only trusted source** for resolving official protocol contract addresses.

The registry is deployed at the same address across all Flare networks:

Contract

Address

`FlareContractRegistry`

[`0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019`](https://flare-explorer.flare.network/address/0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019 "Open in explorer")

Contract

Address

`FlareContractRegistry`

[`0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019`](https://coston2-explorer.flare.network/address/0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019 "Open in explorer")

Contract

Address

`FlareContractRegistry`

[`0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019`](https://songbird-explorer.flare.network/address/0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019 "Open in explorer")

Contract

Address

`FlareContractRegistry`

[`0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019`](https://coston-explorer.flare.network/address/0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019 "Open in explorer")

## Retrieval Methods[​](#retrieval-methods "Direct link to Retrieval Methods")

In the following code example, the `RandomNumberFetcher` contract retrieves the address of `RandomNumberV2` using the three approaches described below.

contracts/RandomNumberFetcher.sol

```
// SPDX-License-Identifier: MITpragma solidity ^0.8.25;import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston/ContractRegistry.sol";import {IFlareContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston/IFlareContractRegistry.sol";import {RandomNumberV2Interface} from "@flarenetwork/flare-periphery-contracts/coston/RandomNumberV2Interface.sol";// Demonstrates three different ways to retrieve the RandomNumberV2 contract on the Flare network.contract RandomNumberFetcher {    // DO NOT USE IN PRODUCTION — hardcoding addresses is discouraged due to upgradeability and security risks    function getRandomNumberHardcoded()        public        view        returns (            uint256 _randomNumber,            bool _isSecureRandom,            uint256 _randomTimestamp        )    {        // Using a hardcoded address to create an interface instance (Not recommended in production)        RandomNumberV2Interface randomNumberV2 = RandomNumberV2Interface(            0x92a6E1127262106611e1e129BB64B6D8654273F7        );        return randomNumberV2.getRandomNumber();    }    // Fetches a random number by resolving the contract address via the FlareContractRegistry    function getRandomNumberViaRegistryName()        public        view        returns (            uint256 _randomNumber,            bool _isSecureRandom,            uint256 _randomTimestamp        )    {        // Instantiate the FlareContractRegistry at the known address (same across all networks)        IFlareContractRegistry flareContractRegistry = IFlareContractRegistry(            0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019        );        // Get the address of the Random Number V2 contract        address randomNumberV2Address = flareContractRegistry            .getContractAddressByName("RandomNumberV2");        // Create an interface instance pointing to the contract address        RandomNumberV2Interface randomNumberV2 = RandomNumberV2Interface(            randomNumberV2Address        );        return randomNumberV2.getRandomNumber();    }    // Fetches the RandomNumberV2 contract using the shared ContractRegistry library    function getRandomNumberViaContractLibrary()        public        view        returns (            uint256 _randomNumber,            bool _isSecureRandom,            uint256 _randomTimestamp        )    {        // Get the RandomNumberV2 contract interface using the ContractRegistry library        RandomNumberV2Interface randomNumberV2 = ContractRegistry            .getRandomNumberV2();        return randomNumberV2.getRandomNumber();    }}
```

[Open in Remix](https://remix.ethereum.org/#url=https://github.com/flare-foundation/developer-hub/blob/main/examples/developer-hub-solidity/RandomNumberFetcher.sol&version=builtin&evmVersion=cancun&optimize=true&runs=200)

### 🔴 Hardcoded Address[​](#-hardcoded-address "Direct link to 🔴 Hardcoded Address")

The `getRandomNumberHardcoded` function below uses a hardcoded address to create an interface instance. Not recommended in production.

warning

-   Never hardcode contract addresses in production.
-   Avoid using contract addresses obtained from unofficial sources like DMs, social media, or third-party websites.
-   Instead of passing contract addresses directly into constructors, retrieve them dynamically, as shown below.

### Flare Contract Registry Smart Contract[​](#flare-contract-registry-smart-contract "Direct link to Flare Contract Registry Smart Contract")

The Flare Contract Registry smart contract exposes [`getContractAddressByName`](/network/solidity-reference/IFlareContractRegistry#getcontractaddressbyname) or [`getContractAddressByHash`](/network/solidity-reference/IFlareContractRegistry#getcontractaddressbyhash) to retrieve the address of the contract.

In the code example above, the `getRandomNumberViaRegistryName` function uses the `getContractAddressByName` method to retrieve the address of `RandomNumberV2`.

### Contract Registry Library[​](#contract-registry-library "Direct link to Contract Registry Library")

The [Flare periphery package](https://www.npmjs.com/package/@flarenetwork/flare-periphery-contracts) package includes a helper utility [`ContractRegistry`](https://github.com/flare-foundation/flare-solidity-periphery-package-mirror/blob/master/flare/ContractRegistry.sol). This library provides shorthand functions for accessing common protocol contracts, e.g., `ContractRegistry.getRandomNumberV2()`.

In the example, the `getRandomNumberViaContractLibrary` function demonstrates this approach.

tip

If the contract you are looking for does not have a shorthand method in the `ContractRegistry` library, you can fall back to using `getContractAddressByName` or call `getAllContracts` to list all registered contracts.
