harmony-one / go-sdk

Go-SDK & CLI tool to interact with the Harmony Blockchain
https://docs.harmony.one/
43 stars 45 forks source link

[scripts] Add CSV transaction wrapper script #225

Closed Daniel-VDM closed 4 years ago

Daniel-VDM commented 4 years ago

Send transactions using the Harmony CLI from a CSV file

Install

0) (Optional) Open terminal and cd to wherever you want to install your CLI. Personally I like ~/bin.

mkdir -p ~/bin && cd ~/bin

1) Get the latest Harmony CLI version

curl -O https://raw.githubusercontent.com/harmony-one/go-sdk/master/scripts/hmy.sh && chmod +x ./hmy.sh && ./hmy.sh -d

2) Install the CSV parser script in the same directory

curl -O https://raw.githubusercontent.com/harmony-one/go-sdk/master/scripts/hmy-csv.py && chmod +x ./hmy-csv.py

Note that this will require python 3.6 or newer. You can check this with the following command python3 --version. 3) Create your CSV file (with numbers, excel, sheets, etc..), make sure to follow this template. Note that the follow column names must exist: from, to, amount, from-shard, to-shard, passphrase-file (optional), passphrase-string (optional), gas-price (optional). 4) Save/download the CSV file to your computer. If you are using MacOs and google sheets, your csv file will probably be in ~/Downloads. Note this for later.

Using the Script

MAKE SURE ALL from KEYS ARE IN THE CLI'S KEYSTORE. IMPORT KEYS FIRST IF NEEDED.

Reference docs here on how to import keystores into the CLI.

Basic (slow but safe)

1) Go do where you installed your CLI. If using my example in the install section, do cd ~/bin. 2) Run the script with the following command (for mainnet):

./hmy-csv.py ~/Downloads/some-file.csv --node https://api.s0.t.hmny.io/

Substitute ~/Downloads/some-file.csv with the path to your CSV file on your computer.

You can also substitute https://api.s0.t.hmny.io/ for whatever endpoint you want. 3) Respond to the prompts and make sure to check the parsed transactions before sending it!

Fast (does not check if a transaction has confirmed)

1) Go do where you installed your CLI. If using my example in the install section, do cd ~/bin. 2) Run the script with the following command (for mainnet):

./hmy-csv.py ~/Downloads/some-file.csv --fast --node https://api.s0.t.hmny.io/

Substitute ~/Downloads/some-file.csv with the path to your CSV file on your computer.

You can also substitute https://api.s0.t.hmny.io/ for whatever endpoint you want. 3) Respond to the prompts and make sure to check the parsed transactions before sending it!

Automation (for scripting on testnets)

1) Note where you saved the hmy-csv.py file. For me its:

~/go/src/github.com/harmony-one/go-sdk/scripts/hmy-csv.py

2) Run the script with the following command:

~/go/src/github.com/harmony-one/go-sdk/scripts/hmy-csv.py ~/Downloads/some-file.csv --use-default-passphrase --yes --fast --batch-size 25 --chain-id testnet -n http://3.231.157.246:9500/

Note that this just about shows every option one could need when using this script. Normally not all fields are needed.

Help

You can view all of the possible options and what they do with:

./hmy-csv.py --help