Create account and transfer tokens using terra web api?

Swagger UI (terra.dev)

How do you create a terra wallet account? or Transfer tokens?

  1. you don’t use an ‘api’ to create an wallet/account.

you first use something to create a private/public key pair ala terra-rust/terra-rust-api/src/keys at main · PFC-Validator/terra-rust · GitHub (make sure you have a good source of randomness), and don’t give anything about the key away with the exception of the ‘public’ key.

  1. to transfer tokens you will need the bank/send transaction
    see: terra-rust/bank.rs at main · PFC-Validator/terra-rust · GitHub for fields.
    this becomes a json message which then gets wrapped into a transaction.
    you will need to query the server for the account#/sequence# of the public key, and use those (with the chain-id) as fields when you sign the message with your private key.
    this piece of json (or protobuf) is then sent to LCD server

there are TFL supported APIs for JS (GitHub - terra-money/terra.js: JavaScript SDK for Terra, written in TypeScript) , Python.
I wrote the rust one, and I believe there is a java one.

most of them have wrapper functions to do the above… one thing that isn’t easily understood, and out of scope for most of the apis is private key storage.
Be careful with that section, especially if you intend to hold the private key on a machine that is open on the internet.

2 Likes

Thanks for the response.

Which endpoint is used to create an account?
https://lcd.terra.dev/swagger/#/

As for “sending tokens” I assume you would use the broadcast tx endpoint https://lcd.terra.dev/swagger/#/Service/BroadcastTx

Is there a request specification?

You don’t have to use an endpoint to create an account, just generate a private key locally with terra.js/terra.py .

You can find more info on the docs to send tokens Common examples — Terra Docs documentation

I’m using c#, do you have a tech spec on how extactly are the accounts created? (without using the python or JavaScript sdk)

You have to use some algorithms to sign transactions.
More info on the cosmos docs: Accounts | Cosmos SDK