{"id":26469829,"url":"https://github.com/ocdbytes/first_contract","last_synced_at":"2025-03-19T17:09:32.707Z","repository":{"id":113749544,"uuid":"448613080","full_name":"ocdbytes/First_Contract","owner":"ocdbytes","description":"This is first ever Solidity Contract which stores the data of the people according to their wallet address on the virtual or actual blockchain platform","archived":false,"fork":false,"pushed_at":"2022-01-17T17:19:47.000Z","size":3617,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-14T10:46:07.849Z","etag":null,"topics":["blockchain","ethereum","solidity","transaction"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ocdbytes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-01-16T16:43:30.000Z","updated_at":"2022-02-05T18:29:01.000Z","dependencies_parsed_at":"2023-03-15T11:30:42.168Z","dependency_job_id":null,"html_url":"https://github.com/ocdbytes/First_Contract","commit_stats":null,"previous_names":["ocdbytes/first_contract"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocdbytes%2FFirst_Contract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocdbytes%2FFirst_Contract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocdbytes%2FFirst_Contract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocdbytes%2FFirst_Contract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ocdbytes","download_url":"https://codeload.github.com/ocdbytes/First_Contract/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244470251,"owners_count":20457908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","ethereum","solidity","transaction"],"created_at":"2025-03-19T17:09:32.059Z","updated_at":"2025-03-19T17:09:32.693Z","avatar_url":"https://github.com/ocdbytes.png","language":"Solidity","readme":"\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/main.png\" width=\"100%\"\u003e\u003c/img\u003e\n\u003c/p\u003e\n\n# BlockChain - Solidity - First Contract\n\n# IDE used for solidity\n\n[https://remix.ethereum.org/](https://remix.ethereum.org/)\n\n![Screenshot 2022-01-15 at 4.16.09 PM.png](BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/Screenshot_2022-01-15_at_4.16.09_PM.png)\n\n### Our first solidity contract →\n\n```solidity\npragma solidity ^0.6.0; // defining the solidity version\n\n// creating a contract\ncontract SimpleStorage{\n    // uint256 , int 256 (uint - unsigned integer, int - signed integer)\n\n    // uint256 favoriteNumber = 5; // declaring a unsigned integer 5\n    // bool favoriteBool = true; // declaring a boolean\n    // string favoriteString = \"String\"; // declaring a string\n    // int256 favoriteInt = -5; // declaring a integer '-5'\n    // address favoriteAddress = 0x839F42a69Cc24F391DC4F09273f494578653edEC; //declaring an address\n    // bytes32 favoriteBytes = \"cat\"; // declaring byte\n\n    // this will get initialized to 0\n    uint256 favoriteNumber;\n\n    // declaring the function to edit the value of favoriteNumber declared above\n    function store(uint256 _favoriteNumber) public {\n        favoriteNumber = _favoriteNumber;\n    }\n}\n```\n\n### How do deploy our contract on blockchain\n\n![Screenshot 2022-01-15 at 4.29.37 PM.png](BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/Screenshot_2022-01-15_at_4.29.37_PM.png)\n\n- After deploying there will be interaction buttons here in Deployed Contracts\n\n![Screenshot 2022-01-15 at 4.43.19 PM.png](BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/Screenshot_2022-01-15_at_4.43.19_PM.png)\n\n- but here we can’t see any option to see the favourite number so we will change our ‘favoriteNumber’ variable to public\n\n```solidity\npragma solidity ^0.6.0; // defining the solidity version\n\n// creating a contract\ncontract SimpleStorage{\n\n    // this will get initialized to 0\n    uint256 public favoriteNumber;\n\n    // declaring the function to edit the value of favoriteNumber declared above\n    function store(uint256 _favoriteNumber) public {\n        favoriteNumber = _favoriteNumber;\n    }\n}\n```\n\n- Now we can see our option\n\n![Screenshot 2022-01-15 at 4.55.40 PM.png](BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/Screenshot_2022-01-15_at_4.55.40_PM.png)\n\n### Function Types →\n\n- Public Function - Anyone can call\n- External Function - Function can be called by external contract\n- Internal Function - Function can only be called internally.\n- Private Function - Function and Variables are only visible for the contract they are defined in.\n\nIf we don’t give public to a variable or function it will automatically designated as [internal]\n\n### View function and Pure function\n\n```solidity\npragma solidity ^0.6.0; // defining the solidity version\n\n// creating a contract\ncontract SimpleStorage{\n\n    // this will get initialized to 0\n    uint256 public favoriteNumber;\n\n    // declaring the function to edit the value of favoriteNumber declared above\n    function store(uint256 _favoriteNumber) public {\n        favoriteNumber = _favoriteNumber;\n    }\n    // VIEW and PURE function - These function don't use transaction to operate\n    // view function - view function is used to get the state of the blockchain\n    // pure function - pure function is defined when some calculation is going on\n    function retrieve() public view returns(uint256) {\n        return favoriteNumber;\n    }\n}\n```\n\n## Structures in Solidity\n\n```solidity\npragma solidity ^0.6.0; // defining the solidity version\n\n// creating a contract\ncontract SimpleStorage{\n\n    uint256 favoriteNumber;\n\n    // making a structure\n    struct People{\n        uint256 favoriteNumber;\n        string name;\n    }\n\n    // making a structure object\n    People public person = People({favoriteNumber : 2, name : \"Patrick\"});\n}\n```\n\n## Arrays in solidity\n\n```solidity\npragma solidity ^0.6.0; // defining the solidity version\n\n// creating a contract\ncontract SimpleStorage{\n\n    uint256 favoriteNumber;\n\n    // making a structure\n    struct People{\n        uint256 favoriteNumber;\n        string name;\n    }\n\n    People[] public people; // declaring a dynamic array\n\n\t\t// Function to add a person in people array\n    function addPerson(string memory _name, uint256 _favoriteNumber) public{\n        people.push(People({favoriteNumber : _favoriteNumber, name : _name}));\n    }\n\n    // function to view favorite number\n    function retrieve() public view returns(uint256) {\n        return favoriteNumber;\n    }\n}\n```\n\n### Difference between Memory \u0026 Storage\n\nWhen we declare a variable in memory it will only be stored while execution of the program\n\n```solidity\nuint256 memory number1;\n```\n\nWhen we declare a variable in storage it will also be available after the function execution\n\n```solidity\nuint256 memory number2;\n```\n\n## Mapping\n\n```solidity\npragma solidity ^0.6.0; // defining the solidity version\n\n// creating a contract\ncontract SimpleStorage{\n\n    uint256 favoriteNumber;\n    // making a structure\n    struct People{\n        uint256 favoriteNumber;\n        string name;\n    }\n\n\n    People[] public people; // declaring a dynamic array\n\n    // MAPPING - A data structure to get a value in an array without iterating to it whole\n    mapping(string =\u003e uint256) public nameToFavoriteNumber;\n\t\t// string as input to number as output\n\n    function addPerson(string memory _name, uint256 _favoriteNumber) public{\n        people.push(People({favoriteNumber : _favoriteNumber, name : _name}));\n        nameToFavoriteNumber[_name] = _favoriteNumber;\n    }\n\n    // function to view favorite number\n    function retrieve() public view returns(uint256) {\n        return favoriteNumber;\n    }\n}\n```\n\n### Our final Contract\n\n![Screenshot 2022-01-16 at 7.29.19 PM.png](BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/Screenshot_2022-01-16_at_7.29.19_PM.png)\n\nIn this contract we can :\n\n- Add person to the Array\n- Get any Person from array number\n- Find anyone from their favourite number\n\n## How to deploy\n\n![Screenshot 2022-01-16 at 9.44.30 PM.png](BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/Screenshot_2022-01-16_at_9.44.30_PM.png)\n\n- Step 1 : Select ‘Injected Web 3’ from environment then Metamask will popup and ask for connection the Click connect on that.\n- Step 2 : Click Deploy. Then a popup will show up on Metamask to confirm the payment\n- Step 3: Confirm the payment\n\nAfter this we can check the transaction hash generated on payment and verify that on Rinkby Etherscan\n\n```solidity\n// Transaction Hash\n0xe7597b6c979095355d5246489f6294df83687dfc59d7caefd995555e05ea25fa\n```\n\nLink → [https://rinkeby.etherscan.io/tx/0xe7597b6c979095355d5246489f6294df83687dfc59d7caefd995555e05ea25fa](https://rinkeby.etherscan.io/tx/0xe7597b6c979095355d5246489f6294df83687dfc59d7caefd995555e05ea25fa)\n\nNow everytime we interact with our deployment we have to pay some gas fee\n\n## Interaction (with Deployed Contract)\n\n![Screenshot 2022-01-16 at 9.54.51 PM.png](BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/Screenshot_2022-01-16_at_9.54.51_PM.png)\n\n- Click Add Person.\n- Metamask popup will appear for payment.\n\n\u003cp align=\"center\"\u003e\n\t\u003cimg src=\"BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/Screenshot_2022-01-16_at_9.54.23_PM.png\" width=\"200px\"\u003e\u003c/img\u003e\n\u003c/p\u003e\n    \n\u003e\u003e\u003e\u003e\u003e\u003e\u003e 0311ce94f26f573223b4ce136ae725b60302c3a3\n- After confirming the payment hash will be generated. Check it on rinkby etherscan\n\n```solidity\n0xa3fcd67e88fd2dde08e0c5a13ffee5ed0b19b9a1728ff943314c76188cc85524\n```\n\n## Our Deployed Contract\n\n[https://rinkeby.etherscan.io/address/0x924bdf9655e84a65cb9af6431ac9e7eb04a550f8](https://rinkeby.etherscan.io/address/0x924bdf9655e84a65cb9af6431ac9e7eb04a550f8)\n\n## --------------------------------------------------------------------------------------------------------------\n\n# BlockChain - Solidity(Advance Contracts)\n\n## Creating a “Storage Factory” using simple storage we created in basics and using it to create multiple “Simple Storage” for user who interacts with “Storage Factory”\n\n```solidity\n// SPDX_License_Identifier: MIT\npragma solidity ^0.6.0;\n\n// importing simple storage contract\nimport \"./SimpleStorage.sol\";\n\n// creating storage factory contract\ncontract StorageFactory{\n\n    // creating a simple storage array that will store all the contracts created by the user\n    SimpleStorage[] public simpleStorageArray;\n\n    // function to create a new simpleStorage contract\n    function createSimpleStorageContract() public{\n        SimpleStorage simpleStorage = new SimpleStorage(); // creating a simple storage contract instance\n        simpleStorageArray.push(simpleStorage); // pushing created contract to simpleStorageArray\n    }\n\n    // To interact with the created contract we need\n    // * Address\n    // * Application Binary Interface (ABI)\n\n    // Function to store value in the contract defined by the index of array\n    function sFStore(uint256 _simpleStorageIndex, uint256 _simpleStorageNumber) public {\n        // getting the contract to interact\n        SimpleStorage simpleStorage = SimpleStorage(address(simpleStorageArray[_simpleStorageIndex]));\n        // storing the value in contarct\n        simpleStorage.store(_simpleStorageNumber);\n    }\n\n    // Function to call the retrieve function in contract\n    function sFGet(uint256 _simpleStorageIndex) public view returns(uint256){\n        // getting the contract to interact\n        SimpleStorage simpleStorage = SimpleStorage(address(simpleStorageArray[_simpleStorageIndex]));\n        // storing the value in contarct\n        return simpleStorage.retrieve();\n    }\n}\n```\n\n![Screenshot 2022-01-16 at 11.01.54 PM.png](BlockChain%20-%20Solidity%2032dbc76c3bc14f09992abbdd5dc0af13/Screenshot_2022-01-16_at_11.01.54_PM.png)\n\n### Interaction window will look something like this\n\n## If we want to inherit all the functions from on contract to another (like in inheritance in loops) we can do some thing like this\n\n```solidity\n// SPDX_License_Identifier: MIT\npragma solidity ^0.6.0;\n\n// importing simple storage contract\nimport \"./SimpleStorage.sol\";\n\n// creating storage factory contract\n// 'is' contract__name will do our inheritence job\ncontract StorageFactory is SimpleStorage{\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focdbytes%2Ffirst_contract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Focdbytes%2Ffirst_contract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focdbytes%2Ffirst_contract/lists"}