Skip to content

Commit 5a01d40

Browse files
author
Jade Hamilton
committed
chore: add the links to the components for sdk and site
1 parent f592255 commit 5a01d40

File tree

10 files changed

+302
-44
lines changed

10 files changed

+302
-44
lines changed

account-kit/react/src/hooks/useSolanaSigner.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ export type SignerSet = {
2323
* This hook is used to create a SolanaSigner instance.
2424
* It is used to sign transactions and messages for the Solana blockchain.
2525
*
26+
* ```tsx
27+
* import { useSolanaSigner } from "@account-kit/react";
28+
*
29+
* const signer = useSolanaSigner({});
30+
* ```
31+
*
2632
* @param {object} opts - The options for the useSolanaSigner hook.
2733
* @param {SignerSet} [opts.signerSet] - The signer set to use.
2834
* @returns {object} A SolanaSigner instance.

account-kit/react/src/hooks/useSolanaTransaction.ts

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,75 @@ export type SolanaTransactionHookParams = {
6767
* This is the hook that will be used to send a transaction.
6868
*
6969
* @example
70-
* ```ts
71-
const {mutate} = useSolanaTransaction({
72-
policyId: "<policyId>",
73-
});
70+
* ```ts twoslash
71+
import React from "react";
72+
import { useSolanaTransaction } from "@account-kit/react";
73+
import { Connection } from "@solana/web3.js";
7474
75-
mutate({
76-
transfer: {
77-
amount: <amount:number>,
78-
toAddress: "<toAddress>",
79-
},
80-
* ```
75+
function MyComponent() {
76+
const connection = new Connection(
77+
"https://solana-devnet.g.alchemy.com/v2/<API_KEY>",
78+
{
79+
wsEndpoint: "wss://api.devnet.solana.com",
80+
commitment: "confirmed",
81+
}
82+
);
83+
const policyId = "<policyId>";
84+
85+
const {
86+
mutate: doTransaction,
87+
isPending,
88+
signer,
89+
reset,
90+
data: { hash: txHash = null } = {},
91+
} = useSolanaTransaction({
92+
connection,
93+
// Used if we have a alchemy sponsor
94+
policyId,
95+
});
96+
97+
if (!signer) {
98+
return <div>Loading alchemy signer...</div>;
99+
}
100+
101+
return (
102+
<div>
103+
Solana Address: {signer.address}
104+
<button
105+
onClick={() =>
106+
doTransaction({
107+
transfer: {
108+
amount: 1000000,
109+
toAddress: "<ToSolanaAddress>",
110+
},
111+
})
112+
}
113+
>
114+
{" "}
115+
Go make Transfer{" "}
116+
</button>
117+
{
118+
!!txHash &&
119+
<button onClick={() => reset()}> Reset </button>
120+
}
121+
{ !!txHash && <a href={`https://explorer.solana.com/tx/${txHash}?cluster=devnet`} target="_blank"> Go To Tracker </a> }
122+
</div>
123+
);
124+
}
125+
* ```
126+
*
127+
* This hook:
128+
*
129+
* - Signs the transaction and broadcasts it to the network via the Connection passed in
130+
* - Returns a mutate to fire and forget a transaction, either a transfer or list of web3 instructions
131+
* - Provides the state for the result of the txHash that results after the broadcast
132+
* - Has an isPending to know if the transaction is currently sending
133+
* - Has the signer, so we can see if we had provided an alchemy signer in the app. (A signer could have been passed in instead of provided)
134+
* - Has other onMutation hooks that could be passed in as the mutation: argument for the hook
135+
*
136+
* Note: This example assumes that the alchemy signer is defined higher up in the React tree. If this is not the case this transaction will not work. Instead, one could pass down the signer as a parameter for the hook
137+
* Note: This example uses the connection passed in, but there is a AlchemySolanaWeb3Context if we would like do input as a provider.
138+
*
81139
* @param {SolanaTransactionHookParams} opts Options for the hook to get setup, The transaction is required.
82140
* @returns {SolanaTransaction} The transaction hook.
83141
*/

docs/docs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ navigation:
149149
path: wallets/pages/reference/account-kit/react/hooks/useSignTypedData.mdx
150150
- page: useWaitForUserOperationTransaction
151151
path: wallets/pages/reference/account-kit/react/hooks/useWaitForUserOperationTransaction.mdx
152+
- section: Solana Actions
153+
contents:
154+
- page: useSolanaTransaction
155+
path: wallets/pages/reference/account-kit/react/hooks/useSolanaTransaction.mdx
156+
- page: useSolanaSigner
157+
path: wallets/pages/reference/account-kit/react/hooks/useSolanaSigner.mdx
152158
- section: Bundler/RPC Client
153159
contents:
154160
- page: useBundlerClient

site/pages/react/quickstart.mdx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,69 @@ export default function Home() {
394394
</main>
395395
);
396396
}
397+
c;
398+
```
399+
400+
## Other examples
401+
402+
### Sending a solana transaction
403+
404+
This is with the assumption that we have logged in, and we want a component to send a transaction
405+
406+
```tsx twoslash
407+
import React from "react";
408+
import { useSolanaTransaction } from "@account-kit/react";
409+
import { Connection } from "@solana/web3.js";
410+
411+
function MyComponent() {
412+
const connection = new Connection(
413+
"https://solana-devnet.g.alchemy.com/v2/<API_KEY>",
414+
{
415+
wsEndpoint: "wss://api.devnet.solana.com",
416+
commitment: "confirmed",
417+
}
418+
);
419+
420+
const {
421+
mutate: doTransaction,
422+
isPending,
423+
signer,
424+
reset,
425+
data: { hash: txHash = null } = {},
426+
} = useSolanaTransaction({
427+
connection,
428+
});
429+
430+
if (!signer) {
431+
return <div>Loading alchemy signer...</div>;
432+
}
433+
434+
return (
435+
<div>
436+
<button
437+
onClick={() =>
438+
doTransaction({
439+
transfer: {
440+
amount: 1000000,
441+
toAddress: "<ToSolanaAddress>",
442+
},
443+
})
444+
}
445+
>
446+
{" "}
447+
Go make Transfer{" "}
448+
</button>
449+
{!!txHash && <button onClick={() => reset()}> Reset </button>}
450+
{!!txHash && (
451+
<a
452+
href={`https://explorer.solana.com/tx/${txHash}?cluster=devnet`}
453+
target="_blank"
454+
>
455+
{" "}
456+
Go To Tracker{" "}
457+
</a>
458+
)}
459+
</div>
460+
);
461+
}
397462
```

site/pages/reference/account-kit/react/hooks/useSolanaTransaction.mdx

Lines changed: 72 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/scripts/prebuild.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const hookGroupings = {
5353
"useClientActions",
5454
"useChain",
5555
],
56+
"Solana Actions": ["useSolanaTransaction", "useSolanaSignMessage"],
5657
"Bundler/RPC Client": ["useBundlerClient"],
5758
Utilities: [
5859
"useAlchemyAccountContext",

site/sidebar/reference/aa-sdk/core.ts

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/sidebar/reference/account-kit/react-native.ts

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/sidebar/reference/account-kit/react.ts

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)