Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement initializeMint instruction #96

Conversation

nickcruz
Copy link
Contributor

@nickcruz nickcruz commented Aug 1, 2022

Description

Adds initializeMint instruction + some unit tests to ensure it's working as a low-level instruction. Note that I haven't tested it outside of serializing it in a transaction.

For some reference, I'm currently trying to support the equivalent of createNFT.ts in metaplex-android as I haven't seen it implemented.

This is part 1 of 2 new instructions I want to add to SolanaKT, the other being mintTo.

Implementation references

I translated initializeMint.ts, using the initializeAccount.ts TS and Android (this lib) implementations as references.

Then I ran some local TS code to get some serialized Transaction values.

Serialized Transaction Values

Expected serialized transaction values come from some reference TS code. I just used the latest code from https://github.com/metaplex-foundation/js/ to generate them.

import { initializeMintBuilder } from "@metaplex-foundation/js";
import { Keypair, PublicKey } from "@solana/web3.js";

const mintKeypair = Keypair.fromSecretKey(
  new Uint8Array([
    248, 245, 206, 215, 221, 248, 207, 125, 63, 204, 25, 40, 10, 180, 174,
    189, 124, 221, 111, 20, 34, 34, 147, 0, 194, 55, 115, 203, 41, 9, 128,
    188, 119, 48, 108, 85, 136, 220, 56, 7, 110, 148, 77, 217, 121, 23, 39,
    159, 71, 234, 16, 104, 242, 116, 18, 106, 192, 38, 254, 250, 104, 231,
    160, 240,
  ])
);
const mintAuthority = new PublicKey(
  "9Aq6XkUT8Nx2ztkpkUxc4HiVCFWKTJZWiLnhC94iofvy"
);
const freezeAuthority = new PublicKey(
  "22BMtVRGveoYeJyvYDHfJP5JMCRKTYbp3QMhxU1P8w1n"
);
console.log("mint public key:", mintKeypair.publicKey.toBase58());
console.log("mint secret key:", mintKeypair.secretKey.toString());
console.log("mint authority public key:", mintAuthority.toBase58());
console.log("freeze authority public key:", freezeAuthority.toBase58());
const tx = initializeMintBuilder({
  mint: mintKeypair,
  decimals: 9,
  mintAuthority,
  freezeAuthority,
}).toTransaction();

tx.recentBlockhash = "Eit7RCyhUixAe2hGBS8oqnw59QK3kgMMjfLME5bm9wRn";
tx.sign(mintKeypair);

console.log("base64 serialized tx:", tx.serialize().toString("base64"));

Code Style

This is my first contribution to SolanaKT and generally I tried to follow the existing style as much as I could, but took a bit of my own freedom in the unit test I added. Happy to adjust styles if needed!

@nickcruz nickcruz marked this pull request as ready for review August 1, 2022 06:26
Copy link
Contributor

@ajamaica ajamaica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for adding this missing call to the token program. We appreciate your contributions.

@ajamaica ajamaica merged commit 3960078 into metaplex-foundation:master Aug 1, 2022
@nickcruz nickcruz deleted the nick/feature/create-initialize-mint-instruction branch August 1, 2022 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants