Working with Bancor Network
How to navigate the Bancor Network contracts
Bancor Network's system of smart contracts work together to provide a complete solution to on-chain liquidity. We've highlighted some of the key network functions in the Developer Quick Start
and encourage you to begin your development process here. Down below in the Other Guides
section, you'll find some deeper dives into various elements of Bancor Network.
The network includes a contract address discovery mechanism - a contract that servers as a registry for all the core contracts, that queries the latest contract addresses by their names. These contracts are updated from time to time, so developers are advised to reference the registry directly in order to stay current with the network.
Each Quick Start guide has code snippets which demonstrate how to call the registry, however we've also outlined the process and the different approaches below.
Option 1: Querying the ContractRegistry
For example, to get the latest contract address of the BancorNetwork contract, the following call should be used:
bancorNetwork = ContractRegistry.addressOf('BancorNetwork')
The addressOf
function on the ContractRegistry contract can receive any of the known contract names as an argument, in bytes32 format. Below is a list of all core contract names with their bytes32 representation
Option 2: Listen to AddressUpdate Events
Every time an address is changed, the ContractRegistry will throw an AddressUpdate event.
For example, to get the latest contract address of the BancorNetwork contract, one should track an AddressUpdate event that indicates new address for BancorNetwork (using its bytes32 representation).
Contract Names and Addresses
ContractRegistry address
ContractRegistry also indicates its own address, which means you should run the same process to make sure you are working with the latest version of the ContractRegistry
List of Contracts Names and Bytes32 Representation
If you are not sure about the contract name or bytes32 representation, you can always trigger the function contractNames with a serial number as an input (i.e. 0, 1, 2, etc). The response will be the name of the available contract.
Last updated