spl-token-minter.sol 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. @mutableSigner(payer) // payer account
  8. @mutableSigner(mint) // mint account to be created
  9. @mutableAccount(metadata) // metadata account to be created
  10. @signer(mintAuthority) // mint authority for the mint account
  11. @account(rentAddress)
  12. @account(metadataProgramId)
  13. function createTokenMint(
  14. address freezeAuthority, // freeze authority for the mint account
  15. uint8 decimals, // decimals for the mint account
  16. string name, // name for the metadata account
  17. string symbol, // symbol for the metadata account
  18. string uri // uri for the metadata account
  19. ) external {
  20. // Invoke System Program to create a new account for the mint account and,
  21. // Invoke Token Program to initialize the mint account
  22. // Set mint authority, freeze authority, and decimals for the mint account
  23. SplToken.create_mint(
  24. tx.accounts.payer.key, // payer account
  25. tx.accounts.mint.key, // mint account
  26. tx.accounts.mintAuthority.key, // mint authority
  27. freezeAuthority, // freeze authority
  28. decimals // decimals
  29. );
  30. // Invoke Metadata Program to create a new account for the metadata account
  31. MplMetadata.create_metadata_account(
  32. tx.accounts.metadata.key, // metadata account
  33. tx.accounts.mint.key, // mint account
  34. tx.accounts.mintAuthority.key, // mint authority
  35. tx.accounts.payer.key, // payer
  36. tx.accounts.payer.key, // update authority (of the metadata account)
  37. name, // name
  38. symbol, // symbol
  39. uri, // uri (off-chain metadata json)
  40. tx.accounts.rentAddress.key,
  41. tx.accounts.metadataProgramId.key
  42. );
  43. }
  44. @mutableAccount(mint)
  45. @mutableAccount(tokenAccount)
  46. @mutableSigner(mintAuthority)
  47. function mintTo(uint64 amount) external {
  48. // Mint tokens to the token account
  49. SplToken.mint_to(
  50. tx.accounts.mint.key, // mint account
  51. tx.accounts.tokenAccount.key, // token account
  52. tx.accounts.mintAuthority.key, // mint authority
  53. amount // amount
  54. );
  55. }
  56. }