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