Skip to content

Abi.tuple

Several values as one, by position. A value is a readonly tuple.

import { Effect } from "effect";
import { Abi } from "@ethect/core";
// (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)
const Reserves = Abi.tuple([Abi.uint112, Abi.uint112, Abi.uint32]);
const program = Effect.gen(function* () {
const data = yield* Abi.encode(Reserves, [10n ** 18n, 3000n * 10n ** 6n, 1_700_000_000]);
const [reserve0, reserve1, updatedAt] = yield* Abi.decode(Reserves, data);
return { reserve0, reserve1, updatedAt }; // two bigints and a number
});

Use Abi.struct when the components have names. The two encode to the same bytes.

Abi.Reference<readonly [A, B, …]>

The tuple type. A value has one element per component, each of its component’s type. It is an Abi.Type that says it is a reference type.

  • Type: ReadonlyArray<Abi.Type<any>>

The types of the components, in order. At least one.

import { Abi } from "@ethect/core";
const Leg = Abi.tuple([Abi.address, Abi.uint24]);
// a tuple in a tuple, and an array of tuples
const Route = Abi.tuple([Abi.array(Leg), Abi.bytes]);
  • One value per component. A value with fewer or more elements fails to encode, and the types refuse it.
  • A tuple of static types is static. It is written in place, one word after the other. With one dynamic component it is written by offset, as the specification says.
  • A tuple has a component. Abi.tuple([]) does not throw: it gives a type whose every use fails with an AbiError.
Error When
AbiError encoding a value that is not an array, or has another number of elements
AbiError encoding an element its type refuses. The message says which: at [1]