Getting started on the xDAI chain with sbt-ethereum

Setting up to work with a new chain on sbt-ethereum involves a few steps.

1. Set the Sesion Chain ID

The Chain ID of xDAI chain is 100. We use ethNodeChainIdOverride to temporary override our default chain ID.

> ethNodeChainIdOverride 100
[info] The chain ID has been overridden to 100.
[info] The session is now active on chain with ID 100.
[warn] No node URL has been defined -- not as a persistent default, nor as a session override, nor as an sbt setting or hardcoded value.
[warn] Please define a node URL for this chain, via 'ethNodeUrlDefaultSet' or 'ethNodeUrlOverride'.
[warn] All attempts to interact with the blockchain will fail until a node URL is defined!
[warn] There is no sender available for the current session.
[warn] Consider using 'ethAddressSenderDefaultSet' or 'ethAddressSenderOverrideSet' to define one.
[info] Refreshing caches.
[success] Total time: 0 s, completed Feb 19, 2021, 5:31:35 AM

Note that if we wish to, we could make this our installation’s default Chain ID with ethNodeChainIdDefaultSet.

2. Define a node URL

Ideally, one would run ones own xDAI chain customiized Ethereum node, and make use of its jsonrpc services. Most of us won’t do that. However, there is a public xDAI RPC service, at https://rpc.xdaichain.com/. Let’s use that. The relevant task here is ethNodeUrlDefaultSet

> ethNodeUrlDefaultSet https://rpc.xdaichain.com/
[info] Successfully set default node json-rpc URL for chain with ID 100 to https://rpc.xdaichain.com/.
[success] Total time: 0 s, completed Feb 19, 2021, 5:32:08 AM

We have set https://rpc.xdaichain.com/ as the persistent default for out sbt-ethereum installation, when our node chain ID is set to 100. Cool!

3. Check our configuration

A convenient way to do this is to simply ask the node for its current block number. We’ll use ethNodeBlockNumberPrint.

> ethNodeBlockNumberPrint
[info] The current blocknumber is 14622953, according to node at 'https://rpc.xdaichain.com/'.
[success] Total time: 0 s, completed Feb 19, 2021, 5:32:32 AM

4. Create an account

We could use an account we already have (even if we also use it on other chains), but let’s not. We’ll create an account to play on the xDAI chain, using ethKeystoreWalletV3Create.

> ethKeystoreWalletV3Create
[info] Generated keypair for address '0x72a8a15ECa1f824ADE35cdEB2148223402f23448'
[info] Generating V3 wallet, algorithm=scrypt, n=262144, r=8, p=1, dklen=32
Enter passphrase for new wallet: *******************
Please retype to confirm: *******************
[info] Wallet generated into sbt-ethereum shoebox: '/Users/swaldman/Library/Application Support/sbt-ethereum'. Please backup, via 'ethShoeboxBackup' or manually.
[info] Consider validating the wallet using 'ethKeystoreWalletV3Validate 0x72a8a15ECa1f824ADE35cdEB2148223402f23448'.
Would you like to define an alias for address '0x72a8a15ECa1f824ADE35cdEB2148223402f23448' (on chain with ID 100)? [y/n] y
Please enter an alias for address '0x72a8a15ECa1f824ADE35cdEB2148223402f23448' (on chain with ID 100): testing-xDAI
[info] Alias 'testing-xDAI' now points to address '0x72a8a15ECa1f824ADE35cdEB2148223402f23448' (for chain with ID 100).
[info] Refreshing caches.
[success] Total time: 29 s, completed Feb 19, 2021, 5:52:53 AM

Let’s also set this account to be our default sender for this chain, using ethAddressSenderDefaultSet.

> ethAddressSenderDefaultSet testing-xDAI
[info] Successfully set default sender address for chain with ID 100 to '0x72a8a15ECa1f824ADE35cdEB2148223402f23448' (with aliases ['default-sender','testing-xDAI'] on chain with ID 100).
[info] You can use the synthetic alias 'default-sender' to refer to this address.
[info] Refreshing caches.
[success] Total time: 0 s, completed Feb 19, 2021, 5:56:58 AM

5. Interact with a contract

There is a test ERC20 token called FAU (for FaucetToken) deployed on the xDAI chain at address 0x3111C94B9243a8A99D5A867e00609900e437E2c0.

First, so we don’t have to type the hex address all the time, let’s define the token’s symbol as an alias for the address, using ethAddressAliasSet.

> ethAddressAliasSet FAU 0x3111C94B9243a8A99D5A867e00609900e437E2c0
[info] Alias 'FAU' now points to address '0x3111C94B9243a8A99D5A867e00609900e437E2c0' (for chain with ID 100).
[info] Refreshing caches.
[success] Total time: 0 s, completed Feb 19, 2021, 6:15:34 AM

Since FAU is an ERC20 token, we can use sbt-ethereum‘s built-in functions for interacting with these tokens. We can only try read-only operations (since we have no xDAI to pay “gas”). A convenient choice is erc20Summary.

> erc20Summary FAU
[info] ERC20 Summary, token contract at '0x3111C94B9243a8A99D5A867e00609900e437E2c0' (with aliases ['FAU'] on chain with ID 100):
[info]   Self-Reported Name:   FaucetToken
[info]   Self-Reported Symbol: FAU
[info]   Decimals:             18
[info]   Total Supply:         20213495245 tokens (20213495245000000000000000000 atoms)
[success] Total time: 0 s, completed Feb 19, 2021, 6:32:30 AM

Cool!