lido-nation/cardano-nft-maker-laravel

1.0.5 2024-08-17 09:06 UTC

This package is not auto-updated.

Last update: 2024-11-10 08:32:23 UTC


README

Latest Version on Packagist Packagist Downloads GitLab Release GitLab Tag

This package aims at making the cardano nft creation easy, We use NMKR Studio behind the scenes to make this process seemless.

Support us

You can support us by buying one of our nfts or donating.

Installation

You can install the package via composer:

composer require lidonation/cardano-nft-maker-laravel

You can publish the config file with:

php artisan vendor:publish --tag="cardano-nft-maker-laravel-config"

This is the contents of the published config file:

return [
    'auth_key' => env('MAKER_AUTH_KEY', ''),
    'baseUrl' => env('MAKER_BASE_URL', 'https://studio-api.preprod.nmkr.io'),
    'project_uuid' => env('MAKER_PROJECT_UUID',)
];

Usage

Set up a project at NMKR Studio.

To use this package your dedicated nft model neets to implement the CardanoNftInterface that has predefined properties maker_nft_uuid which will be the uuid of the remote nft that will be created in the api and maker_project_uuid the uuid of the project your remote nft will be under.For simplicity we will make the properties as columns in our nft model. Use NftServiceTrait which lets you utilise the NftMakerService to make the api calls.

<?php

namespace App\Models;

use Lidonation\CardanoNftMaker\Interfaces\CardanoNftInterface;
use Lidonation\CardanoNftMaker\Traits\NftServiceTrait;

class Nft extends Model implements CardanoNftInterface
{
    use NftServiceTrait;
}

lets upload our nft to the api

//get our nft instance 
$myNft = Nft::first();

$metadata = [
    "tokenname" => $myNft->name,
    "displayname" => $myNft->name,
    "description" => $myNft->description,
    "previewImageNft" => [
        "mimetype" => "image/png",
        "fileFromsUrl" => "https://images.pexels.com/photos/45201/kitty-cat-kitten-pet-45201.jpeg?auto=compress&cs=tinysrgb&w=800",
    ],
    "metadataPlaceholder" => [
        [
            "name" => "Age",
            "value" => "1"
        ],
        [
            "name" => "Color",
            "value" => "Black and white"
        ]
    ],
];

//our metadata has to conform to the format specified by the api, our DTO can do the validation for us 
$validatedMetadata = MetadataUpload::from($metadata);

//set the remote project uuid
$myNft->update([
  'maker_project_uuid' => '92fa1da3-df83-40b9-a21b-dc819553e98b'
]);

//upload
/* @var $response \Saloon\Http\Response  */
$response = $mynft->uploadNft($validatedMetadata);

//response details 
$remoteNftDetails = $response->json();

//save the nftUid for further updating if required, we will also save our metadata for updating later 
$metadataDetails = $remoteNftDetails['metadata'];
$myNft->update([
  'maker_nft_uuid' => $remoteNftDetails['nftUid'],
  'maker_nft_metadata' => $metadataDetails,
  'policy' => array_key_first(json_decode($metadataDetails, true)[721])
]);

If we need to update our metadata, we can easily do that. For our case we will add social contacts.

$metadataDetails = json_decode($myNft->maker_nft_metadata, true);
$metadata = $metadataDetails[721][$myNft->policy][$myNft->name];

//remove empty fields if any
$updatedMetadata = array_filter($metadata, fn ($value) => !empty($value));

// add custom static metadata
$updatedMetadata['web contact'] = [
    'twitter' => 'https://x.com/catAstrophy',
    'discord' => 'https://discordapp.com/users/7734909132320',
    'website' => 'https://www.cat-astrophy.com',
];
$metadataDetails[721][$myNft->policy][$myNft->name] = $updatedMetadata;

//lets update remote our nft
$response = $myNft->updateNft($metadataDetails)->json();

//sync local with remote nft
$myNft->update([
  'maker_nft_metadata' => $response['metadata'],
]);

To delete our remote nft

$myNft->deleteNft();

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.