|
| 1 | +Stylus |
| 2 | +====== |
| 3 | + |
| 4 | +The flavor of Solidity that Solang supports for Stylus tries to be compatible with conventional Solidity as much as possible. |
| 5 | +However, there are two crucial differences, described below. |
| 6 | + |
| 7 | +Programs must be activated |
| 8 | +__________________________ |
| 9 | + |
| 10 | +In conventional Solidity, one can deploy a contract ``Foo`` and call ``bar`` on it as so: |
| 11 | + |
| 12 | +.. code-block:: solidity |
| 13 | +
|
| 14 | + (new Foo).bar() |
| 15 | +
|
| 16 | +But in Stylus, programs must be activated before methods on them can be called. |
| 17 | +The following is an example of contract activation: |
| 18 | + |
| 19 | +.. code-block:: solidity |
| 20 | +
|
| 21 | + Foo foo = new Foo(); |
| 22 | +
|
| 23 | + ArbWasm arbWasm = ArbWasm(address(0x71)); |
| 24 | + (uint16 version, uint256 dataFee) = arbWasm.activateProgram{ |
| 25 | + value: msg.value |
| 26 | + }(address(foo)); |
| 27 | +
|
| 28 | + foo.bar(); |
| 29 | +
|
| 30 | +In the above `ArbWasm <https://docs.arbitrum.io/build-decentralized-apps/precompiles/reference#arbwasm>`_ is the precompile at address 0x71. |
| 31 | +It has a Solidity interface with the same name. |
| 32 | + |
| 33 | +To activate a program, one should only need the ``activateProgram`` function. |
| 34 | +This function takes the address of a contract to be activated and returns two values. |
| 35 | +The first is the Stylus version the program was activated against; the second is the data fee paid to store the activated program. |
| 36 | + |
| 37 | +Note that if the program was already activated, the call to ``activateProgram`` will revert. |
| 38 | +Thus, one should structure their program to account for this possibility. |
| 39 | + |
| 40 | +``block.number`` |
| 41 | +________________ |
| 42 | + |
| 43 | +According to the Stylus docs, ``block.number`` is defined as: |
| 44 | + |
| 45 | + the block of the first non-Arbitrum ancestor chain |
| 46 | + |
| 47 | +This can seem confusing at first. |
| 48 | +For example, ``block.number`` can return the same value when read into two different L2 blocks. |
| 49 | +Moreover, the value returned can look random because it is for the parent L1 chain, not the L2 chain on which the contract is running. |
| 50 | + |
| 51 | +To get the block number of the L2 on which the contract is running, one can call: |
| 52 | + |
| 53 | +.. code-block:: solidity |
| 54 | +
|
| 55 | + ArbSys(100).arbBlockNumber() |
| 56 | +
|
| 57 | +In the above: |
| 58 | + |
| 59 | +- `ArbSys <https://docs.arbitrum.io/build-decentralized-apps/precompiles/reference#arbsys>`_ is the interface of the ``ArbSys`` precompile |
| 60 | +- 100 is the precompile's address |
| 61 | +- ``arbBlockNumber`` is the function that returns the L2 block number |
0 commit comments