This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from mordonez-me/main
Update dependencies and example snippets to latest version
- Loading branch information
Showing
9 changed files
with
19,622 additions
and
12,969 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"name": "solana-dapp-next", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "Solana Maintainers <[email protected]>", | ||
"license": "MIT", | ||
"private": false, | ||
"scripts": { | ||
|
@@ -12,29 +13,32 @@ | |
"dependencies": { | ||
"@heroicons/react": "^1.0.5", | ||
"@noble/ed25519": "^1.7.1", | ||
"@solana/wallet-adapter-base": "^0.9.18", | ||
"@solana/wallet-adapter-react": "^0.15.21-rc.4", | ||
"@solana/wallet-adapter-react-ui": "^0.9.19-rc.4", | ||
"@solana/wallet-adapter-wallets": "^0.19.4", | ||
"@solana/web3.js": "^1.58.0", | ||
"@tailwindcss/typography": "^0.5.0", | ||
"@solana/wallet-adapter-base": "^0.9.20", | ||
"@solana/wallet-adapter-react": "^0.15.28", | ||
"@solana/wallet-adapter-react-ui": "^0.9.27", | ||
"@solana/wallet-adapter-wallets": "^0.19.11", | ||
"@solana/web3.js": "^1.73.0", | ||
"@tailwindcss/typography": "^0.5.9", | ||
"daisyui": "^1.24.3", | ||
"immer": "^9.0.12", | ||
"next": "12.0.8", | ||
"next": "^13.1.5", | ||
"next-compose-plugins": "^2.2.1", | ||
"next-transpile-modules": "^9.0.0", | ||
"react": "17.0.2", | ||
"react-dom": "17.0.2", | ||
"next-transpile-modules": "^10.0.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"zustand": "^3.6.9" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "17.0.10", | ||
"@types/react": "17.0.38", | ||
"@types/node": "^18.11.18", | ||
"@types/react": "^18.0.27", | ||
"autoprefixer": "^10.4.2", | ||
"eslint": "8.7.0", | ||
"eslint-config-next": "12.0.8", | ||
"eslint-config-next": "^13.1.5", | ||
"postcss": "^8.4.5", | ||
"tailwindcss": "^3.0.15", | ||
"typescript": "4.5.4" | ||
"tailwindcss": "^3.2.4", | ||
"typescript": "^4.9.4" | ||
}, | ||
"engines": { | ||
"node": ">=16" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useConnection, useWallet } from '@solana/wallet-adapter-react'; | ||
import { Keypair, SystemProgram, TransactionMessage, TransactionSignature, VersionedTransaction } from '@solana/web3.js'; | ||
import { FC, useCallback } from 'react'; | ||
import { notify } from "../utils/notifications"; | ||
|
||
export const SendVersionedTransaction: FC = () => { | ||
const { connection } = useConnection(); | ||
const { publicKey, sendTransaction } = useWallet(); | ||
|
||
const onClick = useCallback(async () => { | ||
if (!publicKey) { | ||
notify({ type: 'error', message: `Wallet not connected!` }); | ||
console.log('error', `Send Transaction: Wallet not connected!`); | ||
return; | ||
} | ||
|
||
let signature: TransactionSignature = ''; | ||
try { | ||
|
||
// Create instructions to send, in this case a simple transfer | ||
const instructions = [ | ||
SystemProgram.transfer({ | ||
fromPubkey: publicKey, | ||
toPubkey: Keypair.generate().publicKey, | ||
lamports: 1_000_000, | ||
}), | ||
]; | ||
|
||
// Get the lates block hash to use on our transaction and confirmation | ||
let latestBlockhash = await connection.getLatestBlockhash() | ||
|
||
// Create a new TransactionMessage with version and compile it to version 0 | ||
const messageV0 = new TransactionMessage({ | ||
payerKey: publicKey, | ||
recentBlockhash: latestBlockhash.blockhash, | ||
instructions, | ||
}).compileToV0Message(); | ||
|
||
// Create a new VersionedTransacction to support the v0 message | ||
const transation = new VersionedTransaction(messageV0) | ||
|
||
// Send transaction and await for signature | ||
signature = await sendTransaction(transation, connection); | ||
|
||
// Await for confirmation | ||
await connection.confirmTransaction({ signature, ...latestBlockhash }, 'confirmed'); | ||
|
||
console.log(signature); | ||
notify({ type: 'success', message: 'Transaction successful!', txid: signature }); | ||
} catch (error: any) { | ||
notify({ type: 'error', message: `Transaction failed!`, description: error?.message, txid: signature }); | ||
console.log('error', `Transaction failed! ${error?.message}`, signature); | ||
return; | ||
} | ||
}, [publicKey, notify, connection, sendTransaction]); | ||
|
||
return ( | ||
<div> | ||
<button | ||
className="group w-60 m-2 btn animate-pulse disabled:animate-none bg-gradient-to-r from-[#9945FF] to-[#14F195] hover:from-pink-500 hover:to-yellow-500 ... " | ||
onClick={onClick} disabled={!publicKey} | ||
> | ||
<div className="hidden group-disabled:block "> | ||
Wallet not connected | ||
</div> | ||
<span className="block group-disabled:hidden" > | ||
Send Versioned Transaction | ||
</span> | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.