Signing & Sending Transactions
In order to send tokens from your address to another address using the API there are a few steps described below:
generate an unsigned transaction json
sign the generated unsigned transaction json
post the json to the transaction endpoint
Generating an unsigned transaction json
The first step is to use the API endpoint: https://mainnet.axentro.io/api/v1/transaction/send_token/unsigned by making a POST request with the json for the transaction:
You can get this information from your wallet. If you use the desktop wallet you can go to tools backup and it will produce a backup json that has this information. If you created your wallet using the cli tool axe
then it produces the same json as the desktop wallet.
for example given this wallet json:
You can see the address
and public_key
needed for the POST request mentioned above.
It is recommened to use FAST for the kind - this is the transaction kind and fast transactions are instant
the fee for sending a transaction is 0.0001 - The API has an endpoint that lists the fees
So now you can make a POST request to the endpoint https://mainnet.axentro.io/api/v1/transaction/send_token/unsigned
with the json mentioned above as the payload.
The request will return a response with a transaction json that you can sign and POST to make the actual transaction.
Signing the generated transaction json
The json returned from the api/v1/transaction/send_token/unsigned
endpoint should look similar to this:
You need to first remove all the line breaks and all the spaces between the json properties so that it looks like this:
Remove the surounding json for status and result and just take the payload in the result so you have just the payload of the json with all spaces and new lines removed. If you get this wrong the hash will not match and the transaction will be rejected with invalid signing.
Next you need turn the json above into a SHA256
hash and then sign it with your private key that you must convert from your WIF from your wallet json.
Getting a SHA256
The following example is using Javascript using the crypto-js
package crypto-js
Getting your private key from the WIF
In your wallet json next to the public key and address there is a wif. This is a wallet information format key that has the private key inside that is needed for signing.
Here is a function that would acheive this using the Javascript base64
package base64
Signing the transaction hash
Next sign the transaction hash with your private key. This example uses the ED25519 Javascript package elliptic
Elliptic
The private key is the one you got from the WIF and the message is the transaction_hash you made earlier. This funciton produces a signature which you then paste into the signature field of the sender
in the compact json and post to the transaction endpoint http://mainnet.axentro.io/api/v1/transaction
with the payload wrapped in a transaction
elements as follows:
This json payload does not need to be compacted and can have spaces and line breaks.
Last updated