hirosystems / connect

A library for building excellent user experiences with Stacks.
https://connect.stacks.js.org
MIT License
77 stars 41 forks source link

openSTXTransfer - unable to set nonce in options #250

Closed unclemantis closed 2 years ago

unclemantis commented 2 years ago

I am trying to set up a token transfer with a suggested nonce using openSTXTransfer. I am able to set amount, recipient and memo but nothing else such as fee and nonce.

Open of my project requires nonce to be set by my node.js app.

Is there a different solution using the atacksjs library?

janniks commented 2 years ago

Does the tx need to be sent via connect (i.e. through the users' wallet) in the browser or will it be sent from a node.js app (server-side, script, or CLI) with the private-key/account known during runtime?

unclemantis commented 2 years ago

I am using a node.js app to manage a signedin account. I am currently using API calls using userSession.loadUserData().profile.stxAddress.testnet

What I am trying to do is display a button for the signed in wallet user to click to submit a TX with a nonce set by my node.js app. openSTXTransfer was the first solution that I stumbled across. Is a wallet popup required to confirm payload and broadcast the TX or is there another way? I discovered userSession.loadUserData().appPrivateKey

Bottom line is I am looking to broadcast a TX with a nonce set by the node.js app. It can be of any type, token transfer, contract deploy or contract call.

Please point me in the right direction. Thank you.

janniks commented 2 years ago

I don't think the wallet currently allows custom nonces and there is no other way of constructing the tx first and letting the wallet sign for security reasons.

Without using a browser-extension wallet, if you have access to the privateKey/seed, you can use this example to set a custom nonce using@stacks/transactions: https://github.com/hirosystems/stacks.js/tree/master/packages/transactions#stx-token-transfer-transaction

unclemantis commented 2 years ago

I don't think the wallet currently allows custom nonces and there is no other way of constructing the tx first and letting the wallet sign for security reasons.

Without using a browser-extension wallet, if you have access to the privateKey/seed, you can use this example to set a custom nonce using@stacks/transactions: https://github.com/hirosystems/stacks.js/tree/master/packages/transactions#stx-token-transfer-transaction

I did stumble across that and I tried the following options:

const txOptions = { recipient: 'ST2EB9WEQNR9P0K28D2DC352TM75YG3K0GT7V13CV', amount: "1000000", senderKey: privateKey, network: 'testnet', // for mainnet, use 'mainnet' memo: 'test stx token transfer', nonce: "33", // set a nonce manually if you don't want builder to fetch from a Stacks node fee: "3000", // set a tx fee if you don't want the builder to estimate anchorMode: AnchorMode.Any, };

I end up getting a 400 with:

transaction rejected TooMuchChaining

janniks commented 2 years ago

Hmm, not sure why this hits TooMuchChaining, I'll try to find out what that means.

Can you try setting amount, fee, and nonce as Integer rather than String? (Removing the ""s)

unclemantis commented 2 years ago

Hmm, not sure why this hits TooMuchChaining, I'll try to find out what that means.

Can you try setting amount, fee, and nonce as Integer rather than String? (Removing the ""s)

Thank you for looking into this. I just tried number instead of string and same response.

unclemantis commented 2 years ago

the reason_data says nonce is too far difference from suggest nonce or something like that. problem is the nonce is not correct and the address it returns is NOT the address I am sending from.

unclemantis commented 2 years ago

okay. I am figuring this out. sorry.