Skip to content

Commit

Permalink
reset nft minter starter file
Browse files Browse the repository at this point in the history
  • Loading branch information
masterzorgon committed Feb 7, 2024
1 parent b6aebc5 commit 0ffff28
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 44 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@solana/wallet-adapter-react-ui": "^0.9.8",
"@solana/wallet-adapter-wallets": "^0.16.6",
"@solana/web3.js": "^1.47.3",
"axios": "^1.6.7",
"bs58": "^5.0.0",
"dotenv": "^16.0.1",
"next": "latest",
Expand Down
3 changes: 1 addition & 2 deletions pages/minter/finished.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const Finished = () => {
<form onSubmit={event => mintCompressedNft(event)} className='rounded-lg min-h-content bg-[#2a302f] p-4 sm:col-span-6 lg:col-start-2 lg:col-end-6'>
<div className='flex justify-between items-center'>
<h2 className='text-lg sm:text-2xl font-semibold'>
cNFT Minter 🖼️
cNFT Minter 🖼️
</h2>
<button
type='submit'
Expand All @@ -129,7 +129,6 @@ const Finished = () => {
>
Mint
</button>

</div>

<div className='text-sm font-semibold mt-8 bg-[#222524] border-2 border-gray-500 rounded-lg p-2'>
Expand Down
84 changes: 43 additions & 41 deletions pages/tokens/finished.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,7 @@ const Finished = () => {
} else { return false; }
};

const createAccount = async (event: { preventDefault: () => void }) => {
event.preventDefault();

if (connectionErr()) { return; }

try {
// Token Accounts are accounts which hold tokens of a given mint.
const tokenAccount = web3.Keypair.generate();
const space = token.ACCOUNT_SIZE;
// amount of SOL required for the account to not be deallocated
const lamports = await connection.getMinimumBalanceForRentExemption(space);
const programId = token.TOKEN_PROGRAM_ID;

const transaction = new web3.Transaction().add(
// creates a new account
web3.SystemProgram.createAccount({
fromPubkey: publicKey!,
newAccountPubkey: tokenAccount.publicKey,
space,
lamports,
programId
}),
// initializes the new account as a Token Account account
token.createInitializeAccountInstruction(
tokenAccount.publicKey, // account to initialize
mintAddr!, // token mint address
publicKey!, // owner of new account
token.TOKEN_PROGRAM_ID // spl token program account
)
);

// prompts the user to sign the transaction and submit it to the network
const signature = await sendTransaction(transaction, connection, { signers: [tokenAccount] });
setAccTx(signature);
setAccAddr(tokenAccount.publicKey);
} catch (err) {
toast.error("Error creating Token Account");
console.log('error', err);
}
};

// create transaction to create a token mint on the blockchain
const createMint = async (event: { preventDefault: () => void; }) => {
// prevents page from refreshing
event.preventDefault();
Expand Down Expand Up @@ -109,6 +69,48 @@ const Finished = () => {
}
};

// create transaction to create a token account fo the mint we created on the blockchain
const createAccount = async (event: { preventDefault: () => void }) => {
event.preventDefault();

if (connectionErr()) { return; }

try {
// Token Accounts are accounts which hold tokens of a given mint.
const tokenAccount = web3.Keypair.generate();
const space = token.ACCOUNT_SIZE;
// amount of SOL required for the account to not be deallocated
const lamports = await connection.getMinimumBalanceForRentExemption(space);
const programId = token.TOKEN_PROGRAM_ID;

const transaction = new web3.Transaction().add(
// creates a new account
web3.SystemProgram.createAccount({
fromPubkey: publicKey!,
newAccountPubkey: tokenAccount.publicKey,
space,
lamports,
programId
}),
// initializes the new account as a Token Account account
token.createInitializeAccountInstruction(
tokenAccount.publicKey, // account to initialize
mintAddr!, // token mint address
publicKey!, // owner of new account
token.TOKEN_PROGRAM_ID // spl token program account
)
);

// prompts the user to sign the transaction and submit it to the network
const signature = await sendTransaction(transaction, connection, { signers: [tokenAccount] });
setAccTx(signature);
setAccAddr(tokenAccount.publicKey);
} catch (err) {
toast.error("Error creating Token Account");
console.log('error', err);
}
};

const createAccountOutputs = [
{
title: "Token Account Address...",
Expand Down
2 changes: 1 addition & 1 deletion pages/tokens/starter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import BoilerPlate from '../../components/BoilerPlate';

const Starter = () => (
<BoilerPlate />
)
);

export default Starter;
57 changes: 57 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,11 @@ async-mutex@^0.3.2:
dependencies:
tslib "^2.3.1"

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==

autoprefixer@^10.4.7:
version "10.4.7"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.4.7.tgz#1db8d195f41a52ca5069b7593be167618edbbedf"
Expand All @@ -930,6 +935,15 @@ axios@^0.21.0, axios@^0.21.1:
dependencies:
follow-redirects "^1.14.0"

axios@^1.6.7:
version "1.6.7"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7"
integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==
dependencies:
follow-redirects "^1.15.4"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

base-x@^3.0.2:
version "3.0.9"
resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.9.tgz#6349aaabb58526332de9f60995e548a53fe21320"
Expand Down Expand Up @@ -1213,6 +1227,13 @@ color-name@^1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
dependencies:
delayed-stream "~1.0.0"

commander@^2.20.3:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
Expand Down Expand Up @@ -1317,6 +1338,11 @@ delay@^5.0.0:
resolved "https://registry.yarnpkg.com/delay/-/delay-5.0.0.tgz#137045ef1b96e5071060dd5be60bf9334436bd1d"
integrity sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw==

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

des.js@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.1.tgz#5382142e1bdc53f85d86d53e5f4aa7deb91e0843"
Expand Down Expand Up @@ -1625,13 +1651,27 @@ follow-redirects@^1.14.0:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5"
integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==

follow-redirects@^1.15.4:
version "1.15.5"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020"
integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==

for-each@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
integrity sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==
dependencies:
is-callable "^1.1.3"

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

fraction.js@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.2.0.tgz#448e5109a313a3527f5a3ab2119ec4cf0e0e2950"
Expand Down Expand Up @@ -2106,6 +2146,18 @@ miller-rabin@^4.0.0:
bn.js "^4.0.0"
brorand "^1.0.1"

[email protected]:
version "1.52.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==

mime-types@^2.1.12:
version "2.1.35"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
dependencies:
mime-db "1.52.0"

mimic-fn@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
Expand Down Expand Up @@ -2384,6 +2436,11 @@ process@^0.11.10:
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/ps-tree/-/ps-tree-1.2.0.tgz#5e7425b89508736cdd4f2224d028f7bb3f722ebd"
Expand Down

0 comments on commit 0ffff28

Please sign in to comment.