Static
base64to16Converts a Base-64 encoded string to a Base-16 (hexadecimal) encoded string.
A Base-16 encoded string.
const base64 = "SGVsbG8=";
const base16 = Conversions.base64to16(base64);
console.log(base16); // Outputs: "48656c6c6f"
The Base-64 encoded string to be converted.
Static
csprConverts a CSPR amount to its mote equivalent.
A BigNumber
containing the equivalent amount in motes.
1 CSPR = 10^9 motes
const cspr = 1;
const motes = Conversions.csprToMotes(cspr);
console.log(motes.toString()); // Outputs: "1000000000"
A string
amount of CSPR to convert to motes.
Static
decodeDecodes a Base-16 (hexadecimal) encoded string and returns a Uint8Array
of bytes.
A Uint8Array
containing the decoded bytes.
const base16 = "48656c6c6f";
const bytes = Conversions.decodeBase16(base16);
console.log(bytes); // Outputs: Uint8Array(5) [72, 101, 108, 108, 111]
The Base-16 encoded string to be decoded.
Static
decodeDecodes a Base-64 encoded string and returns a Uint8Array
of bytes.
A Uint8Array
containing the decoded bytes.
const base64 = "SGVsbG8=";
const bytes = Conversions.decodeBase64(base64);
console.log(bytes); // Outputs: Uint8Array(5) [72, 101, 108, 108, 111]
The Base-64 encoded string to be decoded.
Static
encodeEncodes a Uint8Array
into a string using Base-16 (hexadecimal) encoding.
A Base-16 encoded string representation of the input bytes.
const bytes = new Uint8Array([72, 101, 108, 108, 111]);
const base16 = Conversions.encodeBase16(bytes);
console.log(base16); // Outputs: "48656c6c6f"
The Uint8Array
to be encoded.
Static
encodeEncodes a Uint8Array
into a string using Base-64 encoding.
A Base-64 encoded string representation of the input bytes.
const bytes = new Uint8Array([72, 101, 108, 108, 111]);
const base64 = Conversions.encodeBase64(bytes);
console.log(base64); // Outputs: "SGVsbG8="
The Uint8Array
to be encoded.
Static
motesConverts an amount in motes to its CSPR equivalent.
A BigNumber
containing the equivalent amount in CSPR.
This function will round to the nearest whole integer. 1 mote = 10^-9 CSPR
const motes = BigNumber.from('1000000000');
const cspr = Conversions.motesToCSPR(motes);
console.log(cspr.toString()); // Outputs: "1"
A BigNumberish
amount of motes to convert to CSPR.
Generated using TypeDoc
A utility class for various data conversions used in the Casper ecosystem. Provides methods to convert between different encodings (Base64, Base16) and to perform conversions between CSPR and motes.