encode
Encode bytes or text into base-N, URL, IDNA, bech32, hexdump, or bytes32 formats. Options for padding, alphabet, and width.
Instructions
Encode bytes/text into a string form (base-N, URL, IDNA, bech32, hexdump, bytes32).
data is decoded to bytes via input_format (text|hex|base64). options
is a per-scheme dict: padding (bool, default true — base32/base64 family),
alphabet (custom symbol set — base58/base62), hrp (required for
bech32/bech32m), width (bytes per line — hexdump, default 16). idna and
bytes32 read data as a text string / short string respectively. bytes32 is
a fixed-width 32-byte EVM word: inputs of <32 bytes are right-padded with
0x00; decode returns all 32 bytes (it does NOT strip trailing nulls, so the
round-trip is lossless — rstrip them yourself for a short string).
Returns {scheme, encoded}.
Example: encode("hello", "base64") -> encoded "aGVsbG8="
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | Yes | Input to encode, decoded to bytes via `input_format` (idna/bytes32 read it as text). | |
| scheme | Yes | Target encoding: base16/32/32hex/32crockford/45/58/58check/62/64/64url, ascii85/base85/z85, url/url_form (percent), idna, bech32/bech32m, hexdump, or bytes32 (32-byte EVM word). | |
| input_format | No | How `data` is decoded to bytes; default 'text'. | text |
| options | No | Per-scheme options: padding (bool, base32/64 family), alphabet (base58/62), hrp (required for bech32/bech32m), width (hexdump, default 16). Default None. |