Solidity Types in Typescript – 铅字中的实体类型区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Solidity Types in Typescript – 铅字中的实体类型区块链毕设代写 是一篇很好的国外资料

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

Typescript中的实体类型

这个库严格使用Solidity类型来输入以太坊eth字符串。有了这个库,您可以显式地阻止uint256类型转换为address或bytes20。

yarn add soltypes

示例

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

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/20032.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Solidity Types in Typescript – 铅字中的实体类型区块链毕设代写

提供最优质的资源集合

立即查看 了解详情