Elements code tutorial

Using Elements to perform basic operations

With both Elements daemons running, we can now use their associated clients to retrieve wallet information from them:

e1-cli getwalletinfo
e2-cli getwalletinfo

You will see that we currently have 21 million “bitcoin” in each wallet. This is because the “bitcoin” are held in outputs that are created as “anyone-can-spend”. This is done on chain initialization and it is useful for testing and also enables easy allocating of the coins initially created in a non-test environment. The amount of the default asset created can be changed using the “initialfreecoins” setting in the elements config file. The fact that the asset is named “bitcoin” can be ignored for now, it is merely a default label assigned to the first asset created by Elements. We will see how to override the default behaviour of creating 21 Million of the default asset, and the label the default asset is assigned, in a later section.

NOTE: You may notice that a lot of the RPC commands you can issue to an Elements client are the same as those you can issue to a Bitcoin client. This is because the Elements code is based upon Bitcoin’s own. You can find a list of the available RPC commands for the Elements client in elements/src/rpc/client.cpp on GitHub.

Let’s drain the “anyone-can-spend” values and send half the assets to a new address generated by each Elements node. We’ll also need to generate more than 100 blocks so that the coins are spendable (a requirement of the maturity rule for spending coinbase rewards):

e1-cli sendtoaddress $(e1-cli getnewaddress) 21000000 "" "" true
e1-cli generate 101
e1-cli sendtoaddress $(e2-cli getnewaddress) 10500000 "" "" false
e1-cli generate 101

The “true” and “false” refer to fee deductions and can be ignored for now.

Check that the funds have been evenly split:

e1-cli getwalletinfo
e2-cli getwalletinfo

Both should show (amongst other values):

"bitcoin": 10500000.00000000

That confirms that our nodes are operational and able to transact.

Next: Using Confidential Transactions