create-token.sol 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import "./spl_token.sol";
  2. import "./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(address payer) {}
  9. function createTokenMint(
  10. address payer, // payer account
  11. address mint, // mint account to be created
  12. address mintAuthority, // mint authority for the mint account
  13. address freezeAuthority, // freeze authority for the mint account
  14. address metadata, // metadata account to be created
  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. ) public view {
  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. payer, // payer account
  25. mint, // mint account
  26. mintAuthority, // 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. metadata, // metadata account
  33. mint, // mint account
  34. mintAuthority, // mint authority
  35. payer, // payer
  36. payer, // update authority (of the metadata account)
  37. name, // name
  38. symbol, // symbol
  39. uri // uri (off-chain metadata json)
  40. );
  41. }
  42. }