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

调用示例

Java-sdk 调用示例

// 初始化SDK
TDCSDK tdcsdk = new TDCSDK("/root/test-tdc-sdk-conf/conf.yaml");
// 创建名为“tiger01”的集合
String collectionIndex = "tiger01";
String txid = tdcsdk.createNFTCollection(collectionIndex);
System.out.println("Create collection txid: "+txid);

// 生成数字资产meta信息
Metadata md = tdcsdk.newImageMetadata(new String("image bytes").getBytes(),
        "tigerImage","http://obs.huawei.com/1/tiger","description",1);

// 铸造数字资产
MintResp mintResp = tdcsdk.nft721.mint(collectionIndex,"1",md);
System.out.println("Mint nft:"+mintResp.getNft());
System.out.println("Mint txid:"+mintResp.getTxid());

// 生成新的用户信息,包括证书,私钥和地址
IdentityInfo receiver = tdcsdk.generateIdentity(Tools.ECDSA_ALGORITHM,"test1");
System.out.println("cert: "+receiver.getCert());
System.out.println("sk: "+receiver.getKey());
System.out.println("addr: "+receiver.getAddress());

// 查询数字资产所有者
String owner = tdcsdk.nft721.ownerOf(collectionIndex,"1");
System.out.println("collection:"+collectionIndex+", token:1 owner is "+owner);

// 数字资产转移
String transferTxid = tdcsdk.nft721.transferFrom(collectionIndex,owner,receiver.getAddress(),"1");
System.out.println("Transfer txid:"+transferTxid);

// 批量铸造数字资产
String tx = tdcsdk.nft1155.batchMint(collectionIndex, new BatchMintData("10000", "50", md));
System.out.println("BatchMint txid: "+tx);

// 铸造数字资产
MintResp mintResp2 = tdcsdk.nft721.mint(collectionIndex, "2", md);
System.out.println("Mint nft:"+mintResp2.getNft());
System.out.println("Mint txid:"+mintResp2.getTxid());

// 查询数字资产所有者
String ownerOfTokenID = tdcsdk.nft721.ownerOf(collectionIndex,"2");
System.out.println("collection:"+collectionIndex+", token:2 owner is "+ownerOfTokenID);

// 铸造可组合资产
MintResp mintComposeResp = tdcsdk.nft998.mint(collectionIndex, "10", md);
System.out.println("Mint of composable asset nft:"+mintComposeResp.getNft());
System.out.println("Mint of composable asset txid:"+mintComposeResp.getTxid());

// 加入可组合资产
String getChildTxid = tdcsdk.nft998.getChild(ownerOfTokenID, collectionIndex, "10", collectionIndex, "2");
System.out.println("GetChild txid: "+getChildTxid);

// 切换成新的用户身份
tdcsdk.switchIdentityWithPem(Tools.ECDSA_ALGORITHM,receiver.getCert(),receiver.getKey());

// 其他业务调用...

相关文档