3_ArbSys预编译合约

ArbSys是每一条Arbitrum链中都存在的预编译的合约。顾名思义,ArbSys提供了一些系统级的合约功能支持。任何运行在Arbitrum链上的合约都可以调用ArbSys。

ArbSys在地址0x0000000000000000000000000000000000000064中。使用类似下面的方式调用它:

  1. uint256 txCount = ArbSys(address(100)).getTransactionCount();

下面是ArbSys提供的接口:

  1. /**
  2. * @title Precompiled contract that exists in every Arbitrum chain at address(100), 0x0000000000000000000000000000000000000064. Exposes a variety of system-level functionality.
  3. */
  4. interface ArbSys {
  5. /**
  6. * @notice Get internal version number identifying an ArbOS build
  7. * @return version number as int
  8. */
  9. function arbOSVersion() external pure returns (uint);
  10. /**
  11. * @notice Get Arbitrum block number (distinct from L1 block number; Arbitrum genesis block has block number 0)
  12. * @return block number as int
  13. */
  14. function arbBlockNumber() external view returns (uint);
  15. /**
  16. * @notice Send given amount of Eth to dest from sender.
  17. * This is a convenience function, which is equivalent to calling sendTxToL1 with empty calldataForL1.
  18. * @param destination recipient address on L1
  19. * @return unique identifier for this L2-to-L1 transaction.
  20. */
  21. function withdrawEth(address destination) external payable returns(uint);
  22. /**
  23. * @notice Send a transaction to L1
  24. * @param destination recipient address on L1
  25. * @param calldataForL1 (optional) calldata for L1 contract call
  26. * @return a unique identifier for this L2-to-L1 transaction.
  27. */
  28. function sendTxToL1(address destination, bytes calldata calldataForL1) external payable returns(uint);
  29. /**
  30. * @notice get the number of transactions issued by the given external account or the account sequence number of the given contract
  31. * @param account target account
  32. * @return the number of transactions issued by the given external account or the account sequence number of the given contract
  33. */
  34. function getTransactionCount(address account) external view returns(uint256);
  35. /**
  36. * @notice get the value of target L2 storage slot
  37. * This function is only callable from address 0 to prevent contracts from being able to call it
  38. * @param account target account
  39. * @param index target index of storage slot
  40. * @return stotage value for the given account at the given index
  41. */
  42. function getStorageAt(address account, uint256 index) external view returns (uint256);
  43. /**
  44. * @notice check if current call is coming from l1
  45. * @return true if the caller of this was called directly from L1
  46. */
  47. function isTopLevelCall() external view returns (bool);
  48. event EthWithdrawal(address indexed destAddr, uint amount);
  49. event L2ToL1Transaction(address caller, address indexed destination, uint indexed uniqueId,
  50. uint indexed batchNumber, uint indexInBatch,
  51. uint arbBlockNum, uint ethBlockNum, uint timestamp,
  52. uint callvalue, bytes data);
  53. }

2_合约部署1_Layers之间的通信