Table of Contents

Class OnChainData

Namespace
Concordium.Sdk.Types
Assembly
Concordium.Sdk.dll

Represents data to be stored or that was stored on-chain as part of a transaction.

This can be any data which is at most MaxLength bytes, but the convention is to use CBOR encoded data.

public sealed record OnChainData : IEquatable<OnChainData>
Inheritance
OnChainData
Implements
Inherited Members

Fields

MaxLength

The maximum length of a bytearray passed to the constructor.

public const uint MaxLength = 256

Field Value

uint

Methods

AsSpan()

Returns span of underlying data.

public ReadOnlySpan<byte> AsSpan()

Returns

ReadOnlySpan<byte>

Equals(OnChainData?)

Check for equality.

public bool Equals(OnChainData? other)

Parameters

other OnChainData

Returns

bool

From(byte[])

Creates an instance from byte array.

public static OnChainData From(byte[] dataAsBytes)

Parameters

dataAsBytes byte[]

The data to be registered on-chain represented as a byte array.

Returns

OnChainData

Exceptions

ArgumentException

The length of the supplied data exceeds MaxLength.

FromHex(string)

Creates an instance from a hex encoded string.

public static OnChainData FromHex(string hexString)

Parameters

hexString string

Data represented as a hex encoded string representing at most MaxLength bytes.

Returns

OnChainData

Exceptions

ArgumentException

The supplied string is not a hex encoded string representing at most MaxLength bytes.

FromTextEncodeAsCBOR(string, CborConformanceMode)

Creates an instance from a string whose CBOR encoding will be used for the data to be registered on-chain.

public static OnChainData FromTextEncodeAsCBOR(string data, CborConformanceMode conformanceMode = CborConformanceMode.Strict)

Parameters

data string

Text to store on-chain represented as a string whose CBOR encoding will be used for the data to registered on-chain.

conformanceMode CborConformanceMode

The conformance mode to use for encoding and decoding CBOR data.

Returns

OnChainData

Exceptions

ArgumentException

The resulting CBOR encoded string exceeds MaxLength bytes.

ArgumentException

The supplied string is not a valid UTF-8 encoding and this is not permitted under the current conformance mode.

InvalidOperationException

The written CBOR data is not accepted under the current conformance mode.

GetHashCode()

Gets hash code.

public override int GetHashCode()

Returns

int

ToBytes()

Copies the on-chain data in the binary format expected by the node to a byte array.

That is, represented as a byte array with the length of the array prepended as a 16-bit unsigned integer in big-endian format.

public byte[] ToBytes()

Returns

byte[]

ToString()

Get the data to register on-chain as a hex-encoded string.

public override string ToString()

Returns

string

TryCborDecodeToString()

Try to decode the data to be registered on-chain as a single CBOR encoded string.

public string? TryCborDecodeToString()

Returns

string

A string corresponding to the decoded data if it contained a single CBOR encoded string, and null otherwise.

TryDeserial(ReadOnlySpan<byte>, out (OnChainData? OnChainData, string? Error))

Deserialize an "OnChainData" from a byte array.

public static bool TryDeserial(ReadOnlySpan<byte> bytes, out (OnChainData? OnChainData, string? Error) output)

Parameters

bytes ReadOnlySpan<byte>

The serialized "OnChainData".

output (OnChainData OnChainData, string Error)

Where to write the result of the operation.

Returns

bool