Breaking change alert: Consistently encode binary data with Base64 in JSON-RPC

As a part of the new 1.39 release there is a breaking change to the encoding of two fields in the JSONRPC schema. Both SuiEvent.bcs and DynamicFieldInfo.bcs_name fields are now encoded as Base64 strings, instead of Base58 as they were encoded previously. This change eliminates inconsistencies and brings these two fields into line with how other arbitrary length binary data is encoded in other parts of Sui’s JSON-RPC schema.

If you are using the TS SDK, you will need to change how your code interprets these fields. This is simple in Typescript:

// before
import { fromBase58 } from "@mysten/bcs";
MyEvent.parse(fromBase58(event.bcs));

// after
import { fromBase64 } from "@mysten/bcs";
MyEvent.parse(fromBase64(event.bcs));

(The fromB{58,64} functions have also been deprecated, so please update your code to use fromBase64.)

If you instead want to be a bit more defensive (and be temporarily backward-compatible with unupgraded fullnodes) you can do this with the following:

import { fromBase64 } from "@mysten/bcs";
import { fromBase58 } from "@mysten/bcs";

const data =
	'bcsEncoding' in event && event.bcsEncoding === 'base64'
		? MyType.fromBase64(event.bcs)
		: MyType.fromBase58(event.bcs);

If you are using the Rust SDK, you will need to update to >1.39, at which point you will be backwards-compatible with unupgraded fullnodes.

2 Likes