Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ilyasemenov/h3-websocket-anchor-wallet-request
https://github.com/ilyasemenov/h3-websocket-anchor-wallet-request
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ilyasemenov/h3-websocket-anchor-wallet-request
- Owner: IlyaSemenov
- License: mit
- Created: 2024-05-09T12:46:43.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-05-10T07:57:07.000Z (6 months ago)
- Last Synced: 2024-11-06T05:18:14.150Z (11 days ago)
- Language: TypeScript
- Size: 78.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# h3-websocket-anchor-wallet-request
Define `h3` request handler where the server receives an Anchor Wallet-like object and can call `signTransaction` on it. The actual signing is performed on the client side. Uses `h3-websocket-request` under the hood.
## Install
```sh
npm install h3-websocket-anchor-wallet-request
```## Use
Create `server/api/my-handler.ts`:
```ts
import { defineWalletRequestHandler } from "h3-websocket-anchor-wallet-request"export default defineWalletRequestHandler<{ input: string }>(async ({ wallet, data }) => {
// Use client-provided data.
const tx = await prepareTransaction(wallet.publicKey, data.input)
// Request the client to sign the transaction.
const signedTx = await wallet.signTransaction(tx)
const txId = await blockchain.push(signedTx)
// Return result to the client.
return { txId }
})
```In the client-side code, call the handler with:
```ts
import { walletRequest } from "h3-websocket-anchor-wallet-request/client"
import { useAnchorWallet } from "solana-wallets-vue"const wallet = useAnchorWallet()
const { txId } = await walletRequest<{ txId: string }>(
"/my-handler",
wallet.value,
{ input: "user input" }
)
```