更新时间:2022-09-26 GMT+08:00
分享

调用示例

php-sdk 调用示例

<?php
use Dac\DACSDK;
if (file_exists('Dac/vendor/autoload.php')) {
    require 'Dac/vendor/autoload.php';
} else {
    require '../Dac/vendor/autoload.php';
}
$filePath = 'D:\\temp\\w3shared\\conf.yaml';
// 初始化SDK
$tdcsdk = new DACSDK($filePath);
// 创建名为“tiger01”的集合
$collectionIndex = "tiger01";
$txid = $tdcsdk->nft721->createNFTCollection($collectionIndex);
echo "Create collection txid: " . $txid . "\n";
echo '<br>';
// 生成数字资产meta信息
$md = $tdcsdk->toolManager->newImageMetadata("image bytes",
    "tigerImage", "http://obs.huawei.com/1/tiger", "description", 1);
// 铸造数字资产
$mintResp = $tdcsdk->nft721->mint($collectionIndex, "1", $md);
echo "Mint nft:" . $mintResp->getNft()->getTokenURI();
echo '<br>';
echo "Mint txid:" . $mintResp->getTxid() . "\n";
echo '<br>';
// 生成新的用户信息,包括证书,私钥和地址
$receiver = $tdcsdk->toolManager->generateIdentity(\Dac\Manager\ToolManager::ECDSAAlgorithm, "test1");
echo "cert: " . $receiver->getCert() . "\n";
echo '<br>';
echo "sk: " . $receiver->getKey() . "\n";
echo '<br>';
echo "addr: " . $receiver->getAddress() . "\n";
echo '<br>';
sleep(2);
// 查询数字资产所有者
$owner = $tdcsdk->nft721->ownerOf($collectionIndex, "1");
echo "collection:" . $collectionIndex . ", token:1 owner is " . $owner . "\n";
echo '<br>';
// 数字资产转移
$transferTxid = $tdcsdk->nft721->transferFrom($collectionIndex, $owner, $receiver->getAddress(), "1");
echo "Transfer txid:" . $transferTxid . '\n';
echo '<br>';
// 批量铸造数字资产
$bmd = new \Dac\Model\BatchMintData("10000", "50", $md);
$tx = $tdcsdk->nft1155->batchMint($collectionIndex, $bmd);
echo "BatchMint txid: " . $tx;
echo '<br>';
// 铸造数字资产
$mintResp = $tdcsdk->nft721->mint($collectionIndex, "2", $md);
echo "Mint nft: " . $mintResp->getNft()->getTokenURI();
echo '<br>';
echo "Mint txid: " . $mintResp->getTxid() . "\n";
echo '<br>';
// 铸造可组合资产
$mintResp = $tdcsdk->nft998->mint($collectionIndex, "10", $md);
echo "Mint of composable asset nft: " . $mintResp->getNft()->getTokenURI();
echo '<br>';
echo "Mint of composable asset txid: " . $mintResp->getTxid() . "\n";
echo '<br>';
// 加入可组合资产
$getChildTxid = $tdcsdk->nft998->getChild($owner, $collectionIndex, "10", $collectionIndex, "2");
echo "GetChildTxid txid: " . $getChildTxid;
echo '<br>';
// 切换成新的用户身份
$tdcsdk->toolManager->switchIdentityWithPem(\Dac\Manager\ToolManager::ECDSAAlgorithm, $receiver->getCert(), $receiver->getKey());
分享:

    相关文档

    相关产品