# OPTION 1defbuild_prefunded_message_transaction(recipient_address,message):# Build the embedded message transactionmessage_transaction=(facade.create_embedded_transaction_from_descriptor({'type':'transfer_transaction_v1','recipient_address':recipient_address,'message':message},user_key_pair.public_key))# Build the embedded prefund transactionprefund_transaction=(facade.create_embedded_transaction_from_descriptor({'type':'transfer_transaction_v1','recipient_address':facade.network.public_key_to_address(user_key_pair.public_key),'mosaics':[{'mosaic_id':generate_mosaic_alias_id('symbol.xym'),'amount':0# To be filled once value is known}]},app_key_pair.public_key))# Build the wrapper complete aggregate transactiontransaction=facade.create_transaction_from_descriptor({'type':'aggregate_complete_transaction_v3','transactions_hash':facade.hash_embedded_transactions([message_transaction,prefund_transaction]),'transactions':[message_transaction,prefund_transaction]},user_key_pair.public_key,fee_multiplier,2*60*60,1)# Update the prefund amount to match the total feeprefund_transaction.mosaics[0].amount=transaction.fee# Update the embedded transaction hashestransaction.transactions_hash=Hash256(facade.hash_embedded_transactions([message_transaction,prefund_transaction]).bytes)# Sign the aggregate transaction using the user's signaturefacade.transaction_factory.attach_signature(transaction,facade.sign_transaction(user_key_pair,transaction))# Attach the app's cosignaturetransaction.cosignatures.append(facade.cosign_transaction(app_key_pair,transaction))# Obtain the payloadjson_payload=facade.transaction_factory.to_json(transaction)return(transaction,json_payload)
functionbuildPrefundedMessageTransaction(recipientAddress,message){// Build the embedded message transactionconstmessageTransaction=facade.createEmbeddedTransactionFromTypedDescriptor(newdescriptors.TransferTransactionV1Descriptor(newAddress(recipientAddress),undefined,message),userKeyPair.publicKey);// Build the embedded prefund transactionconstprefundTransaction=facade.createEmbeddedTransactionFromTypedDescriptor(newdescriptors.TransferTransactionV1Descriptor(facade.network.publicKeyToAddress(userKeyPair.publicKey),[newdescriptors.UnresolvedMosaicDescriptor(generateMosaicAliasId('symbol.xym'),// To be filled once value is known.newmodels.Amount(0n))],undefined),appKeyPair.publicKey);// Build the wrapper complete aggregate transactionconsttransaction=facade.createTransactionFromTypedDescriptor(newdescriptors.AggregateCompleteTransactionV3Descriptor(facade.static.hashEmbeddedTransactions([messageTransaction,prefundTransaction]),[messageTransaction,prefundTransaction],undefined),userKeyPair.publicKey,feeMultiplier,2*60*60,1);// Update the prefund amount to match the total feeprefundTransaction.mosaics[0].amount=transaction.fee;// Update the embedded transaction hashestransaction.transactionsHash=newmodels.Hash256(facade.static.hashEmbeddedTransactions([messageTransaction,prefundTransaction]).bytes);// Sign the aggregate transaction using the user's signaturefacade.transactionFactory.static.attachSignature(transaction,facade.signTransaction(userKeyPair,transaction));// Attach the app's cosignaturetransaction.cosignatures.push(facade.cosignTransaction(appKeyPair,transaction));// Obtain the payloadconstjsonPayload=facade.transactionFactory.static.toJson(transaction);return{transaction,jsonPayload};}
// OPTION 1privateTransactionAndPayloadbuildPrefundedMessageTransaction(finalStringrecipientAddress,finalStringmessage)throwsIOException{// Build the embedded message transactionfinalEmbeddedTransactionmessageTransaction=facade.createEmbeddedTransactionFromTypedDescriptor(newTransferTransactionV1Descriptor(newAddress(recipientAddress),null,message.getBytes(StandardCharsets.UTF_8)),userKeyPair.getPublicKey());// Build the embedded prefund transactionfinalEmbeddedTransferTransactionV1prefundTransaction=(EmbeddedTransferTransactionV1)facade.createEmbeddedTransactionFromTypedDescriptor(newTransferTransactionV1Descriptor(facade.network.publicKeyToAddress(userKeyPair.getPublicKey()),List.of(newUnresolvedMosaicDescriptor(newUnresolvedMosaicId(IdGenerator.generateMosaicAliasId("symbol.xym")),// To be filled once value is known.newAmount(0))),null),appKeyPair.getPublicKey());// Build the wrapper complete aggregate transactionfinalList<EmbeddedTransaction>transactions=List.of(messageTransaction,prefundTransaction);finalAggregateCompleteTransactionV3transaction=(AggregateCompleteTransactionV3)facade.createTransactionFromTypedDescriptor(newAggregateCompleteTransactionV3Descriptor(SymbolFacade.hashEmbeddedTransactions(transactions),transactions,null),userKeyPair.getPublicKey(),feeMultiplier,2*60*60,1);// Update the prefund amount to match the total feeprefundTransaction.getMosaics().get(0).setAmount(transaction.getFee());// Update the embedded transaction hashestransaction.setTransactionsHash(Hash256.parse(SymbolFacade.hashEmbeddedTransactions(transactions)));// Sign the aggregate transaction using the user's signatureSymbolTransactionFactory.attachSignature(transaction,facade.signTransaction(userKeyPair,transaction));// Attach the app's cosignaturetransaction.getCosignatures().add(facade.cosignTransaction(appKeyPair,transaction));// Obtain the payloadfinalStringjsonPayload=SymbolTransactionFactory.toJson(transaction);returnnewTransactionAndPayload(transaction,jsonPayload);}
# Build the embedded prefund transactionprefund_transaction=(facade.create_embedded_transaction_from_descriptor({'type':'transfer_transaction_v1','recipient_address':facade.network.public_key_to_address(user_key_pair.public_key),'mosaics':[{'mosaic_id':generate_mosaic_alias_id('symbol.xym'),'amount':0# To be filled once value is known}]},app_key_pair.public_key))
// Build the embedded prefund transactionconstprefundTransaction=facade.createEmbeddedTransactionFromTypedDescriptor(newdescriptors.TransferTransactionV1Descriptor(facade.network.publicKeyToAddress(userKeyPair.publicKey),[newdescriptors.UnresolvedMosaicDescriptor(generateMosaicAliasId('symbol.xym'),// To be filled once value is known.newmodels.Amount(0n))],undefined),appKeyPair.publicKey);
// Build the embedded prefund transactionfinalEmbeddedTransferTransactionV1prefundTransaction=(EmbeddedTransferTransactionV1)facade.createEmbeddedTransactionFromTypedDescriptor(newTransferTransactionV1Descriptor(facade.network.publicKeyToAddress(userKeyPair.getPublicKey()),List.of(newUnresolvedMosaicDescriptor(newUnresolvedMosaicId(IdGenerator.generateMosaicAliasId("symbol.xym")),// To be filled once value is known.newAmount(0))),null),appKeyPair.getPublicKey());
# Build the wrapper complete aggregate transactiontransaction=facade.create_transaction_from_descriptor({'type':'aggregate_complete_transaction_v3','transactions_hash':facade.hash_embedded_transactions([message_transaction,prefund_transaction]),'transactions':[message_transaction,prefund_transaction]},user_key_pair.public_key,fee_multiplier,2*60*60,1)# Update the prefund amount to match the total feeprefund_transaction.mosaics[0].amount=transaction.fee# Update the embedded transaction hashestransaction.transactions_hash=Hash256(facade.hash_embedded_transactions([message_transaction,prefund_transaction]).bytes)
// Build the wrapper complete aggregate transactionconsttransaction=facade.createTransactionFromTypedDescriptor(newdescriptors.AggregateCompleteTransactionV3Descriptor(facade.static.hashEmbeddedTransactions([messageTransaction,prefundTransaction]),[messageTransaction,prefundTransaction],undefined),userKeyPair.publicKey,feeMultiplier,2*60*60,1);// Update the prefund amount to match the total feeprefundTransaction.mosaics[0].amount=transaction.fee;// Update the embedded transaction hashestransaction.transactionsHash=newmodels.Hash256(facade.static.hashEmbeddedTransactions([messageTransaction,prefundTransaction]).bytes);
// Build the wrapper complete aggregate transactionfinalList<EmbeddedTransaction>transactions=List.of(messageTransaction,prefundTransaction);finalAggregateCompleteTransactionV3transaction=(AggregateCompleteTransactionV3)facade.createTransactionFromTypedDescriptor(newAggregateCompleteTransactionV3Descriptor(SymbolFacade.hashEmbeddedTransactions(transactions),transactions,null),userKeyPair.getPublicKey(),feeMultiplier,2*60*60,1);// Update the prefund amount to match the total feeprefundTransaction.getMosaics().get(0).setAmount(transaction.getFee());// Update the embedded transaction hashestransaction.setTransactionsHash(Hash256.parse(SymbolFacade.hashEmbeddedTransactions(transactions)));
# Sign the aggregate transaction using the user's signaturefacade.transaction_factory.attach_signature(transaction,facade.sign_transaction(user_key_pair,transaction))# Attach the app's cosignaturetransaction.cosignatures.append(facade.cosign_transaction(app_key_pair,transaction))# Obtain the payloadjson_payload=facade.transaction_factory.to_json(transaction)
// Sign the aggregate transaction using the user's signaturefacade.transactionFactory.static.attachSignature(transaction,facade.signTransaction(userKeyPair,transaction));// Attach the app's cosignaturetransaction.cosignatures.push(facade.cosignTransaction(appKeyPair,transaction));// Obtain the payloadconstjsonPayload=facade.transactionFactory.static.toJson(transaction);
// Sign the aggregate transaction using the user's signatureSymbolTransactionFactory.attachSignature(transaction,facade.signTransaction(userKeyPair,transaction));// Attach the app's cosignaturetransaction.getCosignatures().add(facade.cosignTransaction(appKeyPair,transaction));// Obtain the payloadfinalStringjsonPayload=SymbolTransactionFactory.toJson(transaction);
# OPTION 2defbuild_sponsored_message_transaction(recipient_address,message):# Build the embedded message transactionmessage_transaction=(facade.create_embedded_transaction_from_descriptor({'type':'transfer_transaction_v1','recipient_address':recipient_address,'message':message},user_key_pair.public_key))# Build the embedded filler transactionfiller_transaction=(facade.create_embedded_transaction_from_descriptor({'type':'transfer_transaction_v1','recipient_address':facade.network.public_key_to_address(app_key_pair.public_key)},app_key_pair.public_key))# Build the wrapper complete aggregate transactiontransaction=facade.create_transaction_from_descriptor({'type':'aggregate_complete_transaction_v3','transactions_hash':facade.hash_embedded_transactions([message_transaction,filler_transaction]),'transactions':[message_transaction,filler_transaction]},app_key_pair.public_key,fee_multiplier,2*60*60,1)# Sign the aggregate transaction using the app's signaturefacade.transaction_factory.attach_signature(transaction,facade.sign_transaction(app_key_pair,transaction))# Attach the users's cosignaturetransaction.cosignatures.append(facade.cosign_transaction(user_key_pair,transaction))# Obtain the payloadjson_payload=facade.transaction_factory.to_json(transaction)return(transaction,json_payload)
functionbuildSponsoredMessageTransaction(recipientAddress,message){// Build the embedded message transactionconstmessageTransaction=facade.createEmbeddedTransactionFromTypedDescriptor(newdescriptors.TransferTransactionV1Descriptor(newAddress(recipientAddress),undefined,message),userKeyPair.publicKey);// Build the embedded filler transactionconstfillerTransaction=facade.createEmbeddedTransactionFromTypedDescriptor(newdescriptors.TransferTransactionV1Descriptor(facade.network.publicKeyToAddress(appKeyPair.publicKey),undefined,undefined),appKeyPair.publicKey);// Build the wrapper complete aggregate transactionconsttransaction=facade.createTransactionFromTypedDescriptor(newdescriptors.AggregateCompleteTransactionV3Descriptor(facade.static.hashEmbeddedTransactions([messageTransaction,fillerTransaction]),[messageTransaction,fillerTransaction],undefined),appKeyPair.publicKey,feeMultiplier,2*60*60,1);// Sign the aggregate transaction using the app's signaturefacade.transactionFactory.static.attachSignature(transaction,facade.signTransaction(appKeyPair,transaction));// Attach the user's cosignaturetransaction.cosignatures.push(facade.cosignTransaction(userKeyPair,transaction));// Obtain the payloadconstjsonPayload=facade.transactionFactory.static.toJson(transaction);return{transaction,jsonPayload};}
// OPTION 2privateTransactionAndPayloadbuildSponsoredMessageTransaction(finalStringrecipientAddress,finalStringmessage)throwsIOException{// Build the embedded message transactionfinalEmbeddedTransactionmessageTransaction=facade.createEmbeddedTransactionFromTypedDescriptor(newTransferTransactionV1Descriptor(newAddress(recipientAddress),null,message.getBytes(StandardCharsets.UTF_8)),userKeyPair.getPublicKey());// Build the embedded filler transactionfinalEmbeddedTransactionfillerTransaction=facade.createEmbeddedTransactionFromTypedDescriptor(newTransferTransactionV1Descriptor(facade.network.publicKeyToAddress(appKeyPair.getPublicKey()),null,null),appKeyPair.getPublicKey());// Build the wrapper complete aggregate transactionfinalList<EmbeddedTransaction>transactions=List.of(messageTransaction,fillerTransaction);finalAggregateCompleteTransactionV3transaction=(AggregateCompleteTransactionV3)facade.createTransactionFromTypedDescriptor(newAggregateCompleteTransactionV3Descriptor(SymbolFacade.hashEmbeddedTransactions(transactions),transactions,null),appKeyPair.getPublicKey(),feeMultiplier,2*60*60,1);// Sign the aggregate transaction using the app's signatureSymbolTransactionFactory.attachSignature(transaction,facade.signTransaction(appKeyPair,transaction));// Attach the user's cosignaturetransaction.getCosignatures().add(facade.cosignTransaction(userKeyPair,transaction));// Obtain the payloadfinalStringjsonPayload=SymbolTransactionFactory.toJson(transaction);returnnewTransactionAndPayload(transaction,jsonPayload);}
# Sign the aggregate transaction using the app's signaturefacade.transaction_factory.attach_signature(transaction,facade.sign_transaction(app_key_pair,transaction))# Attach the users's cosignaturetransaction.cosignatures.append(facade.cosign_transaction(user_key_pair,transaction))# Obtain the payloadjson_payload=facade.transaction_factory.to_json(transaction)
// Sign the aggregate transaction using the app's signaturefacade.transactionFactory.static.attachSignature(transaction,facade.signTransaction(appKeyPair,transaction));// Attach the user's cosignaturetransaction.cosignatures.push(facade.cosignTransaction(userKeyPair,transaction));// Obtain the payloadconstjsonPayload=facade.transactionFactory.static.toJson(transaction);
// Sign the aggregate transaction using the app's signatureSymbolTransactionFactory.attachSignature(transaction,facade.signTransaction(appKeyPair,transaction));// Attach the user's cosignaturetransaction.getCosignatures().add(facade.cosignTransaction(userKeyPair,transaction));// Obtain the payloadfinalStringjsonPayload=SymbolTransactionFactory.toJson(transaction);