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

web3-validator

Package Overview
Dependencies
Maintainers
4
Versions
349
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-validator

JSON-Schema compatible validator for web3

  • 2.0.1-dev.7a38fee.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

web3.js

web3-validator

ES Version Node Version NPM Package Downloads

This is a sub-package of web3.js.

web3-validator contains functions for validating objects.

Installation

You can install the package either using NPM or using Yarn

Using NPM

npm install web3-validator

Using Yarn

yarn add web3-validator

Getting Started

  • :writing_hand: If you have questions submit an issue or join us on Discord Discord

Usage

You can use the the validator by importing as and using to validate;

import { validator } from 'web3-validator';

// To validate and throw
validator.validate(['uint8', 'string'], [val1, val2]);

// To validate and return error
const errors = validator.validate(['uint8', 'string'], [val1, val2], { silent: true });

To see more examples of schema you can use to validate check following file.

Following eth types are supported to validate.

TypeInput AsDescription
uintnumber, string, HexStringUnsigned integer, all ethereum compatible variants are also supported e.g. uint8, uint256. You can also use array specifiers as uint[] or uint[2]
intnumber, string, HexStringSigned integer, all ethereum compatible variants are also supported e.g. int8, int256. You can also use array specifiers as int[] or int[2]
bytesHexString, Uint8ArrayRaw bytes. You can also use fixed length bytes as bytes[2]

| string | string | String values | | address | string, HexString | Ethereum network compatible address | | bloom | string, HexString | Check if a given string is a Eth bloom | | tuple | array | You can specify any tuple as nested arrays. e.g. ['uint', 'string']. For a custom tuple or array tuple you can use syntax e.g. ['tuple[3]', ['uint', 'string']] |

For the ethereum compatible data values should be passed as arrays e.g. for schema ['uint', 'string'] value should be passed as [2, 'my-string'].

You can also pass full ABI schema for the validation. e.g.

[{ "name": "owner", "type": "address" }]

The implementation of the validator is extension of JSON-Schema-Draft07 with a custom keyword eth. So you can use JSON-Schema compatible schema to validate any object based data as well.

Prerequisites

Package.json Scripts

ScriptDescription
cleanUses rimraf to remove dist/
buildUses tsc to build package and dependent packages
lintUses eslint to lint package
lint:fixUses eslint to check and fix any warnings
formatUses prettier to format the code
testUses jest to run unit tests
test:integrationUses jest to run tests under /test/integration
test:unitUses jest to run tests under /test/unit

FAQs

Package last updated on 17 Aug 2023

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