Skip to content

Commit

Permalink
Added accountError example
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobcreech committed Mar 9, 2022
1 parent f5a394b commit e9c538a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
},
"dependencies": {
"@heroicons/react": "^1.0.5",
"@solana/spl-token": "^0.2.0",
"@solana/wallet-adapter-base": "^0.9.3",
"@solana/wallet-adapter-react": "^0.15.3",
"@solana/wallet-adapter-react-ui": "^0.9.5",
"@solana/wallet-adapter-wallets": "^0.15.3",
"@solana/web3.js": "^1.31.0",
"@solana/web3.js": "^1.36.0",
"@tailwindcss/typography": "^0.5.0",
"@solana/buffer-layout": "^4.0.0",
"daisyui": "^1.24.3",
"immer": "^9.0.12",
"next": "12.0.8",
Expand Down
41 changes: 41 additions & 0 deletions src/components/CreateAccountError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { FC, useCallback } from 'react';
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { Transaction, Keypair, SystemProgram } from '@solana/web3.js';
import { AccountLayout, TOKEN_PROGRAM_ID } from '@solana/spl-token';

export const CreateAccountError: FC = () => {
const { connection } = useConnection();
const { publicKey, sendTransaction } = useWallet();

const onClick = useCallback(async () => {
const tempTokenAccount = Keypair.generate();
let transaction = new Transaction();


// Create Temp Token X Account
transaction.add(
SystemProgram.createAccount({
programId: TOKEN_PROGRAM_ID,
fromPubkey: publicKey,
newAccountPubkey: tempTokenAccount.publicKey,
space: AccountLayout.span,
lamports: await connection.getMinimumBalanceForRentExemption(AccountLayout.span )
})
);

const signature = await sendTransaction(transaction, connection, {signers: [tempTokenAccount]});
let txid = await connection.confirmTransaction(signature);
console.log(txid);
}, [publicKey, connection, sendTransaction]);

return (
<div>
<button
className="px-8 m-2 btn animate-pulse bg-gradient-to-r from-[#9945FF] to-[#14F195] hover:from-pink-500 hover:to-yellow-500 ..."
onClick={onClick}
>
<span>Create Error</span>
</button>
</div>
)
}
2 changes: 2 additions & 0 deletions src/views/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useWallet, useConnection } from '@solana/wallet-adapter-react';

// Components
import { RequestAirdrop } from '../../components/RequestAirdrop';
import { CreateAccountError } from '../../components/CreateAccountError';
import pkg from '../../../package.json';

// Store
Expand Down Expand Up @@ -44,6 +45,7 @@ export const HomeView: FC = ({ }) => {
</div>
<div className="text-center">
<RequestAirdrop />
<CreateAccountError />
{/* {wallet.publicKey && <p>Public Key: {wallet.publicKey.toBase58()}</p>} */}
{wallet && <p>SOL Balance: {(balance || 0).toLocaleString()}</p>}
</div>
Expand Down

0 comments on commit e9c538a

Please sign in to comment.