Open klren0312 opened 12 months ago
module foo::nft{ use sui::object::{Self, UID}; use sui::transfer; use sui::tx_context::{Self, TxContext}; use sui::display; use sui::package; use std::string::utf8; struct NFT has drop {} struct MyNFT has key,store{ id: UID, tokenId: u64, image_url: std::ascii::String } fun init(witness: NFT, ctx:&mut TxContext){ let keys = vector[ utf8(b"name"), utf8(b"collection"), utf8(b"image_url"), utf8(b"description") ]; let values = vector[ utf8(b"MyNFT #{tokenId}"), utf8(b"MyNFT Collection"), utf8(b"data:image/svg+xml;base64,{image_url}"), utf8(b"This is My NFT") ]; let publisher = package::claim(witness,ctx); let display = display::new_with_fields<MyNFT>(&publisher, keys, values, ctx); display::update_version(&mut display); transfer::public_transfer(publisher, tx_context::sender(ctx)); transfer::public_transfer(display, tx_context::sender(ctx)); let state = State{ id: object::new(ctx), count: 0 }; transfer::transfer(mint_(&mut state, ctx), tx_context::sender(ctx)); transfer::share_object(state); } struct State has key { id: UID, count: u64 } fun mint_( state:&mut State, ctx: &mut TxContext):MyNFT{ MyNFT { id: object::new(ctx), tokenId: state.count, image_url: std::ascii::string(b"PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHhtbG5zOnhsaW5rPSdodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rJyB2ZXJzaW9uPScxLjEnIGlkPSdMYXllcl8xJyB4PScwcHgnIHk9JzBweCcgdmlld0JveD0nMCAwIDEwMCAxMDAnIGVuYWJsZS1iYWNrZ3JvdW5kPSduZXcgMCAwIDEwMCAxMDAnIHhtbDpzcGFjZT0ncHJlc2VydmUnIGhlaWdodD0nMTAwcHgnIHdpZHRoPScxMDBweCc+PGc+PHBhdGggZD0nTTI4LjEsMzYuNmM0LjYsMS45LDEyLjIsMS42LDIwLjksMS4xYzguOS0wLjQsMTktMC45LDI4LjksMC45YzYuMywxLjIsMTEuOSwzLjEsMTYuOCw2Yy0xLjUtMTIuMi03LjktMjMuNy0xOC42LTMxLjMgYy00LjktMC4y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ksMzkuOCw1Ny42eicvPjxwYXRoIGQ9J00yNi4yLDg4LjJjMy4zLDIsNi43LDMuNiwxMC4yLDQuN2MtMy41LTYuMi02LjMtMTIuNi04LjgtMTguNWMtMy4xLTcuMi01LjgtMTMuNS05LTE3LjJjLTEuOSw4LTIsMTYuNC0wLjMsMjQuNyAgIEMyMC42LDg0LjIsMjMuMiw4Ni4zLDI2LjIsODguMnonLz48cGF0aCBkPSdNMzAuOSw3M2MyLjksNi44LDYuMSwxNC40LDEwLjUsMjEuMmMxNS42LDMsMzItMi4zLDQyLjYtMTQuNkM2Ny43LDc2LDUyLjIsNjkuNiwzNy45LDYwLjdDMzIsNTcsMjYuNSw1MywyMS4zLDQ4LjYgICBjLTAuNiwxLjUtMS4yLDMtMS43LDQuNkMyNC4xLDU3LjEsMjcuMyw2NC41LDMwLjksNzN6Jy8+PC9nPjwvc3ZnPg==") } } entry public fun mint( state:&mut State, ctx: &mut TxContext){ let sender = tx_context::sender(ctx); state.count = state.count + 1; let nft = mint_(state, ctx); transfer::public_transfer(nft, sender); } }