NEXUS

Custom Data

When transferring tokens, you often need to send additional information besides the amount. For example, you can attach various types of supplementary information to a transaction, such as payment memos, order information, authentication data, or binary files. By using the custom data feature of the Cross Unity SDK, you can safely include various types of data—plain text, JSON, binary, etc.—in a transaction and record it on the blockchain. This feature is useful for tracking payment history, order processing, user authentication, data proof, and more in real-world services.

This guide explains how to send various types of custom data (plain text, JSON, binary) with token transfers using the Cross Unity SDK.

Sending Custom Data with Cross Coin Transfers

1. Plain Text

const string toAddress = "0x920A31f0E48739C3FbB790D992b0690f7F5C42ea";
var value = Web3.Convert.ToWei(1);

var customData = new Dictionary<string, object>
{
    ["metadata"] = "Enter plain text here"
};

var result = await CrossSdk.Evm.SendTransactionAsync(
    toAddress,
    value,
    customData, // Pass custom data
    null
);

2. JSON Data

const string toAddress = "0x920A31f0E48739C3FbB790D992b0690f7F5C42ea";
var value = Web3.Convert.ToWei(1);

string jsonData = "{\"key\":\"value\", \"number\":123}";
var customData = new Dictionary<string, object>
{
    ["metadata"] = jsonData
};

var result = await CrossSdk.Evm.SendTransactionAsync(
    toAddress,
    value,
    customData, // Pass custom data
    null
);

3. Binary Data

const string toAddress = "0x920A31f0E48739C3FbB790D992b0690f7F5C42ea";
var value = Web3.Convert.ToWei(1);

byte[] binaryData = Encoding.UTF8.GetBytes("Example of binary data");
var customData = new Dictionary<string, object>
{
    ["metadata"] = Convert.ToBase64String(binaryData),
    ["format"] = "binary"
};

var result = await CrossSdk.Evm.SendTransactionAsync(
    toAddress,
    value,
    customData, // Pass custom data
    null
);

Sending Custom Data with ERC20 Token Transfers

Common Setup Code

const string toAddress = "0x920A31f0E48739C3FbB790D992b0690f7F5C42ea";
const string ERC20_ADDRESS = "0x88f8146EB4120dA51Fc978a22933CbeB71D8Bde6";
TextAsset abiText = Resources.Load<TextAsset>("Contracts/SampleERC20abi");
string abi = abiText.text;
var value = Web3.Convert.ToWei(1);

1. Plain Text

var customData = new Dictionary<string, object>
{
    ["metadata"] = "Enter plain text here"
};

var result = await CrossSdk.Evm.WriteContractAsync(
    ERC20_ADDRESS,
    abi,
    "transfer",
    customData, // Pass custom data
    toAddress,
    value
);

2. JSON Data

string jsonData = "{\"key\":\"value\", \"number\":123}";
var customData = new Dictionary<string, object>
{
    ["metadata"] = jsonData
};

var result = await CrossSdk.Evm.WriteContractAsync(
    ERC20_ADDRESS,
    abi,
    "transfer",
    customData, // Pass custom data
    toAddress,
    value
);

3. Binary Data

byte[] binaryData = Encoding.UTF8.GetBytes("Example of binary data");
var customData = new Dictionary<string, object>
{
    ["metadata"] = Convert.ToBase64String(binaryData),
    ["format"] = "binary"
};

var result = await CrossSdk.Evm.WriteContractAsync(
    ERC20_ADDRESS,
    abi,
    "transfer",
    customData, // Pass custom data
    toAddress,
    value
);

Read Custom Data

1. Read Transaction Data

public class CustomDataReader : MonoBehaviour
{
    public async void ReadCustomData(string txHash)
    {
        var tx = await CrossSdk.Dapp.GetTransaction(txHash);
        Debug.Log($"Custom data: {tx.CustomData?.Metadata}");
    }
}

© 2025 NEXUS Co., Ltd. All Rights Reserved.