diff --git a/.changeset/calm-weeks-rescue.md b/.changeset/calm-weeks-rescue.md new file mode 100644 index 0000000000000..f4d89eba870ae --- /dev/null +++ b/.changeset/calm-weeks-rescue.md @@ -0,0 +1,5 @@ +--- +'@mysten/bcs': patch +--- + +Accept arrays of numbers when serializing bcs.bytes() diff --git a/sdk/bcs/src/bcs.ts b/sdk/bcs/src/bcs.ts index ae2da5c72f501..e73931d990758 100644 --- a/sdk/bcs/src/bcs.ts +++ b/sdk/bcs/src/bcs.ts @@ -155,13 +155,14 @@ export const bcs = { * bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3] */ bytes(size: T, options?: BcsTypeOptions>) { - return fixedSizeBcsType({ + return fixedSizeBcsType>({ name: `bytes[${size}]`, size, read: (reader) => reader.readBytes(size), write: (value, writer) => { + const array = new Uint8Array(value); for (let i = 0; i < size; i++) { - writer.write8(value[i] ?? 0); + writer.write8(array[i] ?? 0); } }, ...options,