Skip to content

Latest commit

 

History

History
93 lines (72 loc) · 7.5 KB

remix_1.md

File metadata and controls

93 lines (72 loc) · 7.5 KB

Tutorial 5: Smart Contract Development with Remix & Ethereum

For the next few weeks we're going to look at a common system for writing smart contracts (snippets of code) that can be deployed to and interact with Ethereum.

Note: Most students want to build an app that interacts with a blockchain and this is what learning some solidity can help you with. You are not required to use Solidiy/Ethereum for your project; see below for a list of some alternatives. This is simply informative to give you an idea of whats possible. You are encouraged to use whatever tech/IDE/language/system that interests you. Some students are interested in other aspects of blockchains (not SC-based apps) and that is great too!

Solidity

Solidity is a programming language developed specifically to create smart contracts to be executed by the Ethereum virtual machine (EVM). It looks a lot like javascript. The benefit of learning some solidity is that it is widely used, has been around for a long time (relative to other SC languages) and so has support libraries.

Example solidity contract that can ouptut a string: "Hello there amigo"

/* basic contract structure:
 * https://solidity.readthedocs.io/en/v0.7.1/structure-of-a-contract.html
 */
pragma solidity ^0.7.1;

contract helloWorld{

    function hello() public pure returns(string memory){
        //this function call should be free; check gas
        return 'Hello there amigo';
    }
}

Remix

Head to remix.ethereum.org to get started. Find the LEARNETH tutorials. Note the Scam Alert message and always check your URLs.

remix_IDE_0 25 3

Check the plugins tab to make sure LearnEth is in the Active Modules list. Additionally the Solidity compiler needs to be active. See the docs for more info on how to select a tutorial and get started.

plugin_manager_remix


error loading: undefined

remix_error

If you are getting an error try with your laptop and alternately try the links below to a different resource. I have been having an issue using this plugin on the school network.

1. Load a contract

From the home page, click on the File Explorer, open the contracts folder, and select 1_Storage.sol.
image As it says, this lets you store & retrieve value in a variable.

2. Compile the contract

Click on the compiler tab, its a good idea to click Auto compile, make sure Storage is the selected contract, and click Compile 1_Storage.sol. image The green check on the left will let you know the contract compiles (and at least has no syntax/coding errors).

3. Deploy the contract

Deploying a contract is the process of sending it to the main chain to be processed by the state machine. This makes it accessible to others that want to use the contract. In this case the deployment will be simulated and not go to any real Ethereum blockchain (main or test). Click the deploy tab, have a look at the ENVIRONMENT -- this where the contract will go. In this case its the Remix Virtual Machine that simulated the Shanghai version of Ethereum. Select an account to deploy from; this accounts needs ether to pay gas. Make sure storage is selected and click deploy. image You get a status in the console window, that, when clicked on proved some details including gas cost to deploy this contract. image

4. Call the contract

To interact with our deployed contract, click > STORAGE AT 0X.... in the bottom left in the Deployed Contracts list. Find the decoded input to see what you have stored. image

Exercises

  1. Using remix, modify the Storage.sol contract to store and retrieve a text variable: yourName. How much gas does this use, how does this compare to storing an integer?
  2. Where is a deployed contract stored in Ethereum? Comment on the different gas costs for a) deploying a contract, b) calling a function, and c) storing an address.
  3. Above, where it says STORAGE AT 0X...., what does this mean? Are there differences between someone's Ethereum Address and where your contract is stored?
  4. Open Owner.sol in Remix. What does this contract do? Why would this be required?
  5. What are two development enviornments or tool packages that can help with Ethereum smart contract development (besides Remix)? Choose one of these and setup your local environment to start using it. Include a screenshot showing your dev environment.

Developer Learning Tools & Resources

Some links that may be helpful:

Alternate Developer Learning Tools

You may want to build on other blockchains, for example: