Brownie

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 https://apothemxdcpayrpc.blocksscan.io/

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=https://apothemxdcpayrpc.blocksscan.io/ 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

chain.id 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
'0x4D0928Df315D816d9a6540CF79D7c547C5294eA8'
>>> account.balance()
100000000000000000000
>>>

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 https://explorer.apothem.network/tokens/xdcaccf490aea9a2c17d60a62672ee519e61b5a1ec5

Adding the token to XDC Pay & transfering

Some transactions done

https://explorer.apothem.network/txs/0x23bbf8d8f84bbfdc85cce7493cb388e968f0aed3715b95fa81d3ac7c1614d004#overview

https://explorer.apothem.network/txs/0x2acf5757d236580c98b0c7e4ec864f700964ffa0cf3fcf7fe6130fe2a77a8d0c#overview

Last updated