The Base64 encoding and decoding library provides two built-in functions for BaaS smart contracts: base64_encode and base64_decode. Use these functions to encode strings as MIME Base64 or decode Base64-encoded strings back to their original form — for example, when generating checksums or building verification signatures on-chain.
Function examples
function test_base64_decode() returns (bool , string memory)
{
string memory name = "aHR0cDovL3Rlc3RfYmFzZTY0IH4hQCMkJQ==";
return base64_decode(name);
}
function test_base64_encode() returns (bool , string memory)
{
string memory name = "http://test_base64 ~! @#$%";
return base64_encode(name);
}
base64_decode
Decodes a MIME Base64-encoded string and returns the original data.
Signature
base64_decode(string data) returns(bool result, string memory data);
Request parameters
| Name | Required | Type | Description |
|---|
data | Yes | string | The Base64-encoded string to decode. |
Response parameters
| Parameter | Type | Description |
|---|
result | bool | Indicates whether the call succeeded. true indicates success; false indicates failure. |
data | string | The decoded string. |
base64_encode
Encodes a string using MIME Base64 encoding.
Signature
base64_encode(string data) returns(bool result, string memory data);
Request parameters
| Name | Required | Type | Description |
|---|
data | Yes | string | The string to encode. |
Response parameters
| Parameter | Type | Description |
|---|
result | bool | Indicates whether the call succeeded. true indicates success; false indicates failure. |
data | string | The Base64-encoded string. |