Search in sources :

Example 1 with NFTMetadata

use of com.bloxbean.cardano.client.cip.cip25.NFTMetadata in project cardano-client-lib by bloxbean.

the class TxBuilderContextTest method testMintingTwoNFTs_withSamePolicy.

@Test
void testMintingTwoNFTs_withSamePolicy() throws Exception {
    String senderMnemonic = "kit color frog trick speak employ suit sort bomb goddess jewel primary spoil fade person useless measure manage warfare reduce few scrub beyond era";
    Account sender = new Account(Networks.testnet(), senderMnemonic);
    String senderAddress = sender.baseAddress();
    String receiver1 = "addr_test1qqwpl7h3g84mhr36wpetk904p7fchx2vst0z696lxk8ujsjyruqwmlsm344gfux3nsj6njyzj3ppvrqtt36cp9xyydzqzumz82";
    String receiver2 = "addr_test1qq9f6hzuwmqpe3p9h90z2rtgs0v0lsq9ln5f79fjyec7eclg7v88q9als70uzkdh5k6hw20uuwqfz477znfp5v4rga2s3ysgxu";
    String receiver3 = "addr_test1qqqvjp4ffcdqg3fmx0k8rwamnn06wp8e575zcv8d0m3tjn2mmexsnkxp7az774522ce4h3qs4tjp9rxjjm46qf339d9sk33rqn";
    Policy policy = PolicyUtil.createMultiSigScriptAllPolicy("policy-1", 1);
    // Multi asset and NFT metadata
    // NFT-1
    MultiAsset multiAsset1 = new MultiAsset();
    multiAsset1.setPolicyId(policy.getPolicyId());
    Asset asset = new Asset("TestNFT", BigInteger.valueOf(1));
    multiAsset1.getAssets().add(asset);
    NFT nft1 = NFT.create().assetName(asset.getName()).name(asset.getName()).image("ipfs://Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4").mediaType("image/png").addFile(NFTFile.create().name("file-1").mediaType("image/png").src("ipfs/Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4")).description("This is a test NFT");
    // NFT-2
    MultiAsset multiAsset2 = new MultiAsset();
    multiAsset2.setPolicyId(policy.getPolicyId());
    Asset asset2 = new Asset("TestNFT2", BigInteger.valueOf(1));
    multiAsset2.getAssets().add(asset2);
    NFT nft2 = NFT.create().assetName(asset2.getName()).name(asset2.getName()).image("ipfs://Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4").mediaType("image/png").addFile(NFTFile.create().name("file-1").mediaType("image/png").src("ipfs/Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4")).description("This is a test NFT");
    NFTMetadata nftMetadata = NFTMetadata.create().version("1.0").addNFT(policy.getPolicyId(), nft1).addNFT(policy.getPolicyId(), nft2);
    // Define outputs
    // Output using TransactionOutput
    TransactionOutput mintOutput1 = TransactionOutput.builder().address(receiver1).value(Value.builder().coin(adaToLovelace(2.3)).multiAssets(List.of(multiAsset1)).build()).build();
    TransactionOutput mintOutput2 = TransactionOutput.builder().address(receiver2).value(Value.builder().coin(adaToLovelace(1.8)).multiAssets(List.of(multiAsset2)).build()).build();
    // Output using new Output class
    Output output3 = Output.builder().address(receiver3).assetName(LOVELACE).qty(adaToLovelace(4)).build();
    MultiAsset mergeMultiAsset = multiAsset1.plus(multiAsset2);
    // Create TxBuilder function
    TxBuilder txBuilder = createFromMintOutput(mintOutput1).and(createFromMintOutput(mintOutput2)).and(createFromMintOutput(output3)).buildInputs(createFromSender(senderAddress, senderAddress)).andThen(mintCreator(policy.getPolicyScript(), mergeMultiAsset)).andThen(metadataProvider(nftMetadata)).andThen(feeCalculator(senderAddress, 2)).andThen(// any adjustment in change output
    adjustChangeOutput(senderAddress, 2));
    // Build and sign transaction
    Transaction signedTransaction = TxBuilderContext.init(backendService).buildAndSign(txBuilder, signerFrom(sender).andThen(signerFrom(policy)));
    Result<String> result = backendService.getTransactionService().submitTransaction(signedTransaction.serialize());
    System.out.println(result);
    if (result.isSuccessful())
        System.out.println("Transaction Id: " + result.getValue());
    else
        System.out.println("Transaction failed: " + result);
    waitForTransaction(result);
}
Also used : Account(com.bloxbean.cardano.client.account.Account) NFTMetadata(com.bloxbean.cardano.client.cip.cip25.NFTMetadata) OutputBuilders.createFromMintOutput(com.bloxbean.cardano.client.function.helper.OutputBuilders.createFromMintOutput) ChangeOutputAdjustments.adjustChangeOutput(com.bloxbean.cardano.client.function.helper.ChangeOutputAdjustments.adjustChangeOutput) NFT(com.bloxbean.cardano.client.cip.cip25.NFT) BaseITTest(com.bloxbean.cardano.client.backend.api.BaseITTest) Test(org.junit.jupiter.api.Test)

