2

I would like to create transaction using IotaWallet of wallet.rs containing a message or tag.

Currently I perfectly create a transaction for Alice wallet, using:

from iota_wallet import IotaWallet

# This example sends a transaction.

wallet = IotaWallet('./alice-database', client_options)

account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync()
print(f'Synced: {response}')

wallet.set_stronghold_password("some_hopefully_secure_password")

options = {
        "message": "abc",
        #OR
        "tag": "abc"
}

outputs = [{
        "address": "tst1qprutadk4uc9rp6h7wh7sech42sl0z40ztpgyygr5tf0cn5jrqshg80juhm",
        "amount": "1"
}]


transaction = account.send_micro_transaction(outputs, options)
#OR
#transaction = account.send_amount(outputs, options)

print(f'Sent transaction: {transaction}') 

But there is no trace of "Message" or "Tag" related to the created transaction in the IOTA explorer or starting from account.transacations() or account.pending_transactions() methods.

In documentation examples I don't find anything.

Thank you for your help!

4 Answers 4

2

You can do something like:

outputs = [{
    "address": "rms1qqvnuxck92uwvf2hjpr0m9m0rj565efvchcy0xj9u5w8cwprqealva8g48e",
    "amount": "42600",
}]

tag = '0x'+'custom_tag'.encode('utf-8').hex()
data = '0x'+'custom_data'.encode('utf-8').hex()

transaction = account.send_amount(outputs, options={"taggedDataPayload": {"type": 5, "tag": tag, "data": data}})

This will create a block with a tagged payload. I created the example transaction: https://explorer.shimmer.network/testnet/transaction/0xb04a92b0e8bc52a4a2d85dd538f23c2201aa899d554428925f3ddf94b72a30ee?tab=Payload

And in the related block: https://explorer.shimmer.network/testnet/block/0xa0a69edc125eef56775185cd55a8ef9d96264d79f996047eff8e410aedee3b2b

you can find the added tagged data payload

2
  • 1
    Thank you so much Dr. Electon! Your solution is correctly working. Where can I find any reference about that please? In particular "type": 5. Commented May 16, 2023 at 7:26
  • 2
    The payload types are documented in the TIPs: wiki.iota.org/tips/tips/TIP-0024/#payloads But you shouldn't need to know that, that's why we are working on improving the DX there in a future release Commented May 18, 2023 at 7:27
2

There are several ways to do this, but please note that tag is not indexed by the core API anymore:

  1. You can write something like this: sendMicroTransaction(outputs, transactionOptions). Reference Wiki. You can add taggedatapayload to transactionOptions and it should tag it. Example in Explorer. Read more about TransactionOptions on wiki.

  2. With Stardust, you can also add data to the outputs now.

2
  • Thanks for answer, but Python Reference Wiki is less simple than yours attached in Node.js. There is not a TransactionOptions interface, but just a parameter and it doesn't work. Commented May 15, 2023 at 14:51
  • It should ideally be same with options. If it's not working, please raise an issue in wallet.rs repo.
    – Ani
    Commented May 15, 2023 at 21:29
0

I am using the Java bindings and wanted to use the TaggedDataPayload. I am a bit confused, how I would set the type. Can you please help me out?

public TaggedDataPayload(String tag, String data) {
    this.tag = tag;
    this.data = data;
}

https://github.com/iotaledger/wallet.rs/blob/46f3818ffe1a8552c732379e971010fe07987506/wallet/bindings/java/lib/src/main/java/org/iota/types/payload/TaggedDataPayload.java#L5

0
0

I built the Java library with an adjusted TaggedDataPayload:

package org.iota.types.payload;

public class TaggedDataPayload extends Payload {
    private int type;
    private String tag;
    private String data;

    public TaggedDataPayload(int type, String tag, String data) {
        this.type = type;
        this.tag = tag;
        this.data = data;
    }

    public String getTag() {
        return this.tag;
    }

    public String getData() {
        return this.data;
    }

    public int getType() {
        return this.type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public void setData(String data) {
        this.data = data;
    }
}

I then made the transaction containing the tag and data:

public void makeShimmerTransaction(String receiverAddress, String amount) throws WalletException, InitializeWalletException {
        if (wallet == null) {
            log.error("Wallet has not been initialized");
            throw new InitializeWalletException("Wallet has not been initialized");
        }

        AccountHandle account = wallet.getAccount(new AccountAlias(ACCOUNT_NAME));
        account.syncAccount(new SyncAccount().withOptions(new SyncOptions()));

        AddressWithMicroAmount addressWithMicroAmount = new AddressWithMicroAmount();
        addressWithMicroAmount.withAddress(receiverAddress).withAmount(amount).withExpiration(86400);

        String tag = "0x" + DatatypeConverter.printHexBinary("custom_tag".getBytes(StandardCharsets.UTF_8));
        String data = "0x" + DatatypeConverter.printHexBinary("custom_data".getBytes(StandardCharsets.UTF_8));

        TaggedDataPayload taggedDataPayload = new TaggedDataPayload(5,tag, data);

        TransactionOptions transactionOptions = new TransactionOptions();
        transactionOptions.withTaggedDataPayload(taggedDataPayload);

        try {
            Transaction transaction = account.sendMicroTransaction(new org.iota.types.account_methods.SendMicroTransaction().withAddressesWithMicroAmount(new AddressWithMicroAmount[]{addressWithMicroAmount}).withOptions(transactionOptions));
            log.info("Transaction successfully sent");
        } catch (Exception error) {
            log.error(String.valueOf(error));
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.