The gaming-asset-marketplace.clar
smart contract facilitates the management of gaming assets in a decentralized marketplace. It enables the minting, transferring, listing, unlisting, and burning of gaming assets. The contract supports both single and batch minting, asset ownership management, and validation of asset metadata URIs. Only the marketplace administrator has permission to mint assets, while individual asset owners can transfer, burn, and list/unlist their assets for sale.
- Minting: Admin can mint new gaming assets individually or in batches.
- Asset Management: Asset owners can transfer assets, burn assets, and list/unlist assets for sale.
- Metadata: Each asset has associated metadata, stored as a URI.
- Decentralized Ownership: Asset ownership and marketplace listing status are decentralized and tracked by the contract.
- Asset Status: Tracks burn status and whether an asset is listed for sale on the marketplace.
marketplace-admin
: The address of the marketplace administrator.err-not-admin
: Error if the caller is not the admin.err-not-asset-owner
: Error if the caller is not the asset owner.err-asset-already-exists
: Error if the asset already exists.err-asset-not-found
: Error if the asset is not found.err-invalid-asset-uri
: Error if the asset URI is invalid.err-burn-asset-failed
: Error if burning the asset fails.max-mint-limit
: Maximum number of assets that can be minted in a single batch.
- Non-fungible token (
game-asset
): A unique identifier for each gaming asset. - Asset Counter: Tracks the current asset ID counter.
asset-metadata
: Maps each asset ID to its metadata URI.burned-assets
: Maps each asset ID to its burn status (true if burned).marketplace-listing
: Maps each asset ID to its marketplace listing status (true if listed).
validate-asset-owner
: Ensures the caller is the owner of the asset.validate-uri
: Validates the asset URI (length between 1 and 256 characters).check-asset-burned
: Checks if the asset has been burned.
mint-asset
: Mints a new asset and assigns a unique ID to it.mint-single-asset
: Mints a single asset. Only the admin can mint assets.batch-mint-assets
: Mints multiple assets in a batch, ensuring the batch size does not exceed the mint limit.
transfer-asset
: Transfers ownership of an asset to another user.burn-asset
: Burns an asset, removing it from circulation.
list-asset
: Lists an asset for sale on the marketplace.unlist-asset
: Removes an asset from the marketplace listing.
get-asset-uri
: Retrieves the URI (metadata) associated with an asset.get-asset-owner
: Retrieves the owner of a specific asset.get-asset-metadata
: Retrieves the metadata of a specific asset.is-asset-listed
: Checks if an asset is currently listed on the marketplace.get-total-assets
: Retrieves the total number of minted assets.get-marketplace-admin
: Retrieves the address of the marketplace administrator.
Only the marketplace admin can mint new assets. To mint a single asset, provide a URI for the asset's metadata.
(mint-single-asset "https://example.com/asset-metadata")
The admin can mint up to 50 assets in a single batch. Provide a list of URIs for the assets' metadata.
(batch-mint-assets ["https://example.com/asset1" "https://example.com/asset2" ...])
Asset owners can transfer assets to other users. To transfer an asset, specify the asset ID, owner, and recipient.
(transfer-asset asset-id owner recipient)
Asset owners can burn their assets, removing them from circulation. Specify the asset ID.
(burn-asset asset-id)
To list an asset for sale on the marketplace, the owner can execute the following command:
(list-asset asset-id)
To unlist an asset, use:
(unlist-asset asset-id)
To retrieve various details about an asset, use the following read-only functions:
- Get the URI of an asset:
(get-asset-uri asset-id)
- Get the owner of an asset:
(get-asset-owner asset-id)
- Check if an asset is listed on the marketplace:
(is-asset-listed asset-id)
- Check if an asset has been burned:
(is-asset-burned asset-id)
- Get the total number of minted assets:
(get-total-assets)
Upon contract deployment, the asset counter is initialized to 0
, ensuring that asset IDs start from 1
for the first minted asset.
(begin
(var-set asset-counter u0))
The contract includes various error conditions:
- Not Admin: Only the marketplace admin can mint assets (
err-not-admin
). - Not Asset Owner: Only the owner can transfer, burn, list, or unlist their assets (
err-not-asset-owner
). - Asset Already Exists: Prevents duplicate assets from being minted (
err-asset-already-exists
). - Asset Not Found: Used when trying to access a non-existent asset (
err-asset-not-found
). - Invalid URI: Ensures the asset URI is valid (
err-invalid-asset-uri
). - Burn Failed: Prevents burning assets that are already burned (
err-burn-asset-failed
).
This smart contract provides a decentralized solution for managing gaming assets in a marketplace. It allows for minting, listing, transferring, and burning assets, all while ensuring secure ownership and marketplace listing. The contract also provides several read-only functions to query asset information and status.