1.1.0-alpha.2 • Published 3 days ago

@iota/iscutils v1.1.0-alpha.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 days ago

@iota/iscutils

The iscutils package contains various utility methods to simplify the interaction with the IOTA Magic contract. This utility library is designed to be used with the @iota/iscmagic npm package.

The Magic contract, an EVM contract, is deployed by default on every ISC chain. It has several methods, accessed via different interfaces like ISCSandbox, ISCAccounts, ISCUtil and more. These can be utilized within any Solidity contract by importing the @iota/iscmagic library.

For further information on the Magic contract, check the Wiki.

Installing @iota/iscutils contracts

The @iota/iscutils contracts are installable via NPM with

npm install @iota/iscutils

After installing @iota/iscutils you can use the functions by importing them as you normally would.

Utilities

PRNG

A pseudorandom number generator is available by importing prng.sol. Its required seeding process simply depends on a random 32-byte value, and each invocation of the getRandomNumber() method will generate an algorithmically determined number, based on the initial seed and numbers generated prior. Its deterministic nature makes it ideal for accomplishing predictable outcomes during testing.

The recommended source for the seed value is attained via the getEntropy() method from the ISC sandbox (via the magic contract.) This call yields random bytes drawn from the existing consensus state. Although it is distinctive for each block, it remains the same between immediate calls processed within the same block. Therefore, in order to introduce randomness within a block, this utility comes into play, providing pseudorandom values throughout the block process, buffering the immutable nature of getEntropy() within the same block.

Example PRNG usage

pragma solidity >=0.8.5;

import "@iota/iscmagic/ISC.sol";
import "@iota/iscutils/prng.sol";

contract MyEVMContract {
    using PRNG for PRNG.PRNGState;

    event PseudoRNG(uint256 value);
    event PseudoRNGHash(bytes32 value);
    
    PRNG.PRNGState private prngState;

    function emitValue() public {
        bytes32 e = ISC.sandbox.getEntropy();
        prngState.seed(e);
        bytes32 randomHash = prngState.generateRandomHash();
        emit PseudoRNGHash(randomHash);
        uint256 random = prngState.generateRandomNumber();
        emit PseudoRNG(random);
        uint256 randomRange = prngState.generateRandomNumberInRange(111, 1111111);
        emit PseudoRNG(randomRange);
    }
}
1.1.0-alpha.2

3 days ago

1.1.0-alpha.1

4 days ago

1.0.4-alpha.4

5 days ago

1.0.4-alpha.3

17 days ago

1.0.3

2 months ago

1.0.3-rc.2

2 months ago

1.0.3-alpha.6

2 months ago

1.0.3-rc.1

2 months ago

1.0.3-alpha.5

2 months ago

1.0.3-alpha.4

2 months ago

1.0.3-alpha.3

3 months ago

1.0.3-alpha.1

3 months ago

1.0.3-alpha.2

3 months ago

1.0.2-rc.1

3 months ago

1.0.2-alpha.4

4 months ago

1.0.2-alpha.3

4 months ago

1.0.2-alpha.2

4 months ago

1.0.2-alpha.1

4 months ago

1.0.1-rc.17

4 months ago

1.0.1-rc.16

4 months ago

1.0.1-rc.15

5 months ago

1.0.1-rc.14

5 months ago

1.0.1-rc.13

6 months ago

1.0.1-rc.12

6 months ago

1.0.1-rc.11

6 months ago

1.0.1-rc.10

7 months ago

1.0.1-rc.9

7 months ago

1.0.1-rc.8

7 months ago

1.0.1-rc.7

7 months ago

1.0.1-rc.6

7 months ago

1.0.1-rc.4

7 months ago

1.0.1-rc.3

7 months ago

1.0.0-rc.6

8 months ago

1.0.0-rc-6

8 months ago

1.0.0-rc.5

8 months ago

1.0.0-rc.4

8 months ago

1.0.0-rc.3

8 months ago

1.0.0-rc.2

8 months ago

1.0.0-rc.1

8 months ago

0.7.0-alpha.16

9 months ago

0.7.0-alpha.15

9 months ago