FuelLabs/fuels-ts · error · FuelError

DECODE_ERROR

DECODE_ERROR

Error message

Invalid b512 data size.

What it means

Thrown by B512Coder.decode at the top guard: data.length < this.encodedLength (64). The message is the literal "Invalid b512 data size.". It means the byte buffer handed to decode cannot even contain one B512, so no slicing is attempted.

Source

Thrown at packages/abi-coder/src/encoding/coders/B512Coder.ts:29

    super('b512', 'struct B512', WORD_SIZE * 8);
  }

  encode(value: string): Uint8Array {
    let encodedValue;
    try {
      encodedValue = arrayify(value);
    } catch (error) {
      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
    }
    if (encodedValue.length !== this.encodedLength) {
      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
    }
    return encodedValue;
  }

  decode(data: Uint8Array, offset: number): [string, number] {
    if (data.length < this.encodedLength) {
      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid b512 data size.`);
    }

    let bytes = data.slice(offset, offset + this.encodedLength);

    const decoded = bn(bytes);
    if (decoded.isZero()) {
      bytes = new Uint8Array(64);
    }

    if (bytes.length !== this.encodedLength) {
      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid b512 byte data size.`);
    }

    return [toHex(bytes, this.encodedLength), offset + this.encodedLength];
  }
}

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Verify the source of the byte buffer and that it is the full, untouched encoded payload.
  2. Ensure offset + 64 does not exceed data.length before calling decode.
  3. Confirm you are using the correct coder (b512 vs b256) for this data.
  4. Re-fetch the receipt/return value if it was truncated by the provider.
Defensive patterns

Strategy: try-catch

Validate before calling

if (data.length < 64) throw new Error(`need >= 64 bytes to decode b512, got ${data.length}`)
b512.decode(data, offset)

Type guard

const canDecodeB512 = (data: Uint8Array) => data.length >= 64

Try / catch

try { b512.decode(data, offset) }
catch (e) { if ((e as FuelError).code === ErrorCode.DECODE_ERROR) { /* re-fetch or reject truncated payload */ } throw e }

Prevention

When it happens

Trigger: Calling b512.decode(data, offset) where data is shorter than 64 bytes — e.g. decoding a receipt/log slice that was truncated, decoding at a bad offset, or feeding a raw partial payload. Note the guard checks total data.length, not offset-relative length.

Common situations: Manually decoding ABI-encoded log data whose leading bytes were stripped; using a wrong coder for the bytes on hand; chain/receipt data that was cut off in transit; offset bookkeeping that left fewer than 64 bytes available.

Related errors


AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12). Data as JSON: /api/errors/26877210b10a7d44. Report an issue: GitHub.