Skip to content

๐Ÿ“ Registers in Ergo โ€‹

Store custom data in boxes using registers R4-R9

Overview โ€‹

Ergo boxes have 9 registers (R0-R9):

  • R0-R3: Reserved by protocol (value, script, tokens, creation info)
  • R4-R9: Available for custom data storage
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    ERGO BOX REGISTERS                       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                             โ”‚
โ”‚   RESERVED (R0-R3)              CUSTOM (R4-R9)             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚
โ”‚   โ”‚ R0: Value   โ”‚               โ”‚ R4: Custom  โ”‚ โ—€โ”€ Your   โ”‚
โ”‚   โ”‚ R1: Script  โ”‚               โ”‚ R5: Custom  โ”‚    data!  โ”‚
โ”‚   โ”‚ R2: Tokens  โ”‚               โ”‚ R6: Custom  โ”‚            โ”‚
โ”‚   โ”‚ R3: Info    โ”‚               โ”‚ R7: Custom  โ”‚            โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜               โ”‚ R8: Custom  โ”‚            โ”‚
โ”‚                                 โ”‚ R9: Custom  โ”‚            โ”‚
โ”‚                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Setting Registers in Fleet SDK โ€‹

typescript
import { OutputBuilder } from "@fleet-sdk/core";
import { SInt, SLong, SColl, SByte, SBool } from "@fleet-sdk/serializer";

const output = new OutputBuilder("1000000000", address)
  .setAdditionalRegisters({
    R4: SInt(42),                           // Integer
    R5: SLong(BigInt(Date.now())),          // Long (timestamp)
    R6: SColl(SByte, [1, 2, 3, 4]),         // Byte array
    R7: SBool(true),                        // Boolean
    R8: SColl(SByte, Buffer.from("Hello")), // String as bytes
  });

Type Constructors โ€‹

TypeConstructorExample
IntegerSInt(n)SInt(42)
LongSLong(n)SLong(1000000n)
BooleanSBool(b)SBool(true)
ByteSByte(n)SByte(255)
Byte ArraySColl(SByte, arr)SColl(SByte, [1,2,3])
Int ArraySColl(SInt, arr)SColl(SInt, [10,20])

NFT Metadata (EIP-4) โ€‹

NFTs use registers for metadata:

typescript
const nftOutput = new OutputBuilder("1000000", address)
  .mintToken({
    amount: "1",
    name: "My NFT",
    description: "Description",
    decimals: 0
  })
  .setAdditionalRegisters({
    // R4: Name (set by mintToken)
    // R5: Description (set by mintToken)
    // R6: Decimals (set by mintToken)
    R7: SColl(SByte, Buffer.from("image/png")),     // Content type
    R8: SColl(SByte, Buffer.from("ipfs://Qm...")),  // Asset URL
    R9: SColl(SByte, Buffer.from("SHA256hash")),    // Optional: hash
  });

Reading Registers โ€‹

typescript
// From a box
const box = await getBox(boxId);

// Access register data
const r4Value = box.additionalRegisters.R4;
const r5Value = box.additionalRegisters.R5;

// Registers are hex-encoded - decode as needed
console.log("R4:", r4Value);

Common Use Cases โ€‹

Use CaseRegisters Used
NFT MetadataR4-R9 (name, desc, decimals, type, URL)
Oracle DataR4 (price), R5 (timestamp)
AuctionR4 (min bid), R5 (end time), R6 (seller)
DAO VotingR4 (proposal ID), R5 (votes), R6 (deadline)

Example: Storing JSON โ€‹

typescript
const metadata = {
  name: "My Token",
  creator: "Alice",
  attributes: ["rare", "blue"]
};

const output = new OutputBuilder("1000000", address)
  .setAdditionalRegisters({
    R4: SColl(SByte, Buffer.from(JSON.stringify(metadata)))
  });

Best Practices โ€‹

  1. Use appropriate types - Don't store ints as strings
  2. Keep data minimal - Registers increase tx size
  3. Document your schema - Others need to decode it
  4. Follow standards - Use EIP-4 for NFTs

Next Steps โ€‹

Released under the MIT License.