Example 2 with NFTMetadata

use of com.bloxbean.cardano.client.cip.cip25.NFTMetadata in project cardano-client-lib by bloxbean.

the class TxBuilderContextTest method testTransactionBuilding.

@Test
void testTransactionBuilding() throws CborSerializationException, ApiException {
    String senderMnemonic = "stone decade great marine meadow merge boss ahead again rapid detect cover vital estate web silly copper estate wisdom empty speed salute oak car";
    Account senderAccount = new Account(Networks.testnet(), senderMnemonic);
    Output output1 = Output.builder().address("addr_test1qz3s0c370u8zzqn302nppuxl840gm6qdmjwqnxmqxme657ze964mar2m3r5jjv4qrsf62yduqns0tsw0hvzwar07qasqeamp0c").assetName(LOVELACE).qty(BigInteger.valueOf(12000)).build();
    Output output2 = Output.builder().address("addr_test1qq46hhhpppek6e33hqakqyu2z5xeqwlc4pc0xynwamn34l6vps306wwr475xeh2lnt4hqjm4mfyjqnvla9j5wtc3fxespv67ka").assetName(LOVELACE).qty(ONE_ADA.multiply(BigInteger.valueOf(20))).build();
    Output output3 = Output.builder().address("addr_test1qq46hhhpppek6e33hqakqyu2z5xeqwlc4pc0xynwamn34l6vps306wwr475xeh2lnt4hqjm4mfyjqnvla9j5wtc3fxespv67ka").policyId("8bb9f400ee6ec7c81c5afa2c656945c1ab06785b9751993653441e32").assetName("TestAss1").qty(BigInteger.valueOf(8)).build();
    Value value2 = Value.builder().multiAssets(Arrays.asList(MultiAsset.builder().policyId("8bb9f400ee6ec7c81c5afa2c656945c1ab06785b9751993653441e32").assets(Arrays.asList(new Asset("TestAss1", BigInteger.valueOf(5)))).build())).build();
    TxOutputBuilder multiAssetOutputBuilder = OutputBuilders.createFromOutput(new TransactionOutput("addr_test1qz7g6c8w6lzhr5weyus79rl4alepskc6u2pfuzkr7s5qad30ry2sf3u3vq0hzkyhht4uwqy8p40xfy5qkgc79xswq5msnaucg2", value2));
    String senderAddress = senderAccount.baseAddress();
    String changeAddress = senderAccount.baseAddress();
    Policy policy = PolicyUtil.createMultiSigScriptAllPolicy("mypolicy", 1);
    MultiAsset multiAsset = MultiAsset.builder().policyId(policy.getPolicyId()).assets(List.of(Asset.builder().name("xyz_func").value(BigInteger.valueOf(100)).build())).build();
    Policy nftPolicy = PolicyUtil.createMultiSigScriptAllPolicy("nftPolicy", 1);
    MultiAsset nftMultiAsset = MultiAsset.builder().policyId(nftPolicy.getPolicyId()).assets(List.of(Asset.builder().name("nft-1").value(BigInteger.valueOf(1)).build())).build();
    Value mintValue = Value.builder().coin(BigInteger.ZERO).multiAssets(List.of(multiAsset, nftMultiAsset)).build();
    String mintReceiver = "addr_test1qzllzd3cxvz53k9gkq3n3mpcm6g7kv7rj5yvs88n7xwm3nmcs8dpnr85lclka6sycwccput39p0cffqegn8kkf6euzks6h9ldv";
    TxOutputBuilder mintAssetOuputBuilder = OutputBuilders.createFromMintOutput(new TransactionOutput(mintReceiver, mintValue));
    NFT nft = NFT.create().name("nft-1").description("Test nft 1").image("http://imageurl").assetName("nft-1");
    NFTMetadata nftMetadata = NFTMetadata.create().addNFT(nftPolicy.getPolicyId(), nft).version("1.0");
    MessageMetadata metadata = MessageMetadata.create().add("This is test message !! ---");
    // addr_test1qpg4faaydel7n6cq8e4p5kscg6zahmrhlgeke8c6hn6utespky66rz9quy288xqfwc4k2z3v5h4g7gqxpkr8hn9rngvq00hz02
    String secondSenderMnemonic = "reflect robust shy pond spirit hour suffer can million truck final arrow turn lecture worth quarter choose tourist weird lady flee before congress group";
    Account secondSender = new Account(Networks.testnet(), secondSenderMnemonic);
    TxBuilder builder = output1.outputBuilder().and(output2.outputBuilder()).and(output3.outputBuilder()).and(multiAssetOutputBuilder).buildInputs(InputBuilders.createFromSender(senderAddress, changeAddress)).andThen(mintAssetOuputBuilder.buildInputs(InputBuilders.createFromSender(secondSender.baseAddress(), changeAddress))).andThen(MintCreators.mintCreator(nftPolicy.getPolicyScript(), nftMultiAsset)).andThen(MintCreators.mintCreator(policy.getPolicyScript(), multiAsset)).andThen(AuxDataProviders.metadataProvider(metadata)).andThen(AuxDataProviders.metadataProvider(nftMetadata)).andThen(FeeCalculators.feeCalculator(changeAddress, 2 + policy.getPolicyKeys().size() + policy.getPolicyKeys().size()).andThen(ChangeOutputAdjustments.adjustChangeOutput(changeAddress, // Incase changeout goes below min ada after fee deduction
    2 + policy.getPolicyKeys().size() + policy.getPolicyKeys().size())));
    TxSigner signer = signerFrom(senderAccount, secondSender).andThen(signerFrom(policy, nftPolicy));
    Transaction signedTxn = TxBuilderContext.init(backendService).buildAndSign(builder, signer);
    System.out.println(signedTxn);
    Result<String> result = backendService.getTransactionService().submitTransaction(signedTxn.serialize());
    System.out.println(result);
    waitForTransaction(result);
}
Also used : Account(com.bloxbean.cardano.client.account.Account) MessageMetadata(com.bloxbean.cardano.client.cip.cip20.MessageMetadata) NFTMetadata(com.bloxbean.cardano.client.cip.cip25.NFTMetadata) OutputBuilders.createFromMintOutput(com.bloxbean.cardano.client.function.helper.OutputBuilders.createFromMintOutput) ChangeOutputAdjustments.adjustChangeOutput(com.bloxbean.cardano.client.function.helper.ChangeOutputAdjustments.adjustChangeOutput) NFT(com.bloxbean.cardano.client.cip.cip25.NFT) BaseITTest(com.bloxbean.cardano.client.backend.api.BaseITTest) Test(org.junit.jupiter.api.Test)

