UNPKG

@crtxio/abi

Version:

A tiny Solidity ABI encoder and decoder

17 lines (12 loc) 435 B
import { DecodeArgs, Parser } from '../types'; import { concat, fromHex, stripPrefix, toHex } from '../utils'; export const address: Parser<string> = { isDynamic: false, encode({ buffer, value }): Uint8Array { const addressBuffer = fromHex(stripPrefix(value).padStart(64, '0')); return concat([buffer, addressBuffer]); }, decode({ value }: DecodeArgs): string { return `0x${toHex(value.slice(12, 32))}`; } };