go to  ForumEasy.com   
JavaPro  
 
 
   Home  |  MyForum  |  FAQ  |  Archive    You are not logged in. [Login] or [Register]  
Forum Home » Blockchain » Smart Contract --I: Coding & Compilation via Remix
Email To Friend  |   Set Alert To This Topic Rewarding Points Availabe: 0 (What's this) New Topic  |   Post Reply
Author Topic: Smart Contract --I: Coding & Compilation via Remix
WebSpider
member
offline   
 
posts: 147
joined: 06/29/2006
from: Seattle, WA
  posted on: 06/07/2021 06:44:36 AM    Edit  |   Quote  |   Report 
Smart Contract --I: Coding & Compilation via Remix
Prerequisites:
  • Remix IDE -- Direct access through browser via https://remix.ethereum.org/
  • Solidity -- One of the smart contract coding language
  •  Profile | Reply Points Earned: 0
    WebSpider
    member
    offline   
     
    posts: 147
    joined: 06/29/2006
    from: Seattle, WA
      posted on: 06/07/2021 06:46:29 AM    Edit  |   Quote  |   Report 
    Step 1. Create a new Solidity file

  • Open Remix IDE via https://remix.ethereum.org/
  • Right-click on contracts and then click on New File
  • Type file's name, for example, Account.sol

  •  Profile | Reply Points Earned: 0
    WebSpider
    member
    offline   
     
    posts: 147
    joined: 06/29/2006
    from: Seattle, WA
      posted on: 06/07/2021 06:48:49 AM    Edit  |   Quote  |   Report 
    Step 2. Code the contract
    Account.sol
    pragma solidity >=0.7.0 <0.9.0;
    
    /**
     * @title Account
     * @dev Store & retrieve value in a variable
     */
    contract Account {
    
        uint256 balance;
    
        /**
         * @dev Deposit amount into account
         * @param amount value to deposit
         */
        function deposite(uint256 amount) public {
            balance += amount;
        }
    
        /**
         * @dev Withdraw amount from account
         * @param amount value to withdraw
         */
        function withdraw(uint256 amount) public {
            balance += amount;
        }
    
        /**
         * @dev Return balance 
         * @return balance value of 'number'
         */
        function getBalance() public view returns (uint256){
            return balance;
        }
        
    }
    

     Profile | Reply Points Earned: 0
    WebSpider
    member
    offline   
     
    posts: 147
    joined: 06/29/2006
    from: Seattle, WA
      posted on: 06/07/2021 06:52:49 AM    Edit  |   Quote  |   Report 
    Step 3. Compile the contract

  • Click on the compiler icon on the very left panel
  • Click the button Compile Account.sol
  • Make sure the compiler icon is green checked

    After successful compilation, a file named Account.json is generated under folder artifacts

    Account.json
    {
    	"deploy": {
    	},
    	"data": {
    		"bytecode": {
    			"generatedSources": [],
    			"linkReferences": {},
    			"object": "6080604...",
    			"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE ... ",
    			"sourceMap": "141:574:0:-:0;;;;;;;;;;;;;;;;;;;"
    		},
    		"deployedBytecode": {
    			"generatedSources": [
    				{ ... }
    			],
    			"immutableReferences": {},
    			"linkReferences": {},
    			"object": "60806040... ",
    			"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE ... ",
    			"sourceMap": "141:574:0:-:0; ... "
    		},
    		"gasEstimates": {
    			"creation": {
    				"codeDepositCost": "108600",
    				"executionCost": "153",
    				"totalCost": "108753"
    			},
    			"external": {
    				"deposite(uint256)": "infinite",
    				"getBalance()": "1115",
    				"withdraw(uint256)": "infinite"
    			}
    		},
    		"methodIdentifiers": {
    			"deposite(uint256)": "3104562b",
    			"getBalance()": "12065fe0",
    			"withdraw(uint256)": "2e1a7d4d"
    		}
    	},
    	"abi": [
    		{
    			"inputs": [
    				{
    					"internalType": "uint256",
    					"name": "amount",
    					"type": "uint256"
    				}
    			],
    			"name": "deposite",
    			"outputs": [],
    			"stateMutability": "nonpayable",
    			"type": "function"
    		},
    		{
    			"inputs": [],
    			"name": "getBalance",
    			"outputs": [
    				{
    					"internalType": "uint256",
    					"name": "",
    					"type": "uint256"
    				}
    			],
    			"stateMutability": "view",
    			"type": "function"
    		},
    		{
    			"inputs": [
    				{
    					"internalType": "uint256",
    					"name": "amount",
    					"type": "uint256"
    				}
    			],
    			"name": "withdraw",
    			"outputs": [],
    			"stateMutability": "nonpayable",
    			"type": "function"
    		}
    	]
    }
    


    It should be noted that two critical items abi and bytecode are listed, also present is gasEstimates.
  •  Profile | Reply Points Earned: 0
    WebSpider
    member
    offline   
     
    posts: 147
    joined: 06/29/2006
    from: Seattle, WA
      posted on: 06/07/2021 06:55:04 AM    Edit  |   Quote  |   Report 
    Step 4. Save the contract

    As the Remix is an online IDE, it's important to save an off-line copy of your contact. The easy way is to backup the entire workspace into a zipped file which can be ported and restored to anywhere.
  • Click on home icon
  • Click the link Download all Files as backup zip

  •  Profile | Reply Points Earned: 0

     
    Powered by ForumEasy © 2003-2005, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.