clarity-lang / reference

The Clarity Reference
149 stars 34 forks source link

return values to js from write function calls #51

Closed kelseyp99 closed 1 year ago

kelseyp99 commented 2 years ago

Allow Smart Contract Function Call from Stacks.js to return values. Currently, there are write functions and read-only functions but not both. Values such as the last token number should able to be returned inside the transaction object.

const transaction = await makeContractCall(txOptions);' console.log('My Return values are: ${transaction.payload.returnvalues}`);

Or provide a way to obtain the results value by calling a read function passing only the transaction id and returning the results associated with that transaction

obycode commented 1 year ago

When creating a contract call in stacks.js, you are submitting the transaction to the mempool, and the return value is the transaction ID. It doesn't return the response, because the execution of the transaction will happen at some unknown later time. You can then use the websockets or socket.io interfaces to subscribe to that transaction, or you can later query the API for that transaction. If you have any questions, please submit an issue in the stacks.js repo.