![npm package](https://badge.fury.io/js/send-ether.svg)
send-ether
A simple CLI tool for sending Ethereum ether using any of the following:
- A wallet's private key
- A keystore file
- An HD wallet mnemonic phrase
- A provider (node) wallet address
For the ERC20 token version of this package, check out
send-tokens.
Contents
Installation
npm install -g send-ether
yarn global add send-ether
Examples
DST='0x0420DC92A955e3e139b52142f32Bd54C6D46c023'
PRIVATE_KEY='0x52c251b9e04740157471a724e9a3210b83fac5834b29c89d5bd57661bd2a7057'
MNEMONIC='butter crepes sugar flour eggs milk ...'
$ send-ether --key $PRIVATE_KEY $DST 100.2
$ send-ether --network ropsten --mnemonic "$MNEMONIC" $DST 5.2 -d 9
$ send-ether --keystore './path/to/keystore.json' --password 'secret' $DST 10 -d 0
$ send-ether --provider 'http://localhost:8545' --confirmations 3 $DST 1.5
All Options
$ send-ether --help
Usage: send-ether [options] <to> <amount>
Options:
-v, --version output the version number
-d, --decimals <n> decimal places amount is expressed in (default: 18)
-k, --key <hex> sending wallet's private key
-f, --key-file <file> sending wallet's private key file
-s, --keystore-file <file> sending wallet's keystore file
--password <password> keystore file password
-m, --mnemonic <phrase> sending wallet's HD wallet phrase
--mnemonic-index <n> sending wallet's HD wallet account index (default: 0)
-a, --account <hex> sending wallet's account address (provider wallet)
-c, --confirmations <n> number of confirmations to wait for before returning (default: 0)
-p, --provider <uri> provider URI
-n, --network <name> network name
-G, --gas-price <gwei> explicit gas price, in gwei (e.g., 20)
-l, --log <file> append a JSON log to a file
--no-confirm bypass input confirmation
-h, --help output usage information
JSON Logs
If you pass the --log
option, a JSON object describing the transfer
will be appended to a file when the transaction is mined, one object per line.
Log Entries
Log entries follow this structure:
{
id: '88fdd8a4b8084c36',
time: 1532471209842,
from: '0x0420DC92A955e3e139b52142f32Bd54C6D46c023',
to: '0x2621Ea417659Ad69BAE66AF05eBE5788e533E5e8',
amount: '20',
txId: '0xd9255f8365305ebffd77cb30d09f82745eaa232e42739f5fc2788fa46f1347e3',
block: 4912040,
gas: 40120
}
ENS Names
Anywhere you can pass an address, you can also pass an ENS name, like
'ethereum.eth'
, and the it will automatically be resolved to a real
address.
ENS resolution only works on the mainnet, rinkeby, and ropsten, and the name
must be fully registered with the ENS contract and a resolver.
Library Usage
The send-ether
package can be used as a library through the sendEther()
function.
sendEther()
asynchronously resolves to a
transaction receipt
once the transaction has been mined (or confirmed, if the
confirmations
option is > 0).
sendEther() Examples
const {sendEther} = require('send-ether');
const RECIPIENT = '0x0420DC92A955e3e139b52142f32Bd54C6D46c023';
const PRIVATE_KEY = '0x52c251b9e04740157471a724e9a3210b83fac5834b29c89d5bd57661bd2a7057';
let receipt = await sendEther(RECIPIENT, '100.5',
{key: PRIVATE_KEY});
const MNEMONIC = 'butter crepes sugar flour eggs milk ...';
receipt = await sendEther(RECIPIENT, '32',
{mnemonic: MNEMONIC, confirmations: 3, decimals: 0});
const KEYSTORE = '{...}';
const PASSWORD = 'secret';
receipt = await sendEther(RECIPIENT, '20.1', {
keystore: KEYSTORE,
password: PASSWORD,
decimals: 9,
onTxId: console.log
});
Full sendEther() Options
const {sendEther} = require('send-ether');
{tx: Object} = async sendEther(
RECIPIENT: String,
AMOUNT: String,
{
quiet: Boolean,
log: String,
onTxId: Function,
decimals: Number,
account: String,
key: String,
mnemonic: String,
mnemonicIndex: Number,
keystore: String,
keystoreFile: String,
password: String,
network: String,
gasPrice: Number,
confirmations: Number,
infuraKey: String,
provider: String | Object,
web3: Object
});
toWallet()
Another exposed library function is toWallet()
, which returns an address
& private key pair from a private key, mnemonic, or keystore. Below are the
full options.
const {toWallet} = require('send-ether');
{address: String, key: String} = toWallet({
key: String,
mnemonic: String,
mnemonicIndex: Number,
keystore: String,
password: String
});