MCPcopy Create free account
hub / github.com/wevm/viem / stringToBytes

Function stringToBytes

src/utils/encoding/toBytes.ts:238–248  ·  view source on GitHub ↗
(
  value: string,
  opts: StringToBytesOpts = {},
)

Source from the content-addressed store, hash-verified

236 * // Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
237 */
238export function stringToBytes(
239 value: string,
240 opts: StringToBytesOpts = {},
241): ByteArray {
242 const bytes = encoder.encode(value)
243 if (typeof opts.size === 'number') {
244 assertSize(bytes, { size: opts.size })
245 return pad(bytes, { dir: 'right', size: opts.size })
246 }
247 return bytes
248}

Callers 15

toRlp.test.tsFile · 0.85
toBytesFunction · 0.85
toBytes.test.tsFile · 0.85
fromBytes.test.tsFile · 0.85
toBlobs.test.tsFile · 0.85
namehashFunction · 0.85
labelhashFunction · 0.85

Calls 2

assertSizeFunction · 0.85
padFunction · 0.85

Tested by

no test coverage detected