[Solved] Building and signing raw transactions

We are trying to make an offline “wallet” for our Æepp where we would sign transactions received from raw data.

It would be immensely useful if we could get an example of how to build a raw transaction with all parameters and their respectful encodings.

We wanted to use libsodium for signing and are wondering which curve is used for signing.

Hey Mislav,

You can use the js-sdk to do this. You can use the TxBuilder to build the transaction and after that Account for signing the transaction. I also think that Universal has the above options.

Hope that helps,
Martin

1 Like

Hey Martin,

It’s useful, but we are more interested in how the transaction data itself looks and which curves are used for signing. We’d like to do the signing ourselves without importing the SDK or communicating with the node.

What we need specifically is:

  • What data is needed for an aeternity transaction (to:, from:, nonce:, data:, etc… all the params basically)
  • How is this data formatted (.json?)
  • How is this data converted to a raw transaction
  • How is the raw transaction signed

Again, SDKs aren’t useful for us there since we need to develop it ourselves. I’ll give it a look at the SDKs how they did it, but I’d appreciate an answer still.

Thanks

Something like this https://github.com/aeternity/protocol/blob/master/serializations.md

But if we could be given concrete examples. These are a little bit difficult to follow

We use curve25519 for signatures.

The chain contains quite a number of examples :wink: The swagger definitions for the HTTP API could also give some hints.

1 Like

So would it be correct to assume that I use this:

"tx": { "amount": "14328000000000000000000", "fee": 20260, "nonce": 2, "payload": "", "recipientId": "ak_2tNbVhpU6Bo3xGBJYATnqc62uXjR8yBv9e63TeYCpa6ASgEz94", "senderId": "ak_RMi1xMFStLUvXamNCTXwkBS5RvYGdpXhBfirdcZqSzQAfk3ox", "ttl": 40152, "type": "SpendTx", "version": 1 }

and sign it with curve25519?

Also these are all spend transactions, I can’t find any exmples of contract calls in the block explorer. If you could provide an example of a contract call, that would be awesome! :slight_smile:

Thanks

I’ve found some contract call transactions

"tx":{
   "amount":0,
   "callData":"cb_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACBoPV8aKjz7jyvC9VB7SMH8SDmH6BPI7MqYTKloBqmOkwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC5RbVVYaDJmRFJKdTVQUDh3V3Z0VTU1VlBDZXJ1ekZKcGJCcVdQRkJQQUtLRVhoAAAAAAAAAAAAAAAAAAAAAAAAM4IA0Q==",
   "callerId":"ak_2BnpcMtnLMX1s2gUAKCdCQ2SMtsUPB2wt6bxVJuHxXiRPHHasz",
   "contractId":"ct_2ccJZsoN5D4iWuueX7k4HSTt3QxBGATqzRo1GfeGj2A5GHCTHr",
   "fee":2036620,
   "gas":1579000,
   "gasPrice":1,
   "nonce":2,
   "type":"ContractCallTx",
   "version":1,
   "vmVersion":"0x01"
}

What I’m wondering primarily now is how the callData parameter is encoded?

The callData is aevm bytecode encoded as base64 + added header + added checksum, this means for replicating sophia types as strings to respective encoded calldata needs a sophia compiler.

The standalone compiler (or deprecated node enpoint) provide this functionality using /encode-calldata.

This encoded calldata can then be used to assemble your raw transactions as defined in the contract call serialization protocol. This RLP encoded output binary can then be signed using curve25519.

To post your signed transaction to the blockchain it needs to be assembled and encoded using RLP as well.

The output will have to be encoded using base64 and and double-sha256 checksum to be added, and prefixed with tx_.

Then posted to the /transactions endpoint of a node.

2 Likes

Thank you @piwo ! This answers our question.

3 Likes