Example 3 with NFTMetadata

use of com.bloxbean.cardano.client.cip.cip25.NFTMetadata in project cardano-client-lib by bloxbean.

the class TxBuilderContextTest method testMintingTwoNFTs_withSamePolicyAndAssetName_differentReceivers.

@Test
void testMintingTwoNFTs_withSamePolicyAndAssetName_differentReceivers() throws Exception {
    String senderMnemonic = "kit color frog trick speak employ suit sort bomb goddess jewel primary spoil fade person useless measure manage warfare reduce few scrub beyond era";
    Account sender = new Account(Networks.testnet(), senderMnemonic);
    String senderAddress = sender.baseAddress();
    String receiver1 = "addr_test1qqwpl7h3g84mhr36wpetk904p7fchx2vst0z696lxk8ujsjyruqwmlsm344gfux3nsj6njyzj3ppvrqtt36cp9xyydzqzumz82";
    String receiver2 = "addr_test1qq9f6hzuwmqpe3p9h90z2rtgs0v0lsq9ln5f79fjyec7eclg7v88q9als70uzkdh5k6hw20uuwqfz477znfp5v4rga2s3ysgxu";
    String receiver3 = "addr_test1qqqvjp4ffcdqg3fmx0k8rwamnn06wp8e575zcv8d0m3tjn2mmexsnkxp7az774522ce4h3qs4tjp9rxjjm46qf339d9sk33rqn";
    Policy policy = PolicyUtil.createMultiSigScriptAllPolicy("policy-1", 1);
    // Multi asset and NFT metadata
    // NFT-1
    MultiAsset multiAsset1 = new MultiAsset();
    multiAsset1.setPolicyId(policy.getPolicyId());
    Asset asset = new Asset("TestNFT", BigInteger.valueOf(1));
    multiAsset1.getAssets().add(asset);
    NFT nft1 = NFT.create().assetName(asset.getName()).name(asset.getName()).image("ipfs://Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4").mediaType("image/png").addFile(NFTFile.create().name("file-1").mediaType("image/png").src("ipfs/Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4")).description("This is a test NFT");
    // NFT-2
    MultiAsset multiAsset2 = new MultiAsset();
    multiAsset2.setPolicyId(policy.getPolicyId());
    Asset asset2 = new Asset("TestNFT", BigInteger.valueOf(1));
    multiAsset2.getAssets().add(asset2);
    NFT nft2 = NFT.create().assetName(asset.getName()).name(asset.getName()).image("ipfs://Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4").mediaType("image/png").addFile(NFTFile.create().name("file-1").mediaType("image/png").src("ipfs/Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4")).description("This is a test NFT");
    NFTMetadata nftMetadata = NFTMetadata.create().version("1.0").addNFT(policy.getPolicyId(), nft1).addNFT(policy.getPolicyId(), nft2);
    // Define outputs
    // Output using TransactionOutput
    TransactionOutput mintOutput1 = TransactionOutput.builder().address(receiver1).value(Value.builder().coin(adaToLovelace(2.3)).multiAssets(List.of(multiAsset1)).build()).build();
    TransactionOutput mintOutput2 = TransactionOutput.builder().address(receiver2).value(Value.builder().coin(adaToLovelace(1.8)).multiAssets(List.of(multiAsset2)).build()).build();
    // Output using new Output class
    Output output3 = Output.builder().address(receiver3).assetName(LOVELACE).qty(adaToLovelace(4)).build();
    MultiAsset mergeMultiAsset = multiAsset1.plus(multiAsset2);
    // Create TxBuilder function
    TxBuilder txBuilder = createFromMintOutput(mintOutput1).and(createFromMintOutput(mintOutput2)).and(createFromMintOutput(output3)).buildInputs(createFromSender(senderAddress, senderAddress)).andThen(mintCreator(policy.getPolicyScript(), mergeMultiAsset)).andThen(metadataProvider(nftMetadata)).andThen(feeCalculator(senderAddress, 2)).andThen(// any adjustment in change output
    adjustChangeOutput(senderAddress, 2));
    // Build and sign transaction
    Transaction signedTransaction = TxBuilderContext.init(backendService).buildAndSign(txBuilder, signerFrom(sender).andThen(signerFrom(policy)));
    Result<String> result = backendService.getTransactionService().submitTransaction(signedTransaction.serialize());
    System.out.println(result);
    if (result.isSuccessful())
        System.out.println("Transaction Id: " + result.getValue());
    else
        System.out.println("Transaction failed: " + result);
    waitForTransaction(result);
}
Also used : Account(com.bloxbean.cardano.client.account.Account) NFTMetadata(com.bloxbean.cardano.client.cip.cip25.NFTMetadata) OutputBuilders.createFromMintOutput(com.bloxbean.cardano.client.function.helper.OutputBuilders.createFromMintOutput) ChangeOutputAdjustments.adjustChangeOutput(com.bloxbean.cardano.client.function.helper.ChangeOutputAdjustments.adjustChangeOutput) NFT(com.bloxbean.cardano.client.cip.cip25.NFT) BaseITTest(com.bloxbean.cardano.client.backend.api.BaseITTest) Test(org.junit.jupiter.api.Test)

