inmarelibero / nft-manager
用于管理NFT的PHP库。
0.1.1
2023-05-18 04:05 UTC
Requires
- php: >=7.4
- ext-json: *
- symfony/options-resolver: ^5.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.11
- php-parallel-lint/php-parallel-lint: ^1.1
- phpstan/phpstan: ^1.8
- vimeo/psalm: ^4.9
README
本软件包有助于管理NFT收藏。鉴于您已经生成了一个包含图像和元数据的(生成式)NFT收藏,您可以使用此工具执行其他操作,例如 模糊化(部分揭示)、更新元数据和特征等。
安装
首选的安装方法是使用Composer。运行以下命令安装软件包并将其添加到项目的composer.json文件中
composer require inmarelibero/nft-manager
操作
在单个PHP脚本中,您可以 定义一个或多个步骤,这些步骤将被 顺序 和 独立 处理。
例如,您可以
- 模糊化元数据,同时保留前100个NFT的清晰度
- 然后 更新“名称”元数据,格式为
My super NFT #{id}
- 最后 格式化元数据,使其具有标准格式
您可以通过使用 from_id
来选择仅对NFT子集应用操作。
可用的操作有
1) 更新元数据
用于更新每个NFT的元数据,包括
- 更新
attributes
- 删除
attributes
- 通过键删除
metadata
- 更新“图像”元数据的
url
- 更新
external_url
- 更新
name
2) 格式化元数据
运行一个标准格式化程序,
- 按重要性排序元数据
- 按字母顺序排序属性
3) 模糊化
允许您将 attributes
替换为占位符(例如“?”)以模糊特征。
当进行部分揭示时非常有用,因为您可以从指定的起始ID开始模糊化。
4) 重新编号
当
- 您的NFT从0开始,您想从1开始重新编号时
- 您的收藏中存在漏洞时
5) 洗牌
随机洗牌整个收藏。
使用方法
- 从一个空文件夹开始,例如
mkdir my_project
- 进入文件夹:
cd my_project
- 安装此软件包:
composer require inmarelibero/nft-manager
- 创建文件夹
my_project/input
,并包含以下子文件夹input/
images/
<- 将所有NFT图像放在这里metadata/
<- 将所有NFT元数据放在这里
- 创建一个PHP文件,例如
/run.php
(有关内容,请参阅运行脚本部分) - 运行脚本:
php run.php
- 在
/output
文件夹中,您将找到结果收藏
运行脚本
您必须创建一个PHP脚本,定义将按顺序应用到输入NFT收藏中的操作列表。
<?php
require __DIR__ . '/vendor/autoload.php';
use \Inmarelibero\NFTManager\Operation\OperationFormatMetadata
use \Inmarelibero\NFTManager\Operation\OperationObfuscation
use \Inmarelibero\NFTManager\Operation\OperationRenumbering
use \Inmarelibero\NFTManager\Operation\OperationShuffle
use \Inmarelibero\NFTManager\Operation\OperationUpdateMetadata
// the ID of the last minted NFT (can be null)
$lastMintedId = null;
$nftHandler = new \Inmarelibero\NFTManager\NFTManager();
/*
* renumber IDs
*/
$nftHandler->run(OperationRenumbering::class, [
// the collection will start from NFT #0
'start_from_id' => 0,
// the "name" of the NFT #0 will be "https://examples.com/metadata/0.png"
'update_metadata_image' => 'https://examples.com/metadata/{id}.png',
// the "name" of the NFT #0 will be "Wow NFT #0"
'update_metadata_name' => 'Wow NFT #{id}',
]);
/*
* obfuscate
*/
$nftHandler->run(OperationObfuscation::class, [
// if $lastMintedId is 10, then NFT from #0 to #9 will be left in clear, while NFT from #10 and following will be obfuscated
'from_id' => $lastMintedId !== null ? $lastMintedId + 1 : null,
// the absolute path of the image to use as placeholder, for obfuscated NFTs
'placeholder_image_absolute_path' => getcwd() ."/assets/placeholder.png",
// all obfuscated NFTs will have this string as value in every trait
'placeholder_value' => '?',
]);
/*
* update metadata
*/
$nftHandler->run(OperationUpdateMetadata::class, [
'from_id' => $lastMintedId !== null ? $lastMintedId + 1 : null,
// add attribute "Legendary": "?"
'update_attributes' => [
'Legendary' => '?',
],
// remove the following attributes
'remove_attributes' => [
'Hat Accessories',
'Glasses',
'Mouth',
'Necklace',
'Piercings',
'Earrings',
],
]);
/*
* update metadata: add trait "Genesis Collection
*/
$nftHandler->run(OperationUpdateMetadata::class, [
// add this trait to all NFTs
'update_attributes' => [
'Genesis Collection' => 'Genesis Collection',
],
]);
/*
* update metadata: remove "dna"
*/
$nftHandler->run(OperationUpdateMetadata::class, [
// remove, if present, the "dna" metadata key and value
'remove_values' => [
'dna',
],
]);
/*
* update metadata: update base URI
*/
$nftHandler->run(OperationUpdateMetadata::class, [
// all "image" metadata will be updated
'update_base_uri' => 'https://example.com/metadata/',
]);
/*
* update metadata: update "name"
*/
$nftHandler->run(OperationUpdateMetadata::class, [
'update_name' => 'CryptoNFT #{id}',
]);
/*
* update metadata: update "external_url"
*/
$nftHandler->run(OperationUpdateMetadata::class, [
'update_external_url' => 'https://foocollection.com',
]);
/*
* Shuffle the entire collection and update "image" and "name" metadata
*/
$nftHandler->run(OperationShuffle::class, [
'update_metadata_image' => 'https://foocollection.com/{id}.png',
'update_metadata_name' => 'Foo NFT #{id}',
]);
/*
* Format metadata applying a standard format
*/
$nftHandler->run(OperationFormatMetadata::class);
文档
请参阅 doc/
文件夹中的文档和示例。
版权和许可证
inmarelibero/nft-manager库版权©Emanuele Gaspari Castelletti,许可使用MIT许可证(MIT)。请参阅LICENSE获取更多信息。