Compare commits

...

4 Commits

Author SHA1 Message Date
BahadorGh
d926885446 Merge fa02b20067 into 7e9e6af408 2023-06-21 21:08:25 +08:00
Julien Le Coupanec
7e9e6af408 Merge pull request #334 from samyak003/master
Added cheatsheet for Firebase CLI
2023-06-19 12:59:07 +02:00
Samyak
0ee3753e2f Added cheatsheet for Firebase CLI 2023-06-18 19:58:27 +05:30
Bahador Gh
fa02b20067 Adding solidity cheatsheet 2023-01-07 15:44:05 +03:30
3 changed files with 361 additions and 0 deletions

View File

@@ -124,6 +124,7 @@ Feel free to take a look. You might learn new things. They have been designed to
- [Nginx](tools/nginx.sh)
- [PM2](tools/pm2.sh)
- [Ubuntu](tools/ubuntu.sh)
- [Firebase CLI](tools/firebase_cli.md)
</details>
## 🙌🏼 How to Contribute?

220
backend/solidity.sol Normal file
View File

@@ -0,0 +1,220 @@
/* *******************************************************************************************
* Defining Licensing of the smart contract =>
******************************************************************************************** */
// SPDX-License-Identifier: MIT
// List of allowed SPDX licenses to use => https://spdx.org/licenses/
/* *******************************************************************************************
* Defining solidity compiler(solc) version for compiling the smart contract =>
- Some possible ways to use:
- pragma solidity 0.8.0; ==> compiler version set exactly on 0.8.0 version
- pragma solidity ^0.8.0; ==> compiler version set above 0.8.0 version and lower than 0.9.0 version
- pragma solidity >= 0.7.0 < 0.9.0; ==> compiler version set equal or above 0.7.0 version and lower than 0.9.0 version
******************************************************************************************** */
pragma solidity ^0.8.0;
/* *******************************************************************************************
* Creating the smart contract => contract ContractName {}
- Note: Contracts are like classes in other programming languages.
- Note: Naming convention is like this for declaring contract: MyContract
******************************************************************************************** */
contract HelloWorld {
/* *******************************************************************************************
* Data types:
* 1) Value types:
- Value stored in smart contract storage slot
- bool
- int
- uint
- address
- bytes1 ... bytes32
- enum
* 2) Reference types:
- A reference to a stored value in smart contract storage slot will be set
- array
- string
- mapping
- struct
- bytes
******************************************************************************************** */
/* *******************************************************************************************
* Variable types:
* 1) State variables => Variables which
- Get permanently stored on blockchain(smart contract storage)
- Use most gas usage in smart contracts
- Accessible on whole smart contract
* 2) Local variables => Variables which
- Not stored on blockchain
- Use less gas in smart contracts
- Are living and working just in function body
* 3) Global variables => Variables which
- Provide information about the blockchain
- Can be used both as state variables and local variables
- Mainly used to determine contract owner and checking time
******************************************************************************************** */
/* *******************************************************************************************
* Visibility:
* 1) Variables:
- public
- private
- internal
* Ex: uint public number;
- Note: visibility is just for state variables and not applicable on local variables
- Note: default visibility of a state variable is(if we don't declare visibility scope) --> internal
- Note: if declare a variable to have 'public' scope, automatically a 'getter function' will be created for that variable
* 2) Functions:
- public
- private
- internal
- external
* Ex: function setNumber() public {}
******************************************************************************************** */
/* *******************************************************************************************
* Function types:
* 1) Non-Payable => Functions which
- Write on the blockchain
- Are our default functions type
- Are not able to accept deposits on the smart contract
* Ex: function setNumber() public {}
* 2) View => Functions which
- Are able to show us data
- Read from blockchain
* Ex: function setNumber() public view {}
* 3) Pure => Functions which
- Neither read nor write on blockchain
- Just do a specific work for us (ex: making sum of 2 numbers and returning back the value)
* Ex: function setNumber() public pure {}
* 3) Payable => Functions which
- Are able to accept Ether deposits on the smart contract
* Ex: function setNumber() public payable {}
******************************************************************************************** */
/* *******************************************************************************************
* Constructor => A function which
- Is optional
- Does not have a name
- Does not have visibility scope
- Executed during contract deployment
- Can take parameters while deploying
- Initializes smart contract state variables
- Will be at most 1 within each smart contract
- Can have payable attribute associatede with it
* Ex: constructor(uint _number) { number = _number; }
******************************************************************************************** */
/* *******************************************************************************************
* Data Locations =>
* Each variable declared and used in a contract has a data location:
- Storage:
- global memory available to all functions within a contract.
- oermanent storage that Ethereum stores on every node.
- Memory:
- local memroy available to every function within a contract.
- short living in functions.
- Calldata:
- where all incoming function execution data is stored(including function arguments)
- non-modifiable memory location(note: similar to memrory location, except it is not modifiable)
- Stack
- a stack which is maintained by EVM(Etheereum Virtual Machine) for loading variables and
intermediate values for working with Ethereum instruction set(the working set memory for the EVM).
- max limit is 1024 levels, and exceeding this limit(by storing anything more than that), raises an exception.
- Note: data location of variable, is dependent on:
- Location of the variable declaration
- Data type of the variable
- Note: We face them mostly, when are working with reference type variables.
******************************************************************************************** */
/* *******************************************************************************************
* Events =>
- Used for logging(like other languages)
- Used to notify applications about changes in contracts
- can be used to "call" JavaScript callbacks in the user interface of a dapp
- Primarily for informing the calling application about the current state of the contract
- Declared with 'event' keyword
- Firing them with 'emit' keyword
- Note: Events can be declared anonymous.
- Note: Events can have 'indexed' keyword in variable declaration(to make easier filtering of some specific data)
* Ex: event EventName(address sender,uint number)
* emit EventName(address(0), 10)
******************************************************************************************** */
/* *******************************************************************************************
* Error handling =>
* 1) Require
- Check a condition,
if true => go to next line codes,
if false => show a string message and revert to privious state
- Refund remaining gas to the caller
- Note: Use require conditions, all at beginning the function.
* Ex: require(number >= 10, "number must be greater than 10");
* 1) Revert
- Similar to require, but can have more complex conditions
- Refund remaining gas to the caller
* Ex: if(number <= 10) { revert("number must be greater than 10"); }
* 1) Assert
- Mainly used in writing contract tests
- Don't refund remaining gas to the caller
* Ex: uint number = 123;
* assert(number == 10);
******************************************************************************************** */
/* *******************************************************************************************
* Enum =>
- A user defined data type
* Ex: enum OrderStatus { pending, accepted, completed, rejected};
* OrderStatus order = OrderStatus.accepted;
******************************************************************************************** */
/* *******************************************************************************************
* Mapping =>
* Declaration: `mapping(_KeyType => _ValueType) mappingName`
- Mappings are like **Dictionary** or **hash table** which are virtually initialized
such that every possible key exists and is mapped to a specific value.
- Note: **key** can be any type which EVM internally knows about it(exceptions are: a dynamically sized array, a contract, an enum, or a struct.
- Note: **value** can actually be any type, including mappings.
******************************************************************************************** */
/* *******************************************************************************************
* Struct
* Somehow we can pack some data types(and ofcourse data values) of an specific entity with structs:
* Ex: struct UserInfo { string fName; string lName; uint8 age; address wallet;}
* UserInfo user;
******************************************************************************************** */
}

