Wysdom

Understanding the Interpreter

Interactive Solidity execution in Wysdom notebooks

Wysdom notebooks bring the interactive power of Jupyter Notebooks to Web3 development. They allow you to write, test, and execute Solidity code instantly without deployment overhead. Think of it as a playground where you can experiment with Solidity in real-time.

What Makes It Special?

Unlike traditional Solidity development where you need to compile and deploy contracts, Wysdom notebooks let you:

  • Write code line by line by writing statements rather than just contracts
  • Get immediate results
  • Skip semicolons (;) at the end of lines
  • Test ideas quickly without deployment costs

Statements vs. contracts

A statement is a piece of code that runs in a free-floating way, without being encapsulated in a contract:

uint num = 12;

A contract, on the other hand, is a container for state variables, functions, and other contract-related elements:

contract Counter {
    uint256 count
    
    function increment() {
        count += 1
    }
    
    function getCount() returns (uint256) {
        return count
    }
}

How does it work?

When writing a statement, underneath the hood we insert it into this base context depending on the scope.

/// @notice Entry point for interpreter.
contract MainContract {
    function main() public  {
        
    }
}

There are three different scopes where statements can be inserted:

1. Source level scope

The highest level scope that includes interfaces, libraries, imports, and contracts.

interface IERC20 {
    function transfer(address to, uint256 amount) external returns (bool)
}
 
library MathLib {
    function add(uint256 a, uint256 b) public pure returns (uint256) {
        return a + b
    }
}

would be inserted like this:

// Source level code
interface IERC20 {
    function transfer(address to, uint256 amount) external returns (bool)
}
 
library MathLib {
    function add(uint256 a, uint256 b) public pure returns (uint256) {
        return a + b
    }
}
 
/// @notice Entry point for interpreter.
contract MainContract {
    function main() public  {
        
    }
}

2. Contract level scope

Contract level scope includes state variables, events, and modifiers that are accessible throughout the contract.

uint256 private stateVariable
mapping(address => uint256) private balances
 
event ValueUpdated(uint256 newValue)
 
modifier onlyPositive(uint256 value) {
    require(value > 0, "Value must be positive")
    _
}

is inserted in this way:

/// @notice Entry point for interpreter.
contract MainContract {
    // Contract level code
    uint256 private stateVariable
    mapping(address => uint256) private balances
    
    event ValueUpdated(uint256 newValue)
    
    modifier onlyPositive(uint256 value) {
        require(value > 0, "Value must be positive")
        _
    }
    
    function main() public {
       ... existing code ...
    }
}

Key points about contract level scope:

  • State variables persist between function calls
  • Events can be emitted from any function
  • Modifiers can be used by any function
  • Constructor sets initial state

3. Function level scope

Function level scope includes local variables and parameters that only exist during function execution.

string memory str = "Hello World!";

is inserted in this way:

 
... existing code ...
 
/// @notice Entry point for interpreter.
contract MainContract {
    
    ... existing code ...
 
    function main() public {
        // Function level code
       string memory str = "Hello World!";
    }
 
}

Key points about function level scope:

  • Can access and modify contract state variables
  • Can emit events and use modifiers
  • Parameters (input) are only accessible within the function
  • Block-scoped variables are only accessible within their block

Printing variables and calling function returns

Wysdom notebooks give you the ability to print variables and call function returns by omitting the semicolon ; in the last line:

uint a = 12;
a // prints the varaible a

This will be run in the function scope of the base contract

On this page