import io.brane.core.RevertDecoder;
import io.brane.core.abi.TypeSchema;
import io.brane.contract.Abi;
import io.brane.contract.ReadWriteContract;
ReadWriteContract contract = ...; // Your contract instance
// 1. Define the Error Schema
var customError = new RevertDecoder.CustomErrorAbi(
"InsufficientFunds",
List.of(
new TypeSchema.UIntSchema(256), // available
new TypeSchema.UIntSchema(256) // required
)
);
// 2. Decode
try {
contract.call(...);
} catch (RevertException e) {
String data = e.rawDataHex();
String selector = Abi.getSelector("InsufficientFunds(uint256,uint256)");
var decoded = RevertDecoder.decode(
data,
Map.of(selector, customError)
);
if (decoded.kind() == RevertDecoder.RevertKind.CUSTOM) {
System.out.println("Custom Error: " + decoded.reason());
}
}