-
Notifications
You must be signed in to change notification settings - Fork 106
[react]: add useSendTransaction hook #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This reverts commit 4fa027d.
…into useSendTransaction
🦋 Changeset detectedLatest commit: d9dce41 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@nickfrosty check this out once (my bad multiple commits in order to fix the changeset file) |
|
What's the benefit of using a mutation over something like |
|
@macalinao here we used |
GuiBibeau
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! Nice work on this hook 🎉
Just noticed a small naming issue: the parameter signature in line 19 should probably be wireTransaction or transaction instead.
Currently it's a bit confusing because:
- We're passing IN a transaction (base64 encoded)
- We're getting OUT a signature (the transaction ID)
Using signature for the input makes it seem like we're passing in a signature, when we're actually passing in the whole transaction. What do you think about renaming it?
|
@GuiBibeau thanks for the review i'll make sure all the changes which are reviewed will be added by tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea for this hook is good but the usage pattern is wrong...
Think about how a dev would actually use this hook as its currently written: you have to have the transaction already before even instantiating the hook. Which means you could only really uses this inside a guard component that has the transaction passed to it. That makes no sense.
Instead, developer usage should look something like this:
const { sendTransaction } = useSendTransaction({
config: {
encoding: "base64",
preflightCommitment: "confirmed",
skipPreflight: false,
},
});
const signature = await sendTransaction(...validTransaction);Please rework this hook to:
- rebase to master
- reword the hook as described above
- fix the imports in the files you added to use
.jsfile extensions (see the other hooks and typeset tests) - fix the incorrect readme entry (that does not even match how you would use this as currently written) to be correct for the updated usage
- remove your retry delay since it does not give users any flexibility of control
- remove your incorrect comment for
return the transaction signature as a base-64 encoded string. its aSignature, which is a base58 encoded string
edit: this hook also needs to support the options and config, similarly to how all the other hooks accept them.
|
@nickfrosty I'm doing all the changes you mentioned. questions: the edit you mentioned about the thought: it is good to have them globally by defining them in the |
tobeycodes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like no commits have been made since this comment so this is still a work in progress.
|
@tobeycodes #229 (comment) for this question can you give the clarity for me in this the types mentioned there are only for the useQuery hook they are not working for the useMutation which we are using in the sendTransaction. Thinking: to add these types in the sendTransaction hook itself. i need the clarification on this. |
tobeycodes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work.
question: can you give me an example when you would use sendTransaction instead of signAndSendTransaction?
| return { | ||
| ...mutation, | ||
| sendTransaction: mutation.mutateAsync, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request: if we rename mutateAsync we should also rename mutate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha it make sense i'll add that as send: mutation.mutate
| // Returns a transaction Signature | ||
| return response; | ||
| }, | ||
| mutationKey: [GILL_HOOK_CLIENT_KEY, "sendTransaction"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request: key should also include urlOrMoniker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problem:There is no scope to get this urlOrMoniker you have mentioned.
approach: we can add the network parameter in the inputs which has the rpc's like this
type SolanaNetwork = "devnet" | "mainnet-beta" | "testnet" | string; and in the inputs we can use this network?: SolanaNetwork; this makes the key unique
other than this not getting any approaches to make this unique
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JkrishnaD There is. Take a look at the other hooks that use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @tobeycodes, I’ve reviewed how other hooks are implemented, and I noticed that all of them include their input parameters (like address, mint, signature) in the queryKey/mutationKey to ensure uniqueness.
pattern for key looks like Key: [GILL_HOOK_CLIENT_KEY, "methodName", ...uniqueParams]
problem: Using urlOrMoniker to make the mutationkey unique doesn’t work. Multiple transactions can happen on the same network (mainnet, devnet, etc.), so the key would not be unique per transaction.
approach: We include the transaction itself in the hook inputs and in the mutationKey.
reasoning: This ensures each transaction has a unique key, following the same pattern as other hooks like useTransaction or useBalance. It guarantees correct caching, mutation states, and avoids collisions between different transactions.
| mutationFn: async (tx: SendTransactionArgument) => { | ||
| // The RPC method expects the base-64 encoded transaction as the first argument. | ||
| const response = await rpc | ||
| .sendTransaction(tx as Base64EncodedWireTransaction, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why not sendAndConfirmTransaction per the docs? https://www.gillsdk.com/docs/react/hooks/transactions#current-approach
request: can we remove type casting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using sendTransaction here is intentional, this hook is designed to send transactions non-blocking and handle confirmation separately for better UX and flexibility.
sendAndConfirmTransaction waits for full confirmation before returning, which would block the mutation response and delay UI updates. With sendTransaction, we can immediately return the signature and confirm in the background.
and we can't remove the type casting there without that we are getting the No overload error
| async function handleClick() { | ||
| try { | ||
| // Create a new transaction | ||
| const transaction = createTransaction(...); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: i could be wrong but I do not believe createTransaction returns Base64EncodedWireTransaction | string;. Is this correct?
| export function createTransaction< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you were right it doesn't returns the Base64EncodedWireTransaction but there is no other function in there returns the Base64EncodedWireTransaction.
approach: thinking to remove this and just keep the hook usage like structure of hook.
| ...(config), | ||
| }) | ||
| .send({ abortSignal }); | ||
| // Returns a transaction Signature |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request: lets remove comments like this throughout the pull request. the code itself expresses this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha i'll remove all the comments in the hook
tobeycodes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For @nickfrosty to review
Problem
Implement the sendTransaction call as a hook
Summary of Changes
as mentioned in #167 to create a sendTransaction hook i have done
useSendTransactioninhooks/send-transaction.tssend-transaction.ts- ensures type safety and correct response shapes for all supported encodingsreactpackageREADME.md