create-token.sol 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import "../libraries/spl_token.sol";
  2. import "../libraries/mpl_metadata.sol";
  3. @program_id("8eZPhSaXfHqbcrfskVThtCG68kq8MfVHqmtm6wYf4TLb")
  4. contract create_token {
  5. // Creating a dataAccount is required by Solang
  6. // The account is unused in this example
  7. @payer(payer) // payer account
  8. constructor() {}
  9. @mutableSigner(payer) // payer account
  10. @mutableSigner(mint) // mint account to be created
  11. @mutableAccount(metadata) // metadata account to be created
  12. @signer(mintAuthority) // mint authority for the mint account
  13. @account(rentAddress)
  14. @account(metadataProgramId)
  15. function createTokenMint(
  16. address freezeAuthority, // freeze authority for the mint account
  17. uint8 decimals, // decimals for the mint account
  18. string name, // name for the metadata account
  19. string symbol, // symbol for the metadata account
  20. string uri // uri for the metadata account
  21. ) external {
  22. // Invoke System Program to create a new account for the mint account and,
  23. // Invoke Token Program to initialize the mint account
  24. // Set mint authority, freeze authority, and decimals for the mint account
  25. SplToken.create_mint(
  26. tx.accounts.payer.key, // payer account
  27. tx.accounts.mint.key, // mint account
  28. tx.accounts.mintAuthority.key, // mint authority
  29. freezeAuthority, // freeze authority
  30. decimals // decimals
  31. );
  32. // Invoke Metadata Program to create a new account for the metadata account
  33. MplMetadata.create_metadata_account(
  34. tx.accounts.metadata.key, // metadata account
  35. tx.accounts.mint.key, // mint account
  36. tx.accounts.mintAuthority.key, // mint authority
  37. tx.accounts.payer.key, // payer
  38. tx.accounts.payer.key, // update authority (of the metadata account)
  39. name, // name
  40. symbol, // symbol
  41. uri, // uri (off-chain metadata json)
  42. tx.accounts.metadataProgramId.key,
  43. tx.accounts.rentAddress.key
  44. );
  45. }
  46. }