{"id":3649,"date":"2025-01-23T14:19:00","date_gmt":"2025-01-23T14:19:00","guid":{"rendered":"https:\/\/metaschool.so\/articles\/?p=3649"},"modified":"2025-02-03T02:54:48","modified_gmt":"2025-02-03T02:54:48","slug":"structure-of-a-smart-contract","status":"publish","type":"post","link":"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/","title":{"rendered":"Understanding your Solidity Smart Contract like a Pro: Quick Guide 2025"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_56_1 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#Heres_what_a_smart_contract_is_made_up_of\" title=\"Here&#8217;s what a smart contract is made up of\">Here&#8217;s what a smart contract is made up of<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#1_Variables\" title=\"1. Variables\">1. Variables<\/a><ul class='ez-toc-list-level-4'><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#a_State_variables\" title=\"a. State variables\">a. State variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#b_Local_variables\" title=\"b. Local variables\">b. Local variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#c_Global_variables\" title=\"c. Global variables\">c. Global variables<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#2_Structs\" title=\"2. Structs\">2. Structs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#3_Arrays\" title=\"3. Arrays\">3. Arrays<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#4_Functions\" title=\"4. Functions\">4. Functions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#5_Constructors\" title=\"5. Constructors\">5. Constructors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#6_Events\" title=\"6. Events\">6. Events<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#7_Modifiers\" title=\"7. Modifiers\">7. Modifiers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/metaschool.so\/articles\/structure-of-a-smart-contract\/#8_The_fallback_function\" title=\"8. The fallback function\">8. The fallback function<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<p>It is important to understand the structure of a contract because it determines how the contract will function and what it will be able to do. And that&#8217;s the topic we are going to explore in this blog. <\/p>\n\n\n\n<p>A well-designed <a href=\"https:\/\/metaschool.so\/courses\/writing-your-first-hello-world-contract-in-solidity?ref=Articles&amp;utm_source=Blog_Organic\" target=\"_blank\" rel=\"noreferrer noopener\">smart contract<\/a> should be clear, concise, and easy to understand, and it should accurately reflect the terms of the agreement between the parties involved.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"here-s-what-a-smart-contract-is-made-up-of\"><span class=\"ez-toc-section\" id=\"Heres_what_a_smart_contract_is_made_up_of\"><\/span>Here&#8217;s what a smart contract is made up of<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When you&#8217;re writing your first smart contract, in this case with <a href=\"https:\/\/metaschool.so\/solidity?utm_campaign=smf&amp;utm_source=blog&amp;utm_medium=organic\">Solidity<\/a>, here&#8217;s what its structure would look like and contain.<\/p>\n\n\n\n<p>Inside your FirstContract.sol file, the following code will be included:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/ SPDX-License-Identifier: GPL-3.0\npragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ SPDX-License-Identifier: GPL-3.0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>The first line is a <strong>license identifier,<\/strong> and the second line defines the <strong>pragma version<\/strong> so that Solidity, the programming language for the contract in the case, understands which version our contract is in. This means we are defining the version to be between 0.6.0 and 0.9.0 or equal to 0.6.0.<\/p>\n\n\n\n<p>After defining the pragma version, we can define our smart contract using the &#8220;contract&#8221; keyword, followed by the contract name (in this case, &#8220;FirstContract&#8221;). This is similar to the &#8220;class&#8221; keyword in <a href=\"https:\/\/www.python.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-variables\"><span class=\"ez-toc-section\" id=\"1_Variables\"><\/span>1. Variables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In Solidity, variables are used to store data that can be accessed and modified by functions within a smart contract. Solidity supports three types of variables: state variables, local variables, and global variables.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"a-state-variables\"><span class=\"ez-toc-section\" id=\"a_State_variables\"><\/span>a. State variables<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>are permanently stored in contract storage and can be accessed and modified by functions within the contract. For example, the following code declares a state variable called <code>count<\/code> of type <code>uint256<\/code> and initializes it to 0:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  uint256 count = 0; \/\/ state variable\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">uint256<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">count<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ state variable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"b-local-variables\"><span class=\"ez-toc-section\" id=\"b_Local_variables\"><\/span>b. Local variables<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>On the other hand, local variables are only present while a function is executing. These variables are only accessible within the function in which they are declared and are not permanently stored in contract storage.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"c-global-variables\"><span class=\"ez-toc-section\" id=\"c_Global_variables\"><\/span>c. Global variables<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Lastly, global variables are special variables that exist in the global namespace and provide information about the blockchain. These variables can be accessed from anywhere within the contract and are useful for getting information such as the current block number or the address of the contract.<\/p>\n\n\n\n<p>To make a state variable accessible outside the contract, we can use the <code>public<\/code> keyword before the variable declaration. This allows the variable to be accessed from outside the contract using its name and the contract&#8217;s address. For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  public uint256 count = 0; \/\/ state variable accessible from outside the contract\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">uint256<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">count<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ state variable accessible from outside the contract<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, the <code>count<\/code> variable can be accessed from outside the contract using the contract&#8217;s address and the variable&#8217;s name. This allows other contracts or external programs to read and modify the value of the <code>count<\/code> variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-structs\"><span class=\"ez-toc-section\" id=\"2_Structs\"><\/span>2. Structs<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A Solidity struct is a user-defined data type that allows you to create complex data structures to store multiple values of different types in a single variable. This can be useful for organizing data and making it easier to access and manipulate.<\/p>\n\n\n\n<p>To declare a struct in <a href=\"https:\/\/metaschool.so\/articles\/guide-solidity-contracts\/\">Solidity<\/a>, you use the <code>struct<\/code> keyword followed by the struct name and the variables it will contain inside curly braces <code>{}<\/code>. For example, the following code defines a struct called <code>Student<\/code> that contains the fields <code>name<\/code>, <code>age<\/code>, and <code>grades<\/code>:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  struct Student {\n    string name;\n    uint age;\n    uint[] grades;\n  }\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">struct<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">Student<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">string<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">name<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">age<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\">[] <\/span><span style=\"color: #9CDCFE\">grades<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, the <code>Student<\/code> struct contains three fields: <code>name<\/code> (a string), <code>age<\/code> (an unsigned integer), and <code>grades<\/code> (an array of unsigned integers).<\/p>\n\n\n\n<p>Once a struct is defined, you can create variables of that struct type and initialize them with values. For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  struct Student {\n    string name;\n    uint age;\n    uint[] grades;\n  }\n\n  Student s1 = Student(&quot;John&quot;, 18, [90, 95, 80]); \/\/ create a Student struct variable and initialize it with values\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">struct<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">Student<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">string<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">name<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">age<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\">[] <\/span><span style=\"color: #9CDCFE\">grades<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">Student<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">s1<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">Student<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;John&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">18<\/span><span style=\"color: #D4D4D4\">, [<\/span><span style=\"color: #B5CEA8\">90<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">95<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">80<\/span><span style=\"color: #D4D4D4\">]); <\/span><span style=\"color: #6A9955\">\/\/ create a Student struct variable and initialize it with values<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, we create a <code>Student<\/code> struct variable called <code>s1<\/code> and initialize it with the values &#8220;John&#8221; for the <code>name<\/code> field, 18 for the <code>age<\/code> field, and an array of grades [90, 95, 80] for the <code>grades<\/code> field.<\/p>\n\n\n\n<p>You can then access the individual fields of a struct variable using the <code>.<\/code> operator, as shown below:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  struct Student {\n    string name;\n    uint age;\n    uint[] grades;\n  }\n\n  Student s1 = Student(&quot;John&quot;, 18, [90, 95, 80]);\n\n  function getName() public view returns (string) {\n    return s1.name; \/\/ access the name field of the s1 struct variable\n  }\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">struct<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">Student<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">string<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">name<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">age<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\">[] <\/span><span style=\"color: #9CDCFE\">grades<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">Student<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">s1<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">Student<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;John&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">18<\/span><span style=\"color: #D4D4D4\">, [<\/span><span style=\"color: #B5CEA8\">90<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">95<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">80<\/span><span style=\"color: #D4D4D4\">]);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">getName<\/span><span style=\"color: #D4D4D4\">() <\/span><span style=\"color: #DCDCAA\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">view<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">returns<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #9CDCFE\">string<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">s1<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">name<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ access the name field of the s1 struct variable<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, we create a function called <code>getName<\/code> that returns the <code>name<\/code> field of the <code>s1<\/code> struct variable. This allows us to access the <code>name<\/code> field of the <code>s1<\/code> struct from outside the contract.<\/p>\n\n\n\n<p>Structs are a powerful tool for organizing data in smart contracts, and can be used to create complex data structures to store and manipulate data in them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-arrays\"><span class=\"ez-toc-section\" id=\"3_Arrays\"><\/span>3. Arrays<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>An array is a data type that allows you to store a collection of values of the same type. Arrays can be declared using the <code>type[]<\/code> syntax, where <code>type<\/code> is the data type of the values that the array will store. For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  uint[] numbers; \/\/ declare an array of unsigned integers\n  string[] names; \/\/ declare an array of strings\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\">[] <\/span><span style=\"color: #9CDCFE\">numbers<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ declare an array of unsigned integers<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">string<\/span><span style=\"color: #D4D4D4\">[] <\/span><span style=\"color: #9CDCFE\">names<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ declare an array of strings<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, we declare two arrays: <code>numbers<\/code>, which will store unsigned integers, and <code>names<\/code>, which will store strings.<\/p>\n\n\n\n<p>Once an array is declared, you can initialize it with values and access individual elements using square brackets <code>[]<\/code> and the element&#8217;s index. For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  uint[] numbers = [1, 2, 3, 4, 5]; \/\/ initialize the numbers array with values\n\n  function getNumber(uint index) public view returns (uint) {\n    return numbers[index]; \/\/ return the element at the given index\n  }\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\">[] <\/span><span style=\"color: #9CDCFE\">numbers<\/span><span style=\"color: #D4D4D4\"> = [<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">4<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">]; <\/span><span style=\"color: #6A9955\">\/\/ initialize the numbers array with values<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">getNumber<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">index<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #DCDCAA\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">view<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">returns<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">numbers<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #9CDCFE\">index<\/span><span style=\"color: #D4D4D4\">]; <\/span><span style=\"color: #6A9955\">\/\/ return the element at the given index<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, we initialize the <code>numbers<\/code> array with the values 1, 2, 3, 4, and 5. We also create a function called <code>getNumber<\/code> that takes an index as an input and returns the element at that index in the <code>numbers<\/code> array.<\/p>\n\n\n\n<p>Additionally, Solidity also allows you to specify the length of the array when it is declared. For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  uint[5] numbers; \/\/ declare an array of length 5\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">] <\/span><span style=\"color: #9CDCFE\">numbers<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ declare an array of length 5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, we declare an array called <code>numbers<\/code> that can store up to 5 elements.<\/p>\n\n\n\n<p>Finally, arrays are a useful data type for storing and manipulating collections of values in your smart contracts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-functions\"><span class=\"ez-toc-section\" id=\"4_Functions\"><\/span>4. Functions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A function is a block of code that performs a specific task and can be called from other parts of the smart contract. Functions allow you to organize and modularize your code, making it easier to write and maintain.<\/p>\n\n\n\n<p>To declare a function in Solidity, you use the <code>function<\/code> keyword followed by the function name, the input parameters (if any), and the function body inside curly braces <code>{}<\/code>. For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  function greet() public { \/\/ declare a function called greet\n    \/\/ function body goes here\n  }\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">greet<\/span><span style=\"color: #D4D4D4\">() <\/span><span style=\"color: #DCDCAA\">public<\/span><span style=\"color: #D4D4D4\"> { <\/span><span style=\"color: #6A9955\">\/\/ declare a function called greet<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #6A9955\">\/\/ function body goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, we declare a function called <code>greet<\/code> that takes no input parameters. The function body, which contains the code that the function will execute, is left empty in this example.<\/p>\n\n\n\n<p>To call a function from within the contract, you simply use the function name followed by the input parameters (if any) inside parentheses <code>()<\/code>. For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  function greet() public {\n    \/\/ function body goes here\n  }\n\n  function sayHello() public { \/\/ declare a function called sayHello\n    greet(); \/\/ call the greet function\n  }\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">greet<\/span><span style=\"color: #D4D4D4\">() <\/span><span style=\"color: #DCDCAA\">public<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #6A9955\">\/\/ function body goes here<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">sayHello<\/span><span style=\"color: #D4D4D4\">() <\/span><span style=\"color: #DCDCAA\">public<\/span><span style=\"color: #D4D4D4\"> { <\/span><span style=\"color: #6A9955\">\/\/ declare a function called sayHello<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">greet<\/span><span style=\"color: #D4D4D4\">(); <\/span><span style=\"color: #6A9955\">\/\/ call the greet function<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, we declare a second function called <code>sayHello<\/code> that calls the <code>greet<\/code> function when it is executed.<\/p>\n\n\n\n<p>Functions can also return values using the <code>return<\/code> keyword. For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"pragma solidity &gt;=0.6.0 <0.9.0;\n\ncontract FirstContract {\n  function add(uint a, uint b) public view returns (uint) { \/\/ declare a function called add\n    return a + b; \/\/ return the sum of a and b\n  }\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">pragma<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">solidity<\/span><span style=\"color: #D4D4D4\"> &gt;=<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> &lt;<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">contract<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">FirstContract<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">add<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">a<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">b<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #DCDCAA\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">view<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">returns<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #9CDCFE\">uint<\/span><span style=\"color: #D4D4D4\">) { <\/span><span style=\"color: #6A9955\">\/\/ declare a function called add<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">a<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #9CDCFE\">b<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ return the sum of a and b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this code, we declare a function called <code>add<\/code> that takes two unsigned integer inputs <code>a<\/code> and <code>b<\/code> and returns their sum using the <code>return<\/code> keyword.<\/p>\n\n\n\n<p>Overall, functions are an essential concept and are used to organize and modularize your code, making it easier to write and maintain.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5-constructors\"><span class=\"ez-toc-section\" id=\"5_Constructors\"><\/span>5. Constructors<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The constructor is a special function that is called when the contract is deployed to the blockchain. It is used to initialize the contract and set its initial state. The constructor typically takes any necessary arguments, such as the initial values for the contract&#8217;s variables. <\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"constructor(string memory _name) public {\n    name = _name;\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #DCDCAA\">constructor<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">string<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">memory<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_name<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #9CDCFE\">public<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">name<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">_name<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"the-eventsthese-are-used-to-emit-log-messages-that-can-be-used-to-track-the-contract-s-execution-and-state-events-are-typically-used-to-provide-a-record-of-important-actions-that-have-taken-place-within-the-contract-such-as-the-completion-of-a-transaction-they-can-be-used-to-trigger-external-functions-or-to-provide-information-to-users-of-the-contract-for-example\"><span class=\"ez-toc-section\" id=\"6_Events\"><\/span>6. Events<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p id=\"the-eventsthese-are-used-to-emit-log-messages-that-can-be-used-to-track-the-contract-s-execution-and-state-events-are-typically-used-to-provide-a-record-of-important-actions-that-have-taken-place-within-the-contract-such-as-the-completion-of-a-transaction-they-can-be-used-to-trigger-external-functions-or-to-provide-information-to-users-of-the-contract-for-example\">These are used to emit log messages that can be used to track the contract&#8217;s execution and state. Events are typically used to provide a record of important actions that have taken place within the contract, such as the completion of a transaction. They can be used to trigger external functions or to provide information to users of the contract. <\/p>\n\n\n\n<p id=\"the-eventsthese-are-used-to-emit-log-messages-that-can-be-used-to-track-the-contract-s-execution-and-state-events-are-typically-used-to-provide-a-record-of-important-actions-that-have-taken-place-within-the-contract-such-as-the-completion-of-a-transaction-they-can-be-used-to-trigger-external-functions-or-to-provide-information-to-users-of-the-contract-for-example\">For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"event Deposit(address indexed _from, uint256 _value);\nevent Withdrawal(address indexed _from, uint256 _value);\n\nfunction deposit(uint256 _amount) public {\n    balance = balance.add(_amount);\n    emit Deposit(msg.sender, _amount);\n}\n\nfunction withdraw(uint256 _amount) public {\n    require(balance &gt;= _amount, &quot;Insufficient balance&quot;);\n    balance = balance.sub(_amount);\n    msg.sender.\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">event<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">Deposit<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">address<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">indexed<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_from<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">uint256<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_value<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">event<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">Withdrawal<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">address<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">indexed<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_from<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">uint256<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_value<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">deposit<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">uint256<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #DCDCAA\">public<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">balance<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">balance<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">add<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">emit<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">Deposit<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">msg<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">sender<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">withdraw<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">uint256<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #DCDCAA\">public<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">require<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">balance<\/span><span style=\"color: #D4D4D4\"> &gt;= <\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;Insufficient balance&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">balance<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">balance<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">sub<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">msg<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">sender<\/span><span style=\"color: #D4D4D4\">.<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"7-modifiers\"><span class=\"ez-toc-section\" id=\"7_Modifiers\"><\/span>7. Modifiers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>These are used to modify the behavior of functions. They can be used to check for certain conditions before allowing a function to execute. For example, a modifier might be used to check that a certain requirement has been met before allowing a function to be called, or to ensure that a function can only be called by certain users. <\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"modifier onlyOwner {\n    require(msg.sender == owner, &quot;Only the owner can perform this action&quot;);\n    _;\n}\n\nfunction withdraw(uint256 _amount) public onlyOwner {\n    require(balance &gt;= _amount, &quot;Insufficient balance&quot;);\n    balance = balance.sub(_amount);\n    msg.sender.transfer(_amount);\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">modifier<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">onlyOwner<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">require<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">msg<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">sender<\/span><span style=\"color: #D4D4D4\"> == <\/span><span style=\"color: #9CDCFE\">owner<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;Only the owner can perform this action&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">_<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">withdraw<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">uint256<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #DCDCAA\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">onlyOwner<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">require<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">balance<\/span><span style=\"color: #D4D4D4\"> &gt;= <\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&quot;Insufficient balance&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">balance<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">balance<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">sub<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">msg<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">sender<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">transfer<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">_amount<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"8-the-fallback-function\"><span class=\"ez-toc-section\" id=\"8_The_fallback_function\"><\/span>8. The fallback function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This is a special function that is called when the contract receives an external call to an undefined function. It is used to handle situations where an external party tries to call a function that does not exist in the contract. The fallback function can be used to provide a default behavior for the contract, such as returning an error message or ignoring the call. <\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"function() external {\n    revert(&quot;This function does not exist&quot;);\n}\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\">() <\/span><span style=\"color: #DCDCAA\">external<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">revert<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;This function does not exist&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In conclusion, it is important to design and write smart contracts carefully to ensure that they accurately reflect the terms of the agreement and function as intended. And for that it is crucial to know what components make up the structure of a contract so that you fully understand and work with them. <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":24,"featured_media":12199,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[17],"tags":[47],"class_list":["post-3649","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blockchain","tag-smart-contracts"],"_links":{"self":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/3649","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/comments?post=3649"}],"version-history":[{"count":19,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/3649\/revisions"}],"predecessor-version":[{"id":12200,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/3649\/revisions\/12200"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media\/12199"}],"wp:attachment":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media?parent=3649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/categories?post=3649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/tags?post=3649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}