The open-source, command-line tools inspect the Algorand blockchain, and also compose, sign, and submit transactions to Algorand. See https://www.algorand.com/.
Install
go get src.d10.dev/algo/cmd/...
Configure
Algo tools require an algod
node. Set up the node first, then put the
connection details into file $HOME/.config/algo/algo.cfg
. For example if
Algorand has provided you a token to use with the "hackathon" testnet node,
the file looks like this:
[algod]
address = http://hackathon.algodev.network:9100
token = _PASTE_TOKEN_HERE_
Using a testnet node is recommended to follow the tutorial below. When the time comes to use mainnet, your algo.cfg might look like this:
[algod]
address = https://api.algoexplorer.io
Tutorial
Here's a description of how to send algos from one account to another.
First, create two accounts:
algo-key generate -count=2
The algo-key generate
operation saves secret key information to two files
named ADDRESS.algo-key. These contain private key information, so do not
share them with anyone. Don't move or rename the files, as algo-key
will
find them by address when signing later in the tutorial.
Next, create a (paper) backup of the private key information:
algo-key backup -nick DEMO *.algo-key
This command runs interactively, you will be prompted on the command line.
When shown the secret mnemonic, write it down and store the copy securely.
(Optionally, skip writing down the mnemonic for testnet accounts; however,
do run algo-key backup
because doing so create additional configuration
files.)
The "-nick DEMO" argument gives the new accounts nicknames. This will make
them easy to refer to. In this example, two configuration files "DEMO1.cfg"
and "DEMO2.cfg" should be created by algo-key backup
. These configuration
files include newly created public addresses. The ".cfg" files are not
secrets, the ".algo-key" files are secrets.
Next, move the address configuration files where algo
can find them:
mv *.cfg $HOME/.config/algo/
Check the balances on these accounts. They are brand new, you will see zero algos.
algo account DEMO1 DEMO2
Note that the "-v" flag makes algo
more verbose. Try:
algo -v account DEMO1
to see the entire address of the account with nicknam "DEMO1". Copy the full address. If using testnet, visit the Algorand testnet faucet. Paste the address there to receive testnet algos.
At this point, you should have a balance of algos in DEMO1 account. The remainder of this tutorial constructs a payment to send ten algos from DEMO1 to DEMO2.
Use algo payment
to compose a pay transaction:
algo -as DEMO1 payment DEMO2 10
Note that "-as ADDRESS" is a flag on the algo
command that specifies which
account must sign the transaction. In the case of payment, it is the
originating account. The next argument, payment
, is the "operation" of the
algo
command; in this case, construct a payment transaction. The final
arguments specify the beneficiary "DEMO2" and the amount, 10 algos.
The output of algo payment
is a JSON-encoded transaction. The details are
not important, but if you're curious, you can inspect the output and see the
amount field (note that it is micro-algos), the transaction fee, and all the
other details. Address are encoded differently in the JSON, so don't be
surprised not to see the full address of DEMO1 or DEMO2.
Note that algo payment
composed a transaction but did nothing else. To
complete the payment, we must sign and submit the transaction. In Algo
tools, the compose, sign, and submit steps are three distinct operations.
This allows signing to be isolated to a secure environment. For convenience
though, the three steps can be "pipelined" together, and that's what we'll
do next:
algo -as DEMO1 payment DEMO2 10 | algo-key sign | algo submit
The above pipeline composes a transaction, exactly as before. The
JSON-encoded transaction is sent to algo-key sign
, which adds a signature.
To do so, algo-key
must find the ".algo-key" file that was created
earlier. Finally the transaction with signature is sent to algo submit
,
which broadcasts the transaciton to our algod
node, and from there to the
entire network.
Lastly, check that our account balances have changed. You should see that DEMO2 now has a positive balance:
algo account DEMO1 DEMO2
Note that algo
can compose other transaction types, which can be signed
and submitting as described above. See algo -h
for a description of all
supported operations.
Command algo
Operation assetconfig
Configure an Algorand Standard Asset. See https://developer.algorand.org/docs/asa
Operation assetcreate
Creates an Algorand Standard Asset. See https://developer.algorand.org/docs/asa
Operation assettransfer
Compose an Asset Transfer Transaction, to send Algorand Standard Assets from one account to another.
The composed transaction is unsigned. See algo-key sign
to sign, and algo
submit
to publish after signing.
Operation payment
Compose a pay
transaction, to send Algos from one account to another.
Operation submit
Submit one (or more) signed transactions.
Optional arguments are files containing JSON-encoded signed transactions
(output of algo-key sign
).
If no arguments, algo submit
expects JSON-encoded signed transaction(s) on
stdin.
Operation backup
Shows a secret key, encoded as mnemonic string. The shown string can be written or copied as a (paper) backup of the secret key.
Command algo-key
Usage:
algo-key [FLAGS...] OPERATION [OPFLAGS...]
Operation generate
The generate
operation creates a new keypair. The public address and
private mnemonic are saved to the a file. The file saved is named after
the public address: "ADDRESS.algo-key".
Operation genmulti
Creates multisign addresses for Algorand.
A multisign address is produced by combining several Algorand addresses.
This operation expects a list of addresses on stdin. If you have multiple
address in .cfg files, as produced by algo-key backup
, you can generate a
multisign address with:
grep "address" *.cfg | algo-key genmulti -m 2 -n 3
(algo-key will use a regexp to parse addresses from the results of grep
.)
Operation sign
Signs Algorand transaction(s).
Optional arguments are files, containing JSON-encoded transactions to sign.
If no arguments, JSON-encoded transactions are expected on stdin.
Use the "-as ADDRESS" flag to algo-key
to specific a signing key. This is
required when producing multi-signatures. For single signatures, algo-key
attempt to learn the signing key from the transaction.
algo-key
expects to find private keys in a files named "ADDRESS.algo-key",
in the format produced by algo-key generate
.