Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethersproject/bytes

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/bytes

Bytes utility functions for ethers.

  • 5.0.0-beta.119
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
464K
decreased by-53.52%
Maintainers
1
Weekly downloads
 
Created

What is @ethersproject/bytes?

@ethersproject/bytes is a utility library for handling and manipulating byte arrays in JavaScript. It is part of the ethers.js library, which is widely used for interacting with the Ethereum blockchain. This package provides various functions to work with byte arrays, including conversion, concatenation, slicing, and more.

What are @ethersproject/bytes's main functionalities?

Conversion between hex strings and byte arrays

This feature allows you to convert a hex string to a byte array and vice versa. The `arrayify` function converts a hex string to a Uint8Array, and the `hexlify` function converts a Uint8Array back to a hex string.

const { arrayify, hexlify } = require('@ethersproject/bytes');

const hexString = '0x123456';
const byteArray = arrayify(hexString);
console.log(byteArray); // Uint8Array [ 18, 52, 86 ]

const newHexString = hexlify(byteArray);
console.log(newHexString); // '0x123456'

Concatenation of byte arrays

This feature allows you to concatenate multiple byte arrays into a single byte array. The `concat` function takes an array of Uint8Arrays and returns a new Uint8Array that is the concatenation of all the input arrays.

const { concat } = require('@ethersproject/bytes');

const byteArray1 = new Uint8Array([1, 2, 3]);
const byteArray2 = new Uint8Array([4, 5, 6]);
const concatenatedArray = concat([byteArray1, byteArray2]);
console.log(concatenatedArray); // Uint8Array [ 1, 2, 3, 4, 5, 6 ]

Slicing byte arrays

This feature allows you to slice a byte array to get a subarray. The `slice` function takes a byte array and start and end indices, and returns a new byte array that is a subarray of the input array.

const { arrayify, hexlify, slice } = require('@ethersproject/bytes');

const hexString = '0x1234567890abcdef';
const byteArray = arrayify(hexString);
const slicedArray = slice(byteArray, 2, 6);
console.log(hexlify(slicedArray)); // '0x34567890'

Other packages similar to @ethersproject/bytes

Keywords

FAQs

Package last updated on 08 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc