Ether is the “fuel” of the Ethereum network. Whenever you wish to interact with a smart contract in a way that might update its state, you have to pay some Ether for the privilege (as we have seen, just looking up information from an Ethereum smart contract without changing anything is always free).
Ether is a “cryptocurrency”, like Bitcoin and many others. We’ll generally refer to it as ETH. To work with the Ethereum network, you need a little bit of ETH. But just a little, not much! 10 or 20 USD will go a long way, in terms of letting you develop, deploy, and interact with sanely written Ethereum smart contracts.
While users need a little bit of ETH to interact with the network, most financial smart contracts — applications that manipulate flows of economic value — should not use ETH as their primary currency or store of value.
Like most cryptocurrencies, the value of ETH in terms of real-world goods and services is very, very volatile.
It’s better to define applications in terms of stablecoins, cryptographic tokens whose value is credibly pegged to a real-world currency like the US dollar.
But be careful, choose well! Some stablecoins are more credible than others. Holding value in a bad stablecoin is like holding money in a bad bank with no deposit insurance. You might lose yur money.
We did this in the prior tutorial, but let’s do it again. To check your default account’s ETH balance, use the command ethAddressBalance
:
sbt:eth-command-line> ethAddressBalance default-sender
0 ether (as of the latest incorporated block, address 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2)
This corresponds to approximately 0.00 USD (at a rate of 84.24 USD per ETH, retrieved at 9:13 PM from Coinbase)
[success] Total time: 0 s, completed Dec 16, 2018 9:13:59 PM
The argument to ethAddressBalance
is an Ethereum account, which can be provided in all the forms that sbt-ethereum accepts. We’ve used the automatic address alias default-sender
, but we could also have provided a hex address directly, or an ENS name, like this:
sbt:eth-command-line> ethAddressBalance pejorative.eth
0.36043144606611496 ether (as of the latest incorporated block, address 0x465e79b940bc2157e4259ff6b2d92f454497f1e4)
This corresponds to approximately 30.31 USD (at a rate of 84.1 USD per ETH, retrieved at 9:40 PM from Coinbase)
[success] Total time: 1 s, completed Dec 16, 2018 9:43:51 PM
We can also run this command without providing any argument at all! How does that work? sbt-ethereum relies on the notion of a current sender. Many commands need to act “on behalf” of a particular Ethereum address, and use the current sender.
Let’s check this out:
sbt:eth-command-line> ethAddressSenderPrint
[info] The current effective sender address is '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' (with aliases ['default-sender'] on chain with ID 1).
[info] + This value is the default sender address defined in the sbt-ethereum shoebox for chain with ID 1.
[info] + It has not been overridden with a session override or by an 'ethcfgAddressSender' setting in the project build or the '.sbt' folder.
[success] Total time: 0 s, completed Dec 16, 2018 10:00:10 PM
By default, the current sender is the account we set up during our initial setup as the default sender, and which automatically has the alias default-sender
. However, we can override the current sender at any time, using the task ethAddressSenderOverrideSet
.
If we try ethAddressBalance
with no sender, it will use the current sender.
sbt:eth-command-line> ethAddressBalance
0 ether (as of the latest incorporated block, address 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2)
This corresponds to approximately 0.00 USD (at a rate of 84.22 USD per ETH, retrieved at 10:00 PM from Coinbase)
[success] Total time: 0 s, completed Dec 16, 2018 10:04:14 PM
When sending ETH, or tokens, or interacting with Ethereum applications in any capacity, be sure you understand on behalf of which Ethereum address you are acting!
You can run ethAddressSenderPrint
explicitly, but before transacting on your behalf, sbt-ethereum will always ask you to confirm your willingness to transact, displaying the “From” Ethereum address for you to verify. Always double check that you are transact from the address that you intend to transact.
Before you can really work with Ethereum, you will need an address (probably your default-sender
address) to be funded with a bit of ETH.
The easiest way to do this is to buy a bit (you don’t need much, $10 or $20 is plenty to get started!) from a service such as Coinbase. On the Coinbase website, once you have bought some ETH, you can go under the “Accounts” tab, find your Ethereum wallet, and click “Send”. Send to your sbt-ethereum default sender address.
If you’ve forgotten your default sender, try ethAddressSenderDefaultPrint
. (Obviously, send to your own default sender address, NOT to the one below!):
sbt:eth-command-line> ethAddressSenderDefaultPrint
[info] The default sender address for chain with ID 1 is '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2'.
[success] Total time: 0 s, completed Dec 16, 2018 10:28:40 PM
Before sending money to your address, you may want to verify that you remember the passphrase that unlocks it. (If you don’t remember the passphrase, the address will receive your funds just fine, but no one will ever, ever, be able to access them. Let’s verify, using the command ethKeystoreWalletV3Validate
:
sbt:eth-command-line> ethKeystoreWalletV3Validate 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2
[info] V3 wallet(s) found for '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' (aliases ['default-sender'])
Enter passphrase or hex private key for address '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2': ***************
[info] A wallet for address '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' is valid and decodable with the credential supplied.
[success] Total time: 8 s, completed Dec 16, 2018 10:33:57 PM
The output looks good (note the statement “is valid and decodable with the credential supplied”, and the [success]
). So we can go ahead and send to this address.
If you purchasing ETH via websites like Coinbase, it may take several days before your ETH is available for sending.
That is annoying, but difficult to avoid.
If you know someone who already has ETH, you can buy it from them informally. Just ask them to send to your address, and pay them what it’s worth in a regular currency.
But it’s probably best to keep informal exchanges to small amounts. Large informal exchanges may prompt regulatory scrutiny.
One you have some ETH, we can try ethAddressBalance
again.
sbt:eth-command-line> ethAddressBalance
0.1 ether (as of the latest incorporated block, address 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2)
This corresponds to approximately 15.30 USD (at a rate of 152.975 USD per ETH, retrieved at 10:52 PM from Coinbase)
[success] Total time: 3 s, completed Jan 2, 2019 10:53:33 PM
Hooray! Now we have some Ether to play around with.
To “ping” an address in sbt-ethereum just means to execute a transaction that “sends” 0 ETH. It’s mosty useful for testing purposes, to inexpensively verify that you can actually send from an account. Now that we have a funded account, let’s have it ping itself. Before we start, let’s go to Etherscan, and put our own address in the search field.
Etherscan doesn’t know anything about our address alias default-sender
.
We have to put in our full hex address, rather than the aliases we might use to refer to addresses in sbt-ethereum
.
If you have been following these tutorials in order, you’ll see just one transaction associated with your address, the transaction that funded your account.
Now let’s ping! The command we’ll want is ethTransactionPing
. (Tab completion will get you there with ethT<tab>P<tab>
.) You can specify an address to which you mean to direct a transaction, but by default ethTransactionPing
will cause a sender address to ping itself.
sbt:eth-command-line> ethTransactionPing
[info] No recipient address supplied, sender address '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' will ping itself.
[info] Unlocking address '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' (on chain with ID 1, aliases ['default-sender'])
Enter passphrase or hex private key for address '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2': ***************
[info] V3 wallet(s) found for '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' (aliases ['default-sender'])
==> T R A N S A C T I O N R E Q U E S T
==>
==> The transaction would be a message with...
==> To: 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2 (with aliases ['default-sender'] on chain with ID 1)
==> From: 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2 (with aliases ['default-sender'] on chain with ID 1)
==> Data: None
==> Value: 0 Ether
==>
==> The nonce of the transaction would be 0.
==>
==> $$$ The transaction you have requested could use up to 25200 units of gas.
==> $$$ You would pay 8 gwei for each unit of gas, for a maximum cost of 0.0002016 ether.
==> $$$ This is worth 0.0308095200 USD (according to Coinbase at 11:53 PM).
Would you like to submit this transaction? [y/n] y
A transaction with hash '0x6a29ce4709fac48bb6e7e4e140815b1bccfb646c2d605b53f616ee5d8663be46' will be submitted. Please wait.
[info] Sending 0 wei to address '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' in transaction '0x6a29ce4709fac48bb6e7e4e140815b1bccfb646c2d605b53f616ee5d8663be46'.
[info] Waiting for the transaction to be mined (will wait up to 5 minutes).
[info] Transaction Receipt:
[info] Transaction Hash: 0x6a29ce4709fac48bb6e7e4e140815b1bccfb646c2d605b53f616ee5d8663be46
[info] Transaction Index: 138
[info] Transaction Status: SUCCEEDED
[info] Block Hash: 0xbea508aec03300880ccb3d7eb8c7478930f00ca58ff92b1125b0970186ca2e30
[info] Block Number: 7002247
[info] From: 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2
[info] To: 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2
[info] Cumulative Gas Used: 7075671
[info] Gas Used: 21000
[info] Contract Address: None
[info] Logs: None
[info] Events: None
[info] Ether sent.
[info] Ping succeeded!
[info] Sent 0 ether from '1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' to itself in transaction '0x6a29ce4709fac48bb6e7e4e140815b1bccfb646c2d605b53f616ee5d8663be46'
[success] Total time: 50 s, completed Jan 2, 2019 11:53:57 PM
Now if we check Etherscan, voila, we find a new transaction (with a value of 0 Ether) has appeared! So exciting.
Notice that our account balance has dropped just a bit from the 0.1 Ether we started with. The (useless) Ethereum transaction we’ve executed will forever be a part of the Ethereum blockchain, and modifying the blockchain always costs. We paid 0.000168 Ether (about 2.6¢ at current prices) for the privilege.
Besides paying transaction fees, Ether is a cryptocurrency, which we can send between accounts to make payments or for other purposes. We’d like to try that, but we’ll need another address to play with. So let’s make one.
The command we’ll want is ethWalletKeystoreV3Create
, which is long, but you’ll find that ethW<tab>K<tab>C<tab>
will get you there.
sbt:eth-command-line> ethKeystoreWalletV3Create
[info] Generated keypair for address '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d'
[info] Generating V3 wallet, alogorithm=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/testuser/Library/Application Support/sbt-ethereum'. Please backup, via 'ethShoeboxBackup' or manually.
[info] Consider validating the wallet using 'ethKeystoreWalletV3Validate 0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d'.
[success] Total time: 14 s, completed Jan 3, 2019 12:21:48 AM
We might try doing as that command suggested, and verifying that we can access the address.
sbt:eth-command-line> ethKeystoreWalletV3Validate 0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d
[info] V3 wallet(s) found for '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d'
Enter passphrase or hex private key for address '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d': ***************
[info] A wallet for address '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d' is valid and decodable with the credential supplied.
[success] Total time: 6 s, completed Jan 3, 2019 12:26:44 AM
It’s annoying to cut and paste long hex addresses, so let’s give our new address an alias.
sbt:eth-command-line> ethAddressAliasSet secondary-address 0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d
[info] Alias 'secondary-address' now points to address '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d' (for chain with ID 1).
[info] Refreshing caches.
[success] Total time: 0 s, completed Jan 3, 2019 12:32:52 AM
If you forget the passphrase you’ve just set for this new address, or if you lose the wallet file sbt-ethereum has just generated, you will permanently lose access to all value held by your new account.
If you intend to let the new address manage significant value, be sure to store your passphrase safely.
Also, consider backing up the sbt-ethereum “shoebox” now, which contains (among other things) the wallet files sbt-ethereum manages. The command would be ethShoeboxBackup
.
Whenever we want to interact with the blockchain, we want to be sure to know from which account we would be interacting. We can always check:
sbt:eth-command-line> ethAddressSenderPrint
[info] The current effective sender address is '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' (with aliases ['default-sender'] on chain with ID 1).
[info] + This value is the default sender address defined in the sbt-ethereum shoebox for chain with ID 1.
[info] + It has not been overridden with a session override or by an 'ethcfgAddressSender' setting in the project build or the '.sbt' folder.
[success] Total time: 0 s, completed Jan 3, 2019 12:40:05 AM
Unsurprisingly, the current sender (since we haven’t done anything to change it) is the default sender we set up at the very start of these tutorials. Cool.
We’ve seen the ethAddressBalance
command before. Previously, we just typed the command. By default it checked the current sender account’s balance. But we can also explicitly specify the address we want to check.
sbt:eth-command-line> ethAddressBalance default-sender
0.099832 ether (as of the latest incorporated block, address 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2)
This corresponds to approximately 15.17 USD (at a rate of 151.945 USD per ETH, retrieved at 12:38 AM from Coinbase)
[success] Total time: 0 s, completed Jan 3, 2019 12:42:55 AM
sbt:eth-command-line>
sbt:eth-command-line> ethAddressBalance secondary-address
0 ether (as of the latest incorporated block, address 0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d)
This corresponds to approximately 0.00 USD (at a rate of 151.945 USD per ETH, retrieved at 12:38 AM from Coinbase)
[success] Total time: 0 s, completed Jan 3, 2019 12:43:01 AM
Address aliases tab complete just like commands.
Instead of typing out “default-sender” or “secondary-address”, you can just type d<tab>
or s<tab>
.
The command to send Ether is ethTransactionEtherSend
. Let’s tab-complete it:
sbt:eth-command-line> ethTransactionEtherSend
<ens-name>.eth <recipient-address> default-sender fortune secondary-address
Ether will be sent from the current sender. The command asks for a <recipient-address>
, the address to which you mean to send.
We want to send to our new address. So, tab-completing again…
sbt:eth-command-line> ethTransactionEtherSend secondary-address
<amount>
After we specify the address to which we mean to send, we have to specify how much we wish to send. Let’s send 0.01 Ether (about $1.50 US at this writing). Let’s type 0.01 and tab-complete again.
sbt:eth-command-line> ethTransactionEtherSend secondary-address 0.01
ether finney gwei szabo wei
To specify an amount, it’s not enough to provide a number, you’ll need to provide a unit. Usually we specify amounts in terms of Ether, but one Ether is really 1018 Wei. One Wei is the minimum amount that the Ethereum blockchain tracks, representing a very tiny amount of value.
We wanted to spend 0.01 Ether, so our command will be:
sbt:eth-command-line> ethTransactionEtherSend secondary-address 0.01 ether
[info] Unlocking address '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' (on chain with ID 1, aliases ['default-sender'])
Enter passphrase or hex private key for address '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2': ***************
[info] V3 wallet(s) found for '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' (aliases ['default-sender'])
==> T R A N S A C T I O N S U B M I S S I O N R E Q U E S T
==>
==> The transaction would be a message with...
==> To: 0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d (with aliases ['secondary-address'] on chain with ID 1)
==> From: 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2 (with aliases ['default-sender'] on chain with ID 1)
==> Data: None
==> Value: 0.01 Ether
==>
==> The nonce of the transaction would be 2.
==>
==> $$$ The transaction you have requested could use up to 25200 units of gas.
==> $$$ You would pay 3.5 gwei for each unit of gas, for a maximum cost of 0.0000882 ether.
==> $$$ This is worth 0.0132092730 USD (according to Coinbase at 1:08 AM).
==> You would also send 0.01 ether (1.49765 USD), for a maximum total cost of 0.0100882 ether (1.5108592730 USD).
Would you like to submit this transaction? [y/n] y
A transaction with hash '0x29316bdadd220baeece57467a326669eecdd59b52929f013513b0e91cdfd8737' will be submitted. Please wait.
[info] Sending 10000000000000000 wei to address '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d' in transaction '0x29316bdadd220baeece57467a326669eecdd59b52929f013513b0e91cdfd8737'.
[info] Waiting for the transaction to be mined (will wait up to 5 minutes).
[info] Transaction Receipt:
[info] Transaction Hash: 0x29316bdadd220baeece57467a326669eecdd59b52929f013513b0e91cdfd8737
[info] Transaction Index: 148
[info] Transaction Status: SUCCEEDED
[info] Block Hash: 0xc8362f18196ab0986a31f63e5db81756b0c1fd91b126a122d338bd351a99b9dd
[info] Block Number: 7002534
[info] From: 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2
[info] To: 0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d
[info] Cumulative Gas Used: 7708470
[info] Gas Used: 21000
[info] Contract Address: None
[info] Logs: None
[info] Events: None
[info] Ether sent.
[success] Total time: 114 s, completed Jan 3, 2019 1:10:22 AM
Now let’s check the balance of secondary-address
:
sbt:eth-command-line> ethAddressBalance secondary-address
0.01 ether (as of the latest incorporated block, address 0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d)
This corresponds to approximately 1.50 USD (at a rate of 149.835 USD per ETH, retrieved at 1:16 AM from Coinbase)
[success] Total time: 0 s, completed Jan 3, 2019 1:17:23 AM
Hooray!
By default, your sbt-ethereum installation will use the address that is your default sender. You can always find what address that is via ethAddressSenderDefaultPrint
.
sbt:eth-command-line> ethAddressSenderDefaultPrint
[info] The default sender address for chain with ID 1 is '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2'.
[success] Total time: 0 s, completed Jan 3, 2019 1:22:50 AM
For now, the default sender is the same as the current sender. As we’ve seen, we can find the current sender with:
sbt:eth-command-line> ethAddressSenderPrint
[info] The current effective sender address is '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' (with aliases ['default-sender'] on chain with ID 1).
[info] + This value is the default sender address defined in the sbt-ethereum shoebox for chain with ID 1.
[info] + It has not been overridden with a session override or by an 'ethcfgAddressSender' setting in the project build or the '.sbt' folder.
[success] Total time: 0 s, completed Jan 3, 2019 1:28:35 AM
But your default sender can of course be overridden. Let’s try ethAddressSenderOverrideSet
. Using tab completion to help with the address argument:
sbt:eth-command-line> ethAddressSenderOverrideSet
<address-hex> <ens-name>.eth default-sender fortune secondary-address
sbt:eth-command-line> ethAddressSenderOverrideSet secondary-address
[info] Sender override set to '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d' (on chain with ID 1, aliases ['secondary-address'])).
[success] Total time: 0 s, completed Jan 3, 2019 1:29:36 AM
Now if we check the current sender, we’ll see…
sbt:eth-command-line> ethAddressSenderPrint
[info] The current effective sender address is '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d' (with aliases ['secondary-address'] on chain with ID 1).
[info] + This value has been explicitly set as a session override via 'ethAddressSenderOverrideSet'.
[info] + It has overridden a default sender address for chain with ID 1 set in the sbt-ethereum shoebox: '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' (with aliases ['default-sender'] on chain with ID 1)
[success] Total time: 0 s, completed Jan 3, 2019 1:32:15 AM
We can send now, and the Ether will be taken from this new sender address, rather than our default sender. Let’s send back some of the Ether we just sent to the secondary address.
sbt:eth-command-line> ethTransactionEtherSend default-sender 0.005 ether
[info] Unlocking address '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d' (on chain with ID 1, aliases ['secondary-address'])
Enter passphrase or hex private key for address '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d': ***************
[info] V3 wallet(s) found for '0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d' (aliases ['secondary-address'])
==> T R A N S A C T I O N S U B M I S S I O N R E Q U E S T
==>
==> The transaction would be a message with...
==> To: 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2 (with aliases ['default-sender'] on chain with ID 1)
==> From: 0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d (with aliases ['secondary-address'] on chain with ID 1)
==> Data: None
==> Value: 0.005 Ether
==>
==> The nonce of the transaction would be 0.
==>
==> $$$ The transaction you have requested could use up to 25200 units of gas.
==> $$$ You would pay 3 gwei for each unit of gas, for a maximum cost of 0.0000756 ether.
==> $$$ This is worth 0.0111634740 USD (according to Coinbase at 1:36 AM).
==> You would also send 0.005 ether (0.738325 USD), for a maximum total cost of 0.0050756 ether (0.7494884740 USD).
Would you like to submit this transaction? [y/n] y
A transaction with hash '0xe4a0eb26ad4290bc393a8e9626510fefb20324549dd04923209a0a8eef63338e' will be submitted. Please wait.
[info] Sending 5000000000000000 wei to address '0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2' in transaction '0xe4a0eb26ad4290bc393a8e9626510fefb20324549dd04923209a0a8eef63338e'.
[info] Waiting for the transaction to be mined (will wait up to 5 minutes).
[info] Transaction Receipt:
[info] Transaction Hash: 0xe4a0eb26ad4290bc393a8e9626510fefb20324549dd04923209a0a8eef63338e
[info] Transaction Index: 98
[info] Transaction Status: SUCCEEDED
[info] Block Hash: 0x19d66288e21a7f4c33a37a59d6af67b963cbd168853982e3cac18335a3d87ffe
[info] Block Number: 7002643
[info] From: 0x13e3d8d785cdeb1d18f298dcf07ea35a659e157d
[info] To: 0x1144f4f7aad0c463c667e0f8d73fc13f1e7e86a2
[info] Cumulative Gas Used: 7991842
[info] Gas Used: 21000
[info] Contract Address: None
[info] Logs: None
[info] Events: None
[info] Ether sent.
[success] Total time: 219 s, completed Jan 3, 2019 1:39:51 AM
It worked!
If you are following along at home, check your account balances, or look up your accounts on Etherscan to verify that the transactions and results are as they should be. (But remember that your sending account will always be charged a bit more than you sent! You have to pay transaction fees. In the lingo, you have to pay “for gas”.)
You can interact at any time, from any account you wish. Just use ethAddressSenderOverrideSet
to define the sender account.