140
tools/firebase_cli.md Normal file
View File

@@ -0,0 +1,140 @@
# Firebase CLI Guide
Firebase CLI (Command Line Interface) is a powerful tool that allows developers to interact with Firebase services and manage their Firebase projects directly from the command line. It provides a convenient and efficient way to deploy projects, manage databases, configure authentication, and more, streamlining the development and deployment processes.
## Installation
To use the Firebase CLI, you need to have Node.js and npm (Node Package Manager) installed on your system. Follow the steps below to install the Firebase CLI:
1. Install Node.js and npm by downloading the installer from the [official Node.js website](https://nodejs.org/en/download/) and following the installation instructions for your operating system.
2. Once Node.js and npm are installed, open your terminal or command prompt and run the following command to install the Firebase CLI globally:
```
npm install -g firebase-tools
```
This command will download and install the Firebase CLI package from the npm registry.
3. After the installation is complete, you can verify that the Firebase CLI is installed correctly by running the following command:
```
firebase --version
```
If the installation was successful, you will see the version number of the Firebase CLI printed in the terminal.
Congratulations! You have successfully installed the Firebase CLI.
## Usage
The Firebase CLI allows you to interact with Firebase services and manage your Firebase projects from the command line. Here are some common tasks you can perform using the Firebase CLI:
- Initialize a new Firebase project in your current directory.
- Deploy your Firebase project to Firebase hosting.
- Manage Firebase Authentication, Realtime Database, Cloud Firestore, Cloud Functions, and other Firebase services.
- Configure Firebase project settings.
- Interact with Firebase emulators for local development and testing.
To use the Firebase CLI, open your terminal or command prompt and run the `firebase` command followed by the desired command and options.
Here's an example of the basic usage:
```
firebase <command> [options]
```
Replace `<command>` with the specific Firebase command you want to execute, and `[options]` with any additional options or flags required for that command.
For more detailed usage information, you can run the following command:
```
firebase help
```
This command will display the available Firebase commands and provide detailed information about each command.
## Commands
Here are the commonly used Firebase CLI commands along with a brief explanation, syntax, and an example for each command:
- `firebase init`: Initializes a new Firebase project in the current directory.
- Syntax: `firebase init [options]`
- Example: `firebase init hosting` initializes Firebase Hosting for the current project.
- `firebase deploy`: Deploys your Firebase project to Firebase hosting or other Firebase services.
- Syntax: `firebase deploy [options]`
- Example: `firebase deploy --only hosting` deploys only the Firebase Hosting content.
- `firebase serve`: Starts local development servers and Firebase emulators.
- Syntax: `firebase serve [options]`
- Example: `firebase serve --only functions,hosting` starts the Firebase emulators for functions and hosting.
- `firebase login`: Authenticates the Firebase CLI with your Firebase account.
- Syntax: `firebase login [options]`
- Example: `firebase login --no-localhost` initiates an interactive login session without connecting to localhost.
- `firebase logout`: Logs out from the Firebase CLI.
- Syntax: `firebase logout [options]`
- Example: `firebase logout` logs out the currently authenticated user.
- `firebase use`: Sets the active Firebase project for the current directory.
- Syntax: `firebase use <project_id> [options]`
- Example: `firebase use my-project` sets "my-project" as the active Firebase project.
- `firebase functions`: Interacts with Firebase Cloud Functions.
- Syntax: `firebase functions:command [options]`
- Example: `firebase functions:delete [function_name]` deletes all functions that match the specified name in all regions.
- `firebase database`: Interacts with Firebase Realtime Database.
- Syntax: `firebase database:command [options]`
- Example: `firebase database:get /users` retrieves data from the Firebase Realtime Database.
- `firebase firestore`: Interacts with Firebase Cloud Firestore.
- Syntax: `firebase firestore:command [options]`
- Example: `firebase firestore:delete collection/document` deletes a document from the Firestore database.
- `firebase auth`: Interacts with Firebase Authentication.
- Syntax: `firebase auth:command [options]`
- Example: `firebase auth:export users.csv` exports user data to a CSV file.
- `firebase hosting`: Interacts with Firebase Hosting.
- Syntax: `firebase hosting:command [options]`
- Example: `firebase hosting:disable` disables Firebase Hosting for the current project.
- `firebase remoteconfig`: Interacts with Firebase Remote Config.
- Syntax: `firebase remoteconfig:command [options]`
- Example: `firebase remoteconfig:get template` retrieves the Remote Config template.
- `firebase ext`: Interacts with Firebase Extensions.
- Syntax: `firebase ext:command [options]`
- Example: `firebase ext:install firebase/delete-user-data` installs the Firebase Extension named "firebase/delete-user-data".
- `firebase appdistribution`: Interacts with Firebase App Distribution.
- Syntax: `firebase appdistribution:command [options]`
- Example: `firebase appdistribution:testers:add` Adds testers to the project.
- `firebase use --add`: Adds an existing Firebase project to the current directory
- Syntax: `firebase use --add`
- Example: `firebase use --add` interactively adds an existing Firebase project.
- `firebase projects:create`: Creates a new Firebase project.
- Syntax: `firebase projects:create [options]`
- Example: `firebase projects:create --display-name "My Project"` creates a new Firebase project with the given display name.
These are just a few examples of the available commands. You can explore more commands and their options by running `firebase help` or visiting the [official Firebase CLI documentation](https://firebase.google.com/docs/cli).