Skip to content

Commit

Permalink
Merge branch 'main' into issue#454uint
Browse files Browse the repository at this point in the history
  • Loading branch information
jackleeio authored Mar 27, 2024
2 parents b5582b9 + 1ffe270 commit 85424c4
Show file tree
Hide file tree
Showing 531 changed files with 21,846 additions and 818 deletions.
14 changes: 13 additions & 1 deletion docs/core/build/fluent.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,16 @@ displayed_sidebar: coreSidebar

[Fluent Wallet](https://fluentwallet.com/) is a browser extension wallet supported by the Conflux Foundation, designed to provide convenient and secure digital asset management services for Conflux users. Fluent Wallet supports Conflux Core Space and eSpace while also offering connectivity to other EVM-compatible chains.

Fluent Wallet provides [integration documentation](https://fluent-wallet.zendesk.com/hc/en-001/sections/4410740784411-Developer-Documentation) for dApp developers, which includes use cases for connecting wallets and RPC API content. Developers can complete the integration process by following the relevant documentation.
Fluent Wallet provides [integration documentation](https://docs.fluentwallet.com/conflux/) for Conflux Core Space dApp developers, which includes use cases for connecting wallets and RPC API content. Developers can complete the integration process by following the relevant documentation.

:::tip

Refer to https://docs.fluentwallet.com/espace/ for eSpace integration tutorials. It is also recommended to refer to [use-wallet](../../general/build/tools/use-wallet.md) to simplify wallet integration.

:::

## Resources

- [Fluent Integration Quick Start](https://docs.fluentwallet.com/conflux/get-started/set-up-dev-environment/)
- [React Tutorial](https://docs.fluentwallet.com/conflux/category/tutorials/)
- [Conflux Provider API](https://docs.fluentwallet.com/conflux/reference/provider-api/)
1 change: 1 addition & 0 deletions docs/core/core-developer-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,4 @@ If your account does not have enough balance, you will encounter the following e
2. Refer to [SDKs](./build/sdks-and-tools/sdks.md) for examples of other SDKs.
3. [Core Space Faucet](https://faucet.confluxnetwork.org/)
4. [Conflux Core Scan](https://confluxscan.io/)
5. [use-wallet](../general/build/tools/use-wallet.md): a front-end perspective wallet hooks library providing rapid development support for lightweight dapps, with React and Vue3 support.
2 changes: 1 addition & 1 deletion docs/espace/DeveloperQuickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ After compiling your contracts, the easiest way to deploy using Remix is by [set

Now, in the “Deploy and Run Transactions” tab, use the “Environment” drop-down and select “Injected Provider - MetaMask.”

![](./img/injectedProviderMM.avif)
![](./img/injectedprovidermm.png)

Connect your wallet and select the Conflux eSpace Testnet. Your account should be selected automatically in Remix, and you can click “Deploy.” A complete workflow for Remix usage is shown [here](./tutorials/deployContract/remix.md)

Expand Down
Binary file added docs/espace/img/injectedprovidermm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
displayed_sidebar: generalSidebar

---


# Constant vs Immutable

1. `constant`: Declares a constant that must be initialized at the time of declaration and cannot be altered thereafter.
Expand Down
51 changes: 51 additions & 0 deletions docs/general/build/smart-contracts/gas-optimization/error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
displayed_sidebar: generalSidebar
---
# Error

In Solidity, developers can define errors in three main forms: `revert`, `require`, and `assert`. The main differences between these methods from a functional perspective are two-fold:

1. Whether they can throw developer-defined error reasons;
2. Whether they can throw developer-defined errors carrying variables;

The main differences are as follows:

| Type | Custom Reason | Carries Variable | Example |
|----------|---------------|------------------|----------------------------------------------------------------|
| `revert` ||| Reason: UnauthorizedAccess(0x05D01CAF54524A610CCF187082201120757f7AE5) |
| `require`||| Reason: UnauthorizedAccess |
| `assert` ||| Reason: Assertion violated |

**DemoCode**

Below, we use the three forms of errors to observe the changes in gas usage:

```solidity
contract Error {
error UnauthorizedAccess();
// gas: 164
function errorRevert() external pure {
if (true) revert UnauthorizedAccess();
}
// gas: 268
function errorRequire() external pure {
require(false, "UnauthorizedAccess");
}
// gas: 180
function errorAssert() external pure {
assert(false);
}
}
```

the gas optimization suggestions are as follows:

🌟1. `revert` is the most recommended as it can throw error messages as well as related variables.

🌟2. The string in `require` is stored on-chain, which not only consumes more gas but also increases the contract size. It is recommended to choose based on actual needs.

🌟3. If there's a scenario where `assert` is used, it's suggested to replace it with `revert`.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
displayed_sidebar: generalSidebar
sidebar_position: 2
---
# Memory vs Calldata

1. `memory`: Typically used for function parameters and temporary variables within functions. Stored in memory and not persistent on the blockchain.

2. `calldata`: Similar to memory, stored in memory and not persistent on the blockchain. The key difference is that calldata variables are immutable and commonly used for function parameters.


Learn more:
[Data location and assignment behavior](https://docs.soliditylang.org/en/latest/types.html#data-location)

Below, we demonstrate how to write data using both `calldata` and `memory`

```solidity
contract CalldataAndMemory {
struct Confi {
uint16 age;
string name;
string wish;
}
Confi John;
Confi Jane;
function writeToJohn(Confi calldata JohnData) external {
John = JohnData;
}
function writeToJane(Confi memory JaneData) external {
Jane = JaneData;
}
}
```

Recommendations for gas optimization:

🌟 In practical situations, if it's possible to use calldata, it is recommended to use `calldata` instead of `memory`.


42 changes: 42 additions & 0 deletions docs/general/build/smart-contracts/gas-optimization/unchecked.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
displayed_sidebar: generalSidebar

---
# Unchecked

We know that before the Solidity version 0.8, it was necessary to manually import the SafeMath library to ensure data safety and avoid overflow, thereby preventing overflow attacks.

After Solidity version 0.8, Solidity performs a check every time there is a data change to determine whether there is an overflow, thus deciding whether to throw an exception.

This also means that the check incurs additional gas costs. By using `unchecked` wisely, it is possible to effectively remove the intermediate checking step, thus achieving the purpose of saving gas.

Learn more: [Checked or Unchecked Arithmetic](https://docs.soliditylang.org/en/v0.8.25/control-structures.html#checked-or-unchecked-arithmetic)

**Demo Code**

Below, we demonstrate using both a conventional for-loop and an `unchecked` for-loop. Note that since `iterations` is already of type `uint256`, there will not be an overflow issue.

```solidity
contract UncheckedExample {
// gas: 1910309
function conventionalForLoop(uint256 iterations) external pure returns (uint256 result) {
for (uint256 index = 0; index < iterations; index++) {
result = index + 1;
}
}
// gas: 570287
function uncheckedForLoop(uint256 iterations) external pure returns (uint256 result) {
for (uint256 index = 0; index < iterations; ) {
unchecked {
result = index + 1;
index++;
}
}
}
}
```

Recommendations for gas optimization:

🌟 In situations where security is controllable, the unchecked block can be used to save gas.
2 changes: 2 additions & 0 deletions docs/general/conflux-basics/economics.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ The amount of pre-mined tokens in the genesis block of Conflux Network is 5 bill
- *Ecosystem Fund*: 40% of the genesis tokens will be offered to community developers supporting the DApps in the Conflux ecosystem. This proportion of tokens will be unlocked within four years.
- *Public Fund*: 0% of the genesis tokens will be allocated into the public fund account.

![CFX Token Distribution](./img/CFX_Distribution.png)

### **Operational Phase CFX Distribution**

In the operational phase, system maintainers are inspired to promote continuous system upgrading; ecosystem contributors are encouraged to constantly generate value for the ecosystem. Meanwhile, self-adaptive configuration of Conflux system resources is promoted through system resource marketization.
Expand Down
2 changes: 1 addition & 1 deletion docs/general/conflux-basics/ecosystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ If you want to learn how to use Zero Gravity, you can follow [this](../tutorials

## [ConfluxHub (Cross-Space Bridge, CFX Staking & Governance)](https://confluxhub.io/)

Governance ConfluxHub is a vital component of the Conflux ecosystem, serving as a versatile platform for cross-space bridges, CFX staking, and governance.
ConfluxHub is a vital component of the Conflux ecosystem, serving as a versatile platform for cross-space bridges, CFX staking, and governance.

If you want to learn how to use Confluxhub, you can follow [this](../tutorials/transferring-funds/transfer-funds-across-spaces.md) tutorial.

Expand Down
13 changes: 12 additions & 1 deletion docs/general/conflux-basics/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ ERC20 is a standard for tokens on the Ethereum blockchain. It specifies a set of
### **ERC721**
ERC721 is a standard for non-fungible tokens (NFTs) on the Ethereum blockchain. Unlike ERC20 tokens, which are identical to each other, each ERC721 token is unique. This makes them suitable for representing ownership of unique items or assets. Like ERC20, ERC721 tokens can also exist on the Conflux network, especially if they are transferred from the Ethereum network.

### **Fork**
### **EVM (Ethereum Virtual Machine)**
The Ethereum Virtual Machine (EVM) is a powerful, sandboxed virtual stack embedded within each full Ethereum node, responsible for executing contract bytecode. Contracts are written in high-level languages, like Solidity, then compiled into bytecode, which the EVM can read and execute. The EVM ensures that programs do not have access to each other's state, thus allowing for the safe execution of code without risking the network's security. It is pivotal for enabling the programmability and flexibility that smart contracts offer in the Ethereum ecosystem. In the context of Conflux, EVM compatibility allows developers to deploy Ethereum contracts on the Conflux network, benefiting from Conflux's scalability and efficiency while leveraging Ethereum's robust developer tooling and ecosystem.

### **Finalization**
Finalization refers to the process by which transactions and blocks on the Conflux blockchain are considered definitive and irreversible. This process is critical for the network's security, as it prevents the possibility of double-spending attacks and ensures the blockchain's integrity. In the context of Conflux, PoS chain will periodically choose and refer to a PoW block which is created several minutes ago, thus providing finalization to all blocks (transactions) before the epoch of the specified block, ensuring they cannot be altered or removed subsequently.

### **Fork**
A fork in a blockchain system denotes a split or divergence in the chain, originating from a common point with a shared history and creating two distinct paths. They can be implemented intentionally via software updates to either bring about significant changes (hard fork) or introduce backward-compatible alterations (soft fork). However, forks can also occur organically due to simultaneous block creation or as a result of network latencies and block propagation delays.

Additionally, malicious activities aimed at disrupting the network, performing deceptive transactions, or double-spending can also force a fork in the system. These inadvertent forks are typically short-lived as subsequent block addition commonly results in the resolution of temporary branches. No matter the reason for their occurrence, forks are an inherent part of the dynamic and decentralized nature of blockchain technology, necessitating robust consensus mechanisms to manage and mitigate potential issues.
Expand Down Expand Up @@ -144,6 +149,9 @@ Related links:
### **Merkle Tree**
A Merkle tree, in cryptography and computer science, is a tree in which every leaf node is labelled with the hash of a data block, and every non-leaf node is labelled with the cryptographic hash of the labels of its child nodes. Merkle trees are used in blockchains to efficiently verify the contents of large data structures.

### **Mined**
A "mined" block in the Conflux Network refers to a block in which transactions have been validated and added to the blockchain after successfully being processed through mining. This status indicates that the block has passed the network's consensus mechanism, ensuring its transactions are secured and immutable within the blockchain ledger. The term differentiates such blocks from those still awaiting validation.

### **Mining**
Mining is like a competition where people use powerful computers to solve puzzles. Each puzzle solved helps confirm new transactions and safely add them to the blockchain. Think of **miners** as special participants who use advanced equipment, like ASICs or high-performance GPUs, to take part in this puzzle-solving contest. The contest involves lots of trial and error to find a special code (hash value) that fits certain rules. When a miner finds the right code, it's like they win the round, allowing them to add a page (block) of confirmed transactions to the ledger. The first one to do this gets a prize in the form of digital money (cryptocurrency). In the Conflux network, this process helps to build a unique ledger structure known as the Tree-Graph, which organizes transactions in a special way.

Expand All @@ -167,6 +175,9 @@ In the context of blockchains and smart contracts, an oracle is an agent that fi
### **Peer-to-Peer Network (P2P)**
A peer-to-peer network is one in which each computer in the network can act as a client or server for the other computers in the network, allowing shared access to files and peripherals without the need for a central server. Conflux, like other blockchain networks, operates as a peer-to-peer network, with each node communicating directly with others.

### **Pivot Chain**
The pivot chain is a selected sequence of blocks within Conflux's Tree-Graph structure, used to determine the total order of blocks and transactions. It acts as a backbone organizing and finalizing the transaction set, ensuring consistency and finality across the network. The pivot chain is chosen through an algorithm considering various factors, such as the accumulated proof-of-work (PoW), to maintain the system's security and stability.

### **Proof of Stake (PoS)**
Proof of Stake (PoS) is a type of consensus algorithm where block creators are chosen based on the number of tokens they hold or are willing to "stake". PoS is used in the Conflux network to prevent 51% attacks and to finalize blocks.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/general/conflux-basics/wallets.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Choosing a wallet depends on your specific needs. If you're a developer, you mig

The Conflux Network supports several wallets, including but not limited to:

- [Fluent](../tutorials/wallets/fluent.md): A browser extension wallet for Chrome and Firefox, similar to MetaMask but for the Conflux Network. Supports both Core a eSpace.
- [Fluent](../tutorials/wallets/fluent.md): A browser extension wallet for Chrome (most Chromium-based browsers) and Firefox, similar to MetaMask but for the Conflux Network. Supports both Core and eSpace.
- [Ledger](../tutorials/wallets/ledger.md): A hardware wallet known for its security features. Supports both Core a eSpace.
- [MetaMask](../../espace/UserGuide.md): A popular wallet that can also be configured to work with the Conflux Network eSpace.

Expand Down
3 changes: 3 additions & 0 deletions docs/general/tutorials/wallets/wallets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Wallets supported depend on the Space you plan to interact with.
| [Fluent](./fluent) |||
| [Ledger](./ledger) |||
| [MetaMask](../../../espace/UserGuide.md)|||
| [OKX Web3](https://www.okx.com/web3)|||
| [OneKey](https://onekey.so/download)|||


For more information about each wallet, please navigate to the corresponding section.

Expand Down
40 changes: 40 additions & 0 deletions docs/overview/for-dapp-developers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
sidebar_position: 3
title: For dApp Developers
keywords:
- dApp
---

Decentralized Applications, or dApps, represent the next generation of app development, leveraging blockchain's potential to offer a more transparent, secure, and user-centric digital experience. The key differentiation lies in the backend: instead of relying on centralized servers, dApps use blockchain as their backbone. As dApps allow for direct integration with users' wallets, they can facilitate seamless and trustless peer-to-peer interactions.

Each step of the journey to build a dApp offers unique considerations, insights, and challenges. Below are several sections with summarized descriptions to guide developers through a wealth of internal resources available:

## Basics for Conflux Development

|Title|Description|Key Subjects|
|---|---|---|
| **Getting Started on [Core Space](../core/getting-started/installing-a-wallet.md) & [eSpace](../espace/UserGuide.md)** | User guides for Conflux Core Space and Conflux eSpace | Wallet installation, Testnet faucet, User guide |
| **Network endpoints: [Core](../core/core-endpoints.md) & [eSpace](../espace/network-endpoints.md)** | Public network endpoints of Conflux Core Space and Conflux eSpace, enabling you to connect to blockchain via JSON-RPC | Chain id, Network endpoints |
| **SDKs or Tools for [Core Space](/docs/category/sdks-and-tools) & [eSpace](../espace/DeveloperQuickstart.md)** | SDKs and Tools to assist in building web3 applications | SDK, Toolchain, Hardhat |

## Become Acquainted With Smart Contracts

|Title|Description|Key Subjects|
|---|---|---|
| [**Introduction to Smart Contracts**](../general/conflux-basics/contracts.md)| An overview and basic introduction to smart contracts | Concept |
| [**Smart Contracts Development**](/docs/category/smart-contracts) | Basic understanding of how to develop smart contracts, including the smart contracts development workflow, elementary Solidity syntax, and prevalent token standards | Solidity, Token Standard |
|[**How to Deploy Contract on eSpace**](/docs/category/how-to-deploy-contract)|Guidelines on how to utilize build tools (like hardhat, remix) to deploy contracts in **Conflux eSpace** | Hardhat, Remix, Thirdweb |

## Frontend Development

|Title|Description|Key Subjects|
|---|---|---|
| [**Fluent Integration**](../core/build/fluent.md)| Guidance on integrating Fluent wallet into your frontend | Wallet Connection, Fluent wallet |
| [**use-wallet**](/docs/category/smart-contracts)| `use-wallet` is a front-end oriented wallet hooks library designed to provide swift development support for lightweight dapps. `use-wallet` is compatible with conflux chains and ethereum chains, with integration support for the React and Vue3 frameworks. | Wallet Connection, Fluent wallet, MetaMask, React, Vue3 |
|[**Scaffold Conflux**](../espace/tutorials/scaffoldCfx/scaffold.md)| Instructions for Scaffold Conflux, the adaptation of [Scaffold-ETH-2](https://scaffoldeth.io/) template, enabling you to deploy the contract on **Conflux eSpace** and utilize the components, integration of hardhat, and the swift deployment of Scaffold-ETH-2. | Scaffold, Hardhat, Conflux eSpace |

## Tools

|Title|Description|Key Subjects|
|---|---|---|
|[**IPFS Overview**](../general/build/nfts/ipfs.md) &<br/>[**Pinata Tutorial**](../general/build/nfts/pinata.md)|What IPFS is and how to "pin" files to IPFS using Pinata. Valuable for NFT development if you're looking to upload files to IPFS| NFT development, IPFS|
Loading

0 comments on commit 85424c4

Please sign in to comment.