spl-token-minter.sol 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import "../libraries/spl_token.sol";
  2. import "../libraries/mpl_metadata.sol";
  3. @program_id("F1ipperKF9EfD821ZbbYjS319LXYiBmjhzkkf5a26rC")
  4. contract spl_token_minter {
  5. @payer(payer)
  6. constructor() {}
  7. function createTokenMint(
  8. address payer, // payer account
  9. address mint, // mint account to be created
  10. address mintAuthority, // mint authority for the mint account
  11. address freezeAuthority, // freeze authority for the mint account
  12. address metadata, // metadata account to be created
  13. uint8 decimals, // decimals for the mint account
  14. string name, // name for the metadata account
  15. string symbol, // symbol for the metadata account
  16. string uri // uri for the metadata account
  17. ) public {
  18. // Invoke System Program to create a new account for the mint account and,
  19. // Invoke Token Program to initialize the mint account
  20. // Set mint authority, freeze authority, and decimals for the mint account
  21. SplToken.create_mint(
  22. payer, // payer account
  23. mint, // mint account
  24. mintAuthority, // mint authority
  25. freezeAuthority, // freeze authority
  26. decimals // decimals
  27. );
  28. // Invoke Metadata Program to create a new account for the metadata account
  29. MplMetadata.create_metadata_account(
  30. metadata, // metadata account
  31. mint, // mint account
  32. mintAuthority, // mint authority
  33. payer, // payer
  34. payer, // update authority (of the metadata account)
  35. name, // name
  36. symbol, // symbol
  37. uri // uri (off-chain metadata json)
  38. );
  39. }
  40. function mintTo(address mintAuthority, address tokenAccount, address mint, uint64 amount) public {
  41. // Mint tokens to the token account
  42. SplToken.mint_to(
  43. mint, // mint account
  44. tokenAccount, // token account
  45. mintAuthority, // mint authority
  46. amount // amount
  47. );
  48. }
  49. }