<divclass="link title"><ahref="/v5/">Documentation</a></div><divclass="base show link depth-1"><ahref="/v5/getting-started/">Getting Started</a></div><divclass="base show link depth-1"><ahref="/v5/concepts/">Ethereum Basics</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/events/">Events</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/gas/">Gas</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/security/">Security</a></div><divclass="base show link depth-1"><ahref="/v5/api/">Application Programming Interface</a></div><divclass="hide link depth-2"><ahref="/v5/api/contract/">Contract Interaction</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract/">Contract</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract-factory/">ContractFactory</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><divclass="hide link depth-2"><ahref="/v5/api/signer/">Signers</a></div><divclass="hide link depth-2"><ahref="/v5/api/providers/">Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/provider/">Provider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/api-providers/">API Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/other/">Other Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/types/">Types</a></div><divclass="hide link depth-2"><ahref="/v5/api/utils/">Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/abi/">Application Binary Interface</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/coder/">AbiCoder</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/formats/">ABI Formats</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/fragments/">Fragments</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/interface/">Interface</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/address/">Addresses</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/bignumber/">BigNumber</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/bytes/">Byte Manipulation</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/constants/">Constants</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/display-logic/">Display Logic and Input</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/encoding/">Encoding Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/fixednumber/">FixedNumber</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/hashing/">Hashing Algorithms</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/hdnode/">HD Wallet</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/logger/">Logging</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/properties/">Property Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/signing-key/">Signing Key</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/strings/">Strings</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/transactions/">Transactions</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/web/">Web Utilities</a></div><divclass="hide link depth-3"><ahref="/v5/api/utils/wordlists/">Wordlists</a></div><divclass="hide link depth-2"><ahref="/v5/api/other/">Other Libraries</a></div><divclass="hide link depth-3"><ahref="/v5/api/other/assembly/">Assembly</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/api/">Utilities</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></div><divclass="hide link depth-3"><ahref="/v5/api/other/hardware/">Hardware Wallets</a></div><divclass="hide link depth-2"><ahref="/v5/api/experiment
<divclass="breadcrumbs"><ahref="/v5/">Documentation</a> » <ahref="/v5/cli/">Command Line Interfaces</a> » <spanclass="current">Sandbox Utility</span></div>
<aname="sandbox-utility"></a><h1class="show-anchors"><div>Sandbox Utility<divclass="anchors"><aclass="self"href="/v5/cli/ethers/#sandbox-utility"></a></div></div></h1><p>The sandbox utility provides a simple way to use the most common ethers utilities required during learning, debuging and managing interactions with the Ethereum network.</p>
<p>If no command is given, it will enter a REPL interface with many of the ethers utilities already exposed.</p>
info [ TARGET ... ] Dump info for accounts, addresses and ENS names
send TARGET ETHER Send ETHER ether to TARGET form accounts[0]
[ --allow-zero ] Allow sending to the address zero
[ --data DATA ] Include data in the transaction
sweep TARGET Send all ether from accounts[0] to TARGET
sign-message MESSAGE Sign a MESSAGE with accounts[0]
[ --hex ] The message content is hex encoded
eval CODE Run CODE in a VM with ethers
run FILENAME Run FILENAME in a VM with ethers
wait HASH Wait for a transaction HASH to be mined
wrap-ether VALUE Deposit VALUE into Wrapped Ether (WETH)
unwrap-ether VALUE Withdraw VALUE from Wrapped Ether (WETH)
send-token TOKEN ADDRESS VALUE
Send VALUE tokens (at TOKEN) to ADDRESS
compile FILENAME Compiles a Solidity contract
[ --no-optimize ] Do not optimize the compiled output
[ --warnings ] Error on any warning
deploy FILENAME Compile and deploy a Solidity contract
[ --no-optimize ] Do not optimize the compiled output
[ --contract NAME ] Specify the contract to deploy
ACCOUNT OPTIONS
--account FILENAME Load from a file (JSON, RAW or mnemonic)
--account RAW_KEY Use a private key (insecure *)
--account 'MNEMONIC' Use a mnemonic (insecure *)
--account - Use secure entry for a raw key or mnemonic
--account-void ADDRESS Use an address as a void signer
--account-void ENS_NAME Add the resolved address as a void signer
--account-rpc ADDRESS Add the address from a JSON-RPC provider
--account-rpc INDEX Add the index from a JSON-RPC provider
--mnemonic-password Prompt for a password for mnemonics
--xxx-mnemonic-password Prompt for a (experimental) hard password
PROVIDER OPTIONS (default: all + homestead)
--alchemy Include Alchemy
--etherscan Include Etherscan
--infura Include INFURA
--nodesmith Include nodesmith
--rpc URL Include a custom JSON-RPC
--offline Dump signed transactions (no send)
--network NETWORK Network to connect to (default: homestead)
TRANSACTION OPTIONS (default: query network)
--gasPrice GWEI Default gas price for transactions(in wei)
--gasLimit GAS Default gas limit for transactions
--nonce NONCE Initial nonce for the first transaction
--yes Always accept Siging and Sending
OTHER OPTIONS
--wait Wait until transactions are mined
--debug Show stack traces for errors
--help Show this usage and exit
--version Show this version and exit
(*) By including mnemonics or private keys on the command line they are
possibly readable by other users on your system and may get stored in
your bash history file. This is NOT recommended.</div><aname="sandbox-utility--examples"></a><h2class="show-anchors"><div>Examples<divclass="anchors"><aclass="self"href="/v5/cli/ethers/#sandbox-utility--examples"></a></div></div></h2>
<aname="cliex-init"></a><divclass="code-title"><div>Creating New Wallets</div></div><divclass="code">/home/ethers> ethers init wallet.json
Creating a new JSON Wallet - wallet.json
Keep this password and file SAFE!! If lost or forgotten
it CANNOT be recovered, by ANYone, EVER.
Choose a password: ******
Confirm password: ******
Encrypting... 100%
New account address: 0x485bcC23ae2E5038ec7ec9b8DCB2A6A6291cC003
Saved: wallet.json
# If you are planning to try out the Ropsten testnet...
/home/ethers> ethers --network ropsten fund 0x485bcC23ae2E5038ec7ec9b8DCB2A6A6291cC003
Transaction Hash: 0x8dc55b8f8dc8076acded97f9e3ed7d6162460c0221e2769806006b6d7d1156e0</div><aname="cliex-send"></a><divclass="code-title"><div>Sending Ether and Tokens</div></div><divclass="code"># Sending ether
recid: 0</div><aname="cliex-scripting"></a><aname="sandbox-utility--examples--cliex-scripting"></a><h3class="show-anchors"><div>Scripting<divclass="anchors"><aclass="self"href="/v5/cli/ethers/#cliex-scripting"></a></div></div></h3><p>The <codeclass="inline">eval</code> command can be used to execute simple one-line scripts from the command line to be passed into other commands or stored in script environment variables.</p>
<divclass="code-title"><div>Get the formatted balance of an account</div></div><divclass="code">/home/ethers> ethers --network ropsten \
3.141592653589793238</div><divclass="code-title"><div>Get the current block number</div></div><divclass="code">/home/ethers> ethers --network rinkeby \
eval "provider.getBlockNumber()"
5761009</div><divclass="code-title"><div>Convert a Solidity signature to JSON</div></div><divclass="code">/home/ethers> ethers eval 'utils.Fragment.from(
"function balanceOf(address) view returns (uint)"
).format("json")' | json_pp
{
"inputs" : [
{
"type" : "address",
"name" : "owner"
}
],
"type" : "function",
"payble" : false,
"stateMutability" : "view",
"ouputs" : [
{
"type" : "uint256"
}
],
"name" : "balanceOf",
"constant" : true
}</div><divclass="code-title"><div>Compute a topic hash</div></div><divclass="code">/home/ricmoo> ethers eval 'id("Transfer(address,address,uint256")'
0xd99659a21de82e379975ce8df556f939a4ccb95e92144f38bb0dd35730ffcdd5</div><divclass="code-title"><div>Create a random mnemonic</div></div><divclass="code">/home/ricmoo> ethers eval 'Wallet.createRandom().mnemonic'
useful pond inch knock ritual matrix giggle attend dilemma convince coach amazing</div><aname="cliex-mnemonicpassword"></a><aname="sandbox-utility--examples--cliex-mnemonicpassword"></a><h3class="show-anchors"><div>Using Mnemonics (with a password)<divclass="anchors"><aclass="self"href="/v5/cli/ethers/#cliex-mnemonicpassword"></a></div></div></h3><p>All mnemonic phrases have a password, but the default is to use the empty string (i.e. <codeclass="inline">""</code>) as the password. If you have a password on your mnemonic, the <codeclass="inline">--mnemonic-password</code> will prompt for the password to use to decrypt the account.</p>
homestead></div><aname="cliex-mnemonicpassword-xxx"></a><aname="sandbox-utility--examples--cliex-mnemonicpassword-xxx"></a><h3class="show-anchors"><div>Using Mnemonics (with experimental memory-hard passwords)<divclass="anchors"><aclass="self"href="/v5/cli/ethers/#cliex-mnemonicpassword-xxx"></a></div></div></h3><p>The <codeclass="inline">--xxx-mnemonic-password</code> is similar to the <codeclass="inline">--mnemonic-password</code> options, which uses a password to decrypt the account for a mnemonic, however it passes the password through the <ahref="https://en.wikipedia.org/wiki/Scrypt">scrypt</a><i>password-based key derivation function</i> first, which is intentionally slow and makes a brute-force attack far more difficult.</p>
homestead></div><divclass="definition container-box warning"><divclass="term">Note</div><divclass="body"><p>This is still an experimental feature (hence the <codeclass="inline">xxx</code>).</p>
</div></div>
<divclass="footer">
<divclass="nav previous"><ahref="/v5/cli/"><spanclass="arrow">←</span>Command Line Interfaces</a></div>
<divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Last modified on June 12, 2020, 7:17pm.</div>