Example 4 with NFTMetadata

use of com.bloxbean.cardano.client.cip.cip25.NFTMetadata in project cardano-client-lib by bloxbean.

the class CIP25NFTTransactionITTest method mintToken.

@Test
public void mintToken() throws CborSerializationException, ApiException, AddressExcepion {
    long currentSlot = queryTipSlot();
    assertNotEquals(0, currentSlot);
    Policy policy = PolicyUtil.createEpochBasedTimeLockedPolicy("CIP25PolicyTimeLockedPolicy", currentSlot, 5L);
    String assetName = "NFTTest-" + new Random().nextInt();
    MultiAsset multiAsset = new MultiAsset();
    multiAsset.setPolicyId(policy.getPolicyId());
    Asset asset = new Asset(HexUtil.encodeHexString(assetName.getBytes(StandardCharsets.UTF_8), true), BigInteger.valueOf(1));
    multiAsset.getAssets().add(asset);
    Map<String, String> datePropsMap = new HashMap<>();
    datePropsMap.put("year", "2021");
    datePropsMap.put("month", "Dec");
    NFT nft = NFT.create().assetName(assetName).name(assetName).image("ipfs://Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4").mediaType("image/png").addFile(NFTFile.create().name("file-1").mediaType("image/png").src("ipfs/Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4")).description("This is a test NFT").description("This is a test NFT-2").property("Artist", "Simply NFT").property("Brand", "My Brand").property("Series", "2").property("Attributes", Arrays.asList("Accessory", "Chain", "Clothing")).property("date", datePropsMap);
    // Add some extra attributes
    nft.putNegative("longitude", new BigInteger("-1223787"));
    NFTMetadata nftMetadata = NFTMetadata.create().addNFT(policy.getPolicyId(), nft);
    System.out.println("Metadata: " + nftMetadata.toJson());
    MintTransaction mintTransaction = MintTransaction.builder().sender(sender).receiver(receiver).mintAssets(Arrays.asList(multiAsset)).policy(policy).build();
    BigInteger fee = feeCalculationService.calculateFee(mintTransaction, TransactionDetailsParams.builder().ttl(getTtl()).build(), nftMetadata);
    mintTransaction.setFee(fee);
    System.out.println(fee);
    Result<TransactionResult> result = transactionHelperService.mintToken(mintTransaction, TransactionDetailsParams.builder().ttl(getTtl()).build(), nftMetadata);
    System.out.println("Request: \n" + JsonUtil.getPrettyJson(mintTransaction));
    if (result.isSuccessful())
        System.out.println("Transaction Id: " + result.getValue());
    else
        System.out.println("Transaction failed: " + result);
    waitForTransaction(result);
    assertThat(result.isSuccessful(), is(true));
    if (result.isSuccessful()) {
        System.out.println("Transaction Id: " + result.getValue().getTransactionId());
        System.out.println("Policy Id: " + policy.getPolicyId());
        System.out.println("Asset Name: " + assetName);
    }
}
Also used : Policy(com.bloxbean.cardano.client.transaction.spec.Policy) TransactionResult(com.bloxbean.cardano.client.backend.api.helper.model.TransactionResult) HashMap(java.util.HashMap) MintTransaction(com.bloxbean.cardano.client.transaction.model.MintTransaction) MultiAsset(com.bloxbean.cardano.client.transaction.spec.MultiAsset) Random(java.util.Random) NFTMetadata(com.bloxbean.cardano.client.cip.cip25.NFTMetadata) MultiAsset(com.bloxbean.cardano.client.transaction.spec.MultiAsset) Asset(com.bloxbean.cardano.client.transaction.spec.Asset) BigInteger(java.math.BigInteger) NFT(com.bloxbean.cardano.client.cip.cip25.NFT) Test(org.junit.jupiter.api.Test)

Example 5 with NFTMetadata

use of com.bloxbean.cardano.client.cip.cip25.NFTMetadata in project cardano-client-lib by bloxbean.

the class TxBuilderContextTest method testMintingTwoNFTs_withSamePolicyAndAssetName_differentReceivers_withOutputClass.

@Test
void testMintingTwoNFTs_withSamePolicyAndAssetName_differentReceivers_withOutputClass() throws Exception {
    String senderMnemonic = "kit color frog trick speak employ suit sort bomb goddess jewel primary spoil fade person useless measure manage warfare reduce few scrub beyond era";
    Account sender = new Account(Networks.testnet(), senderMnemonic);
    String senderAddress = sender.baseAddress();
    String receiver1 = "addr_test1qqwpl7h3g84mhr36wpetk904p7fchx2vst0z696lxk8ujsjyruqwmlsm344gfux3nsj6njyzj3ppvrqtt36cp9xyydzqzumz82";
    String receiver2 = "addr_test1qq9f6hzuwmqpe3p9h90z2rtgs0v0lsq9ln5f79fjyec7eclg7v88q9als70uzkdh5k6hw20uuwqfz477znfp5v4rga2s3ysgxu";
    String receiver3 = "addr_test1qqqvjp4ffcdqg3fmx0k8rwamnn06wp8e575zcv8d0m3tjn2mmexsnkxp7az774522ce4h3qs4tjp9rxjjm46qf339d9sk33rqn";
    Policy policy = PolicyUtil.createMultiSigScriptAllPolicy("policy-1", 1);
    // Multi asset and NFT metadata
    // NFT-1
    MultiAsset multiAsset1 = new MultiAsset();
    multiAsset1.setPolicyId(policy.getPolicyId());
    Asset asset = new Asset("TestNFT", BigInteger.valueOf(1));
    multiAsset1.getAssets().add(asset);
    NFT nft1 = NFT.create().assetName(asset.getName()).name(asset.getName()).image("ipfs://Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4").mediaType("image/png").addFile(NFTFile.create().name("file-1").mediaType("image/png").src("ipfs/Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4")).description("This is a test NFT");
    // NFT-2
    MultiAsset multiAsset2 = new MultiAsset();
    multiAsset2.setPolicyId(policy.getPolicyId());
    Asset asset2 = new Asset("TestNFT", BigInteger.valueOf(1));
    multiAsset2.getAssets().add(asset2);
    NFT nft2 = NFT.create().assetName(asset.getName()).name(asset.getName()).image("ipfs://Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4").mediaType("image/png").addFile(NFTFile.create().name("file-1").mediaType("image/png").src("ipfs/Qmcv6hwtmdVumrNeb42R1KmCEWdYWGcqNgs17Y3hj6CkP4")).description("This is a test NFT");
    NFTMetadata nftMetadata = NFTMetadata.create().version("1.0").addNFT(policy.getPolicyId(), nft1).addNFT(policy.getPolicyId(), nft2);
    // Define outputs
    // Output using Output class
    Output output1 = Output.builder().address(receiver1).assetName(LOVELACE).qty(adaToLovelace(2.3)).build();
    Output output11 = Output.builder().address(receiver1).policyId(policy.getPolicyId()).assetName("TestNFT").qty(BigInteger.valueOf(1)).build();
    Output output2 = Output.builder().address(receiver2).assetName(LOVELACE).qty(adaToLovelace(1.8)).build();
    Output output21 = Output.builder().address(receiver2).policyId(policy.getPolicyId()).assetName("TestNFT").qty(BigInteger.valueOf(1)).build();
    // Output using new Output class
    Output output3 = Output.builder().address(receiver3).assetName(LOVELACE).qty(adaToLovelace(4)).build();
    MultiAsset mergeMultiAsset = multiAsset1.plus(multiAsset2);
    // Create TxBuilder function
    TxBuilder txBuilder = output1.outputBuilder().and(output11.mintOutputBuilder()).and(output2.outputBuilder()).and(output21.mintOutputBuilder()).and(// An alternate way
    createFromMintOutput(output3)).buildInputs(createFromSender(senderAddress, senderAddress)).andThen(mintCreator(policy.getPolicyScript(), mergeMultiAsset)).andThen(metadataProvider(nftMetadata)).andThen(feeCalculator(senderAddress, 2)).andThen(// any adjustment in change output
    adjustChangeOutput(senderAddress, 2));
    // Build and sign transaction
    Transaction signedTransaction = TxBuilderContext.init(backendService).buildAndSign(txBuilder, signerFrom(sender).andThen(signerFrom(policy)));
    Result<String> result = backendService.getTransactionService().submitTransaction(signedTransaction.serialize());
    System.out.println(result);
    if (result.isSuccessful())
        System.out.println("Transaction Id: " + result.getValue());
    else
        System.out.println("Transaction failed: " + result);
    waitForTransaction(result);
}
Also used : Account(com.bloxbean.cardano.client.account.Account) NFTMetadata(com.bloxbean.cardano.client.cip.cip25.NFTMetadata) OutputBuilders.createFromMintOutput(com.bloxbean.cardano.client.function.helper.OutputBuilders.createFromMintOutput) ChangeOutputAdjustments.adjustChangeOutput(com.bloxbean.cardano.client.function.helper.ChangeOutputAdjustments.adjustChangeOutput) NFT(com.bloxbean.cardano.client.cip.cip25.NFT) BaseITTest(com.bloxbean.cardano.client.backend.api.BaseITTest) Test(org.junit.jupiter.api.Test)

Aggregations

NFT (com.bloxbean.cardano.client.cip.cip25.NFT)5 NFTMetadata (com.bloxbean.cardano.client.cip.cip25.NFTMetadata)5 Test (org.junit.jupiter.api.Test)5 Account (com.bloxbean.cardano.client.account.Account)4 BaseITTest (com.bloxbean.cardano.client.backend.api.BaseITTest)4 ChangeOutputAdjustments.adjustChangeOutput (com.bloxbean.cardano.client.function.helper.ChangeOutputAdjustments.adjustChangeOutput)4 OutputBuilders.createFromMintOutput (com.bloxbean.cardano.client.function.helper.OutputBuilders.createFromMintOutput)4 TransactionResult (com.bloxbean.cardano.client.backend.api.helper.model.TransactionResult)1 MessageMetadata (com.bloxbean.cardano.client.cip.cip20.MessageMetadata)1 MintTransaction (com.bloxbean.cardano.client.transaction.model.MintTransaction)1 Asset (com.bloxbean.cardano.client.transaction.spec.Asset)1 MultiAsset (com.bloxbean.cardano.client.transaction.spec.MultiAsset)1 Policy (com.bloxbean.cardano.client.transaction.spec.Policy)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1