Write a Raw Transaction and Post to algod REST Server

This tutorial works with a private network. 

Prerequisites tutorials: 

1) creating private network tutorial

2) creating a new Wallet tutorial 

3) creating a new account and participation key

See Using the REST APIs for an overview of Algorand API calls that are available via a REST interface.

With Algorand's kmd process, developers can create a signed transaction and write it to disk. This signed transaction can then be posted to the blockchain using a node that is running the algod process. In order to do this, you need to have the kmd process running on a machine that has access to the wallet and sign the transaction which can be output to a file. You can then submit the raw transaction to a network using the algod REST endpoint on any node in the Algorand network that you have the API token for. This tutorial shows how this can be done with a private network. 

 

Create the Private Network

See the creating private network tutorial for details on the network template.

goal network create -r ~/net1 -n private -t <path_to_template.json>

Start the Network

You can check that the status of the network is working by running the following command:

goal network status -r ~/net1

Create a Raw Transaction

See the tutorial on creating a new account to add an account to use for the ToAccount variable. Use the one account with tokens in the Primary wallet for the FromAccount variable. Also, you can get a listing of accounts using

goal account list -d ~/net1/Primary

And

goal account list -d ~/net1/Primary -w unencrypted-default-wallet

Creating a raw transaction can be done by running the following goal command:

goal clerk send -s -o ./raw.tx -a 102000 -f [FromAccount] -t [ToAccount] -d ~/net1/Primary -w unencrypted-default-wallet

The send command above will write out the raw transaction to disk. The -s flag specifies that the transaction is signed. You can push this raw data using the algod REST /v1/transactions path. This can be done with any language but for this example, we will just use curl to post it to the local private network.

curl -s -X POST --data-binary "@./raw.tx" -H "X-Algo-API-Token: $(cat ~/net1/Primary/algod.token)" "http://$(cat ~/net1/Primary/algod.net)/v1/transactions" 

The above command uses two cat statements to open files in the Primary nodes data directory. These two files hold the API token and IP and port endpoints. 

Shutdown and Delete the Private Network

In order to prevent multiple copies of the Algorand processes from running, you may want to shut down and delete the private network when you are finished testing. To do this run the following commands:

goal network stop -r ~/net1
goal network delete -r ~/net1