stacks-archive / stacks-transactions-js

The JavaScript library for generating Stacks 2.0 transactions
19 stars 17 forks source link

Async builder function signatures #44

Closed yknl closed 4 years ago

yknl commented 4 years ago

This PR makes the transaction builder functions async. This is to enable automatic handling of nonce values in the future. The nonce value will be retrieved from a core node API and requires a network request.

Builder functions affected: makeSTXTokenTransfer makeSmartContractDeploy makeContractCall

New usage example:

const transaction = await makeSTXTokenTransfer(...);

or

makeSTXTokenTransfer(...).then((transaction) => {
  // do something with transaction
});

Type of Change

Does this introduce a breaking change?

Yes makeSTXTokenTransfer makeSmartContractDeploy makeContractCall

Are documentation updates required?

Yes.

Testing information

npm run test

Checklist

kyranjamie commented 4 years ago

Is there a use case in which a consumer would want to manage the nonce themselves, for some reason, and thus circumvent the request, thus needing something like makeSTXTokenTransferSync?

yknl commented 4 years ago

Is there a use case in which a consumer would want to manage the nonce themselves, for some reason, and thus circumvent the request, thus needing something like makeSTXTokenTransferSync?

Yes I think that's a valid use case. We should be able to add that option.

hstove commented 4 years ago

Yeah - I find this change unnecessary for my use case. If we do add support for automatic fetching of nonce, then we should do so in a separate function. I don't want this library to handle nonce fetching (for the authenticator's use case), because that can run into issues when you have multiple unconfirmed TXs.

yknl commented 4 years ago

Sounds like we'd prefer to keep the transaction builder functions synchronous and have separate async nonce and fee estimation functions. Going to close this PR for now.