click below
click below
Normal Size Small Size show me how
Solidity Microsoft
Solidity learn.microsoft.com
Question | Answer |
---|---|
What is Solidity? | Solidity is a programming language used to code operations on a blockchain network. It is used to create smart contracts that specify user actions and secure, transparent networks. |
What are the components of a smart contract? | The components of a smart contract are the functions, variables, modifiers, and events. |
What programming language knowledge is needed to work with Solidity? | Previous experience with any programming language like C++, Python, or JavaScript is needed to work with Solidity. |
What is the purpose of using Solidity to program blockchain networks? | Solidity is used to program blockchain networks in order to create secure and transparent networks for participants, as well as to specify user actions. |
What are the prerequisites needed to learn Solidity? | The prerequisites needed to learn Solidity include understanding of blockchain fundamentals, knowledge of the Ethereum platform, previous experience with any programming language like C++, Python, or JavaScript, and basic knowledge of programming concepts |
What are Pragma directives? | Pragma directives are instructions that define the compiler version and a list of other compiler options that must be used when compiling a Solidity contract. |
What is the purpose of the '#pragma' directive? | The '#pragma' directive is used to provide additional information to the compiler beyond what is conveyed in the language itself. |
What is the syntax for the _Pragma operator? | The syntax for the _Pragma operator is _Pragma (string-literal), where string-literal can be either a normal or wide-character string literal.. |
What is the purpose of the #pragma GCC poison directive? | The #pragma GCC poison directive is used to remove an identifier completely from a program and ensure that it never creeps back in. |
What is a state variable? | A state variable is a property of a system that depends only on the current, equilibrium state of the system and thus do not depend on the path by which the system arrived at that state. |
How is a state variable declared in Solidity? | A state variable is declared in Solidity with the syntax: type variableName;, where type is the type of the variable and variableName is the name of the variable. |
What are the visibility options for a state variable? | The visibility options for a state variable are public, internal and private. |
What are functions in Solidity? | Functions in Solidity are executable units of code that describe a single action and are reusable and can also be called from other source files like libraries. |
How do you define a function in Solidity? | A function in Solidity is defined with the syntax: function functionName() visibilitySpecifier { // ... }, where functionName is the name of the function and visibilitySpecifier is the visibility (public, private, internal or external) of the function. |
What types of parameters can functions in Solidity accept? | Functions in Solidity can accept parameters of any type, including integers, strings, arrays, and custom types. |
What are function modifiers? | Function modifiers are used to change the behavior of functions. They work by checking a condition before the function executes. |
What is the special symbol used in function modifiers? | The special symbol used in function modifiers is '_;', which indicates where the function body gets inserted. |
What are the other function modifiers that can be used in the function definition? | The other function modifiers that can be used in the function definition are 'pure', 'view' and 'payable'. |
What are events in Solidity? | Events in Solidity describe actions that are taken in the contract and are similar to functions, with parameters that need to be specified when the event is called. |
How do we call an event in Solidity? | To call an event in Solidity, we must use the keyword "emit" with the event name and its parameters. |
What is the transaction log associated with events? | When an event is called, the event is captured as a transaction in the transaction log, which is a special data structure in the blockchain. These logs are associated with the address of the contract, are incorporated into the blockchain, and stay there f |
What are the primary value types used in Solidity? | The primary value types used in Solidity are integers, booleans, string literals, addresses, and enums. |
What operations can be applied to integers? | Comparisons, bit operators, and arithmetic operators can be applied to integers. |
What are some examples of integer definitions? | Examples of integer definitions include signed int, unsigned int, and int with a specified number of bits. |
How are booleans defined? | Booleans are defined using the keyword bool, and they always have a value of either true or false. |
What types of statements can booleans be used in? | Booleans can be used in comparison statements and in function parameters and return types. |
What are string literals? | String literals are characters or words surrounded by either double or single-quotes. |
What escape characters can be used with string literals? | Escape characters that can be used with string literals include <newline>, n, r, and t. |
What is an address? | An address is a type with a 20-byte value that represents an Ethereum user account. |
What is the difference between a regular address and an address payable? | An address payable type is an address that you can send Ether to, and it contains the additional members transfer and send. |
What is an enum? | An enum is a user-defined type that can be used to present many selectable choices, one of which is required. |
Where can enums be declared? | Enums can be declared in contract or library definitions. |
What are reference types? | Reference types provide a data location for the value and include structs, arrays, and mappings. |
What are the data locations available for reference types? | The data locations available for reference types are memory, storage, and calldata. |
What happens when a reference type is assigned to a different memory location? | Assigning a reference type value to a different memory location will always incur a content copy operation, creating an independent clone of the reference type value. |
What is an array? | An array is a way to store similar data in a set data structure. |
How do you create an array? | To create an array of fixed size k and element type T, you'd write T[k]. For a dynamically sized array, you'd write T[]. |
What is a struct? | A struct is a custom type that a user can define to represent real-world objects. Structs are typically used as a schema or to represent records. |
What are some of the members that can manipulate and get information about Arrays? | Some of the members that can manipulate and get information about structs are length, push(), and pop(). |
What are mappings? | Mappings are key value pairs that are encapsulated or packaged together. Mappings are closest to dictionaries or objects in JavaScript. |
How can mappings be used? | Mappings can be used to model real-world objects and perform faster data lookups. The values can include complex types like structs, which makes the mapping type flexible and human readable. |