Sign not working due to non base 58 character

Hi there,

I am trying to create a spendTx transaction, i’ve done so both through the ‘/debug/transactions/spend’ endpoint as well as through the new Transaction().spendTx() SDK function. Both functions return a string in the format tx_+EsMAaEBuaOJ/QXTInlxWiHEiC+GIjABsRmJIot9Ou2vsUjvkdqhAYOExyyB2qUAYqPCJkecKeea9JGT9jdP4vbY2Gzq+TyNCgEBAIBQtJf4

Once i try to sign the transaction according to https://github.com/aeternity/aepp-sdk-js/blob/develop/docs/examples/node/aecrypto.md#transaction-signing . I get the error Error: Non-base58 character. (which is correct the + and / characters are not included in base58, this looks like base64). I’ve tried replacing “const binaryTx = Crypto.decodeBase58Check(base58CheckTx)” with “const binaryTx = Crypto.decodeBase64Check(base58CheckTx)”, but this resulted in an invalid tx.
Any idea what i can do to make this work?

The transaction (prefixed tx_) is indeed Base64Check encoded. Your transaction looks just fine to me:

24> {_, TX} = aeser_api_encoder:decode(<<"tx_+EsMAaEBuaOJ/QXTInlxWiHEiC+GIjABsRmJIot9Ou2vsUjvkdqhAYOExyyB2qUAYqPCJkecKeea9JGT9jdP4vbY2Gzq+TyNCgEBAIBQtJf4">>).
{transaction,<<248,75,12,1,161,1,185,163,137,253,5,211,
               34,121,113,90,33,196,136,47,134,34,48,1,
               177,25,137,...>>}
25> aetx:deserialize_from_binary(TX).                                                                                                                         
{aetx,spend_tx,aec_spend_tx,77,
      {spend_tx,{id,account,
                    <<185,163,137,253,5,211,34,121,113,90,33,196,136,47,134,
                      34,48,1,177,...>>},
                {id,account,
                    <<131,132,199,44,129,218,165,0,98,163,194,38,71,156,41,
                      231,154,244,...>>},
                10,1,1,0,<<>>}}

But unfortunately I don’t know enough about the SDK to point you to the right functions there. The linked instructions seems to be missing the step where you add the network_id to the serialized transaction, but again the SDK is uncharted territory for me… Maybe @nduchak.chain can clarify?

Hey @Kenyre, please take a look at this method.
This is exactly the place where signing happens https://github.com/aeternity/aepp-sdk-js/blob/develop/es/account/index.js#L40. Also, you can take a look on the guide for low-lvl usage. But still I recommend you to use hight LVL SDK API for that.
https://github.com/aeternity/aepp-sdk-js/blob/develop/docs/examples/node/aecrypto.md#transaction-signing this doc is deprecated and will be fixed soon

1 Like

thanks a lot for the reply!
When using https://github.com/aeternity/aepp-sdk-js/blob/develop/docs/guides/low-vs-high-usage.md#low-level-sdk-usage-use-api-endpoints-directly i get the error “There must be spendTx in this stamp methods” maybe because my internal endpoint is wrongly formatted? (debug is enabled in the .yaml) I use the following endpoints:
let url = ‘http ://localhost:3013’
let internalUrl = ‘http ://localhost:3113’
(spaces in url because i wasnt allowed to post more than 2 urls)
The error arises before anything is done on the spendTx, so i recon it is due to wrong settings.

I’ll try building my own sign from the other url you provided. Problem is i don’t want any of the private keys stored in the node (i have my own database for keys). Do you know if using the Account({}) from the SDK places the keys in some sort of keystore?

SO basically SDK is storing your keys in memory if you need to store your keys in the database you probably can use the keystore from SDK for that. The question is why are you not using high-lvl API of SDK?
If you don’t want to store you privateKey in SDK then you need to provided using onAccount option for each operation

const sdkInstance = await Universal({ ... }) // 
await sdkInstance.spend(amount, recipient, { onAccount: { secretKey: 'YOUR_PRIV', publicKey: 'YOUR_PUB' } })

I am not using the high level SDK, since with most coins this means your keys are stored in the local keystore. My database where i store the keys is more secure than the node where the syncing is done. Furthermore the format for saving userData has to be the same over all different coins.

I’ll try it with the onAccount, thanks for the support.

1 Like

Can you elaborate further please? The official erlang node does not use or store any account keys. I assume you’re referring to it as you wrote “where syncing is done”.

1 Like