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

soltypes

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soltypes

Typescript wrapped Solidity types w/ @ethersproject/bignumber

  • 2.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
decreased by-37.3%
Maintainers
1
Weekly downloads
 
Created
Source

Solidity Types in Typescript

This library types Ethereum strings strictly using Solidity types. With this library, you can explicitly prevent to convert uint256 types to address or bytes20.

yarn add soltypes

Examples

import { Bytes32, Uint256, Uint32, Address } from 'soltypes'

> new Bytes32('0x1111111111111111111111111111111111111111111111111111111111111111')
// OK

> Bytes32.from('0x1111111111111111111111111111111111111111111111111111111111111111')
// OK

> Bytes32.from('1111111111111111111111111111111111111111111111111111111111111111')
// ERROR - does not start with 0x

> Bytes32.from('0x111111111111111')
// ERROR - bytes length is not 32

> const hash = new Bytes32('0x1111111111111111111111111111111111111111111111111111111111111111')

> hash.toString()
'0x1111111111111111111111111111111111111111111111111111111111111111'
// returns 0x string

> const n: Uint256 = hash.toUint()
> n.toString()
'7719472615821079694904732333912527190217998977709370935963838933860875309329'
// returns Uint256 instance

> Uint32.from('11111')
// OK

> Uint32.from('0x1111111')
// ERROR - should not start with 0x

> Uint32.from('111111111111111111111111')
// ERROR - overflow

> const uintA = Uint256('1234')

> const b: Bytes32 = uintA.toBytes()
> b.toString()
'0x00000000000000000000000000000000000000000000000000000000000004d2'
// returns 0x string

> Address.from('0x1234343434343434343434343434343434343434')
// OK

> Address.from('0xabcd1234')
// FAILs

Keywords

FAQs

Package last updated on 14 Mar 2022

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