Brownie is Python-Based framework for developing custom smart contracts on the Blockchain, we will be deploying XRC20 to XDC Network using brownie

Things we need:

  • Python > 3.8

  • eth-brownie

Brownie works well with Python above 3.8

 python -m pip install eth-brownie

Will get you the latest eth-brownie version from pypi packages

After installation eth-brownie should be in your terminal enviroment as brownie

Fire up a terminal and type brownie --help to make sure everything is good

Connecting to XDC Network Using Brownie

Using a suitable RPC address we will be connecting to a node on XDC Network to be use on brownie

We will connect to Testnet using RPC

brownie network list will print a list of network that we have available and ready to use yet we need to add XDC since it does not come by default in brownie

To easily connect to XDC Network when using brownie we will be adding it as default in our Brownie Networks enviroment type the following:

brownie networks add xdc testnet host= chainid=51

Interacting with XDC Network using Brownie

We our network already added on our brownie list we will proceed to interact with it

Lighting up a terminal type brownie console --network tesnet print us 51 letting us know that are already connected to XDC

Querying Account balances

We will add an account to query the balance we have available on XDC

>>> from web3 import Account
>>> account = accounts.add(Account.create().key)
>>> account.address
>>> account.balance()

Our balance in fact:

Initializing a new Brownie Project

Using brownie init will output us a project structure containing folder to initialize our new project (tokens, etc)

Transfering XDC between Accounts using Brownie

below we are transfering some XDC main token between accounts using browning

Compiling a XRC20 & deploying to the network

We will be deploying the following XRC20

pragma solidity >=0.8.0 <0.9.0;
import "./XRC20.sol";
address constant owner = 0x4D0928Df315D816d9a6540CF79D7c547C5294eA8;
contract BlastToken is XRC20Token {
  constructor() XRC20Token('Blaster Token', 'Blast', 18, 1000*10**18) {}

Deployed Token

After deployment the we can see "Blast Token" on-chain

Adding the token to XDC Pay & transfering

Some transactions done

Last updated