HomeDeveloper MaterialsPopular ToolingRemix

Remix

Remix is a convenient open sourced utility for the rapid iteration, testing and debugging of solidity smart contracts directly in your browser.  The interface is written in JavaScript and supports custom connections to private permission-based Kaleido environments for smart contract deployments and subsequent interactions.

Connecting Remix to Kaleido

  • Visit the Remix IDE
  • Upload your own smart contract or use the default solidity code
  • Kaleido provides the Simple Storage smart contract within the REST API Gateway for testing and experimentation purposes.  For convenience, the code is as follows:

pragma solidity >=0.4.24 <0.6.0;
    /**
     * @title Simple Storage
     * @dev Read and write values to the chain
     */
    contract simplestorage {
        uint public storedData;
        /**
         * @dev Constructor sets the default value
         * @param initVal The initial value
         */
        constructor(uint initVal) public {
            storedData = initVal;
        }
        /**
         * @dev Set the value
         * @param x The new value
         */
        function set(uint x) public {
            storedData = x;
        }
        /**
         * @dev Get the value
         */
        function get() public view returns (uint retVal) {
            return storedData;
        }
    }
  • Paste this code into the editor or use a different smart contract of your choice.
  • If your smart contract compiles successfully and the debug reveals no warnings, you will see a green status bar with the name of your smart contract.

  • In the top right corner of the screen switch to the Run tab
  • Expand the Environment dropdown and select Injected Web3
  • This will interface with your MetaMask browser wallet and look for a custom connection to Kaleido.  Make sure that your MetaMask plugin is configured to point to a Kaleido chain.  If you have not yet configured a Custom RPC URL in MetaMask, refer to the MetaMask article for instructions on creating a custom URL.

  • Make sure your account in MetaMask has been funded with Ether from the Kaleido Ether Pool
  • Remix requires gas in order for transactions to successfully execute.
  • Once you have successfully pointed Remix to your Kaleido chain via MetaMask, click the Deploy button to instantiate the smart contract.
  • You can optionally pass an integer to the constructor if you would like to populate state for the storedData variable

  • This will open up your MetaMask console and prompt you to confirm the proposed deployment transaction.
  • The console will also display the ETH cost for the deployment

  • Click Confirm when you are ready to instantiate your contract on Kaleido
  • The receipt will be returned when the transaction is mined

Interacting with your Contract

  • If a contract is successfully deployed to the targeted network, the Remix browser will provide you with a new dropdown exposing the available methods in your smart contract for interaction via the browser.
  • SimpleStorage contains a set and a get method for updating the storedData global variable and querying its state.
  • In the above example we passed “12345” to the constructor upon deployment.  As a result, a call to the get method returns us “12345”

  • In the Javascript console at the bottom of the screen you can see a record of all invocations and queries to your chain
  • Expand the dropdown next to any call to view the transaction specific details
  • For any transaction that has failed to execute, you can use the Debug option to dig deeper into the EVM opcodes and attempted execution instructions.

  • Additional details on Remix’s functionality can be found in the formal Remix Documentation.