Skip to content

Commit fc9e5c1

Browse files
insider89SaeeDawod
andauthored
feat: add fantom chain documentation (#43)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduces an overview of Fantom, including key features like FTM cryptocurrency and Lachesis consensus mechanism. - Information on different node types within SettleMint for blockchain history maintenance. - Guide on connecting to a blockchain node using various backend APIs. - Dashboard displaying network statistics of the Fantom network. - SettleMint IDE for editing smart contracts with features like OpenAI GPT integration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: SaeeDawod <122533407+SaeeDawod@users.noreply.github.com>
1 parent e50a661 commit fc9e5c1

File tree

9 files changed

+984
-0
lines changed

9 files changed

+984
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# The basics
2+
3+
Fantom is a high-performance, scalable, and secure smart-contract platform launched in December 2019. It is designed to overcome the limitations of older blockchain platforms like Ethereum. Fantom’s native cryptocurrency is called FTM. The platform leverages a unique consensus mechanism known as Lachesis, which allows it to process transactions much faster and at a lower cost compared to traditional blockchains. Fantom is fully compatible with the Ethereum Virtual Machine (EVM), enabling developers to deploy their existing Ethereum dApps on Fantom without any changes. Beyond scalability and compatibility, Fantom emphasizes decentralization. The network is secured by a decentralized network of validators and governed through on-chain governance, ensuring it is not controlled by any single entity.
4+
5+
## Mainnet and Testnet
6+
7+
SettleMint supports, the **Fantom Mainnet** and the **Fantom Testnet**.
8+
9+
The Mainnet is the primary public Fantom production blockchain where real-value transactions occur. Each transaction requires payment of a transaction fee, payable in the native coin FTM. The Testnet, on the other hand, is an instance of the blockchain used for testing and experimentation. The coins used in the Testnet have no real value, mitigating the risk of losing real funds.
10+
11+
You can consider the Testnet as a prototype environment and the Mainnet as the official production blockchain, similar to the analogy of staging versus production servers.
12+
13+
## Consensus mechanism
14+
15+
The Fantom consensus algorithm is known as Lachesis, a unique asynchronous Byzantine Fault Tolerant (aBFT) protocol. Lachesis does not rely on leaders to propose blocks, allowing it to provide high throughput and fast finality. Transactions on the Fantom network are confirmed in about 1-2 seconds.
16+
17+
Lachesis works as follows:
18+
19+
1. **Asynchronous**: Transactions are processed asynchronously, meaning that validators do not need to wait for the previous transaction to be completed before starting a new one.
20+
2. **Byzantine Fault Tolerant**: The protocol can achieve consensus even if up to one-third of the nodes act maliciously.
21+
3. **Finality**: Transactions achieve finality within a few seconds, making them irreversible once confirmed.
22+
23+
The Lachesis consensus algorithm is scalable, secure, and decentralized, providing a robust foundation for decentralized applications.
24+
25+
More information can be found on the [official Fantom website](https://fantom.foundation/).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Node types
2+
3+
All nodes running in SettleMint are configured to be **archive nodes**, meaning they all include all previous states of a given blockchain since its origin.
4+
5+
[Learn here how to interact with your Fantom node.](3_fantom-connect-to-a-node.md)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Connect to a node
2+
3+
For a software application to interact with a blockchain (e.g. by sending transactions/data to the network, or even just by reading data), it must connect to a node. This section describes how to connect to your Fantom node.
4+
5+
## Backend APIs
6+
7+
Once a node has been deployed on an EVM (Ethereum Virtual Machine) compatible network, such as Fantom Mainnet, it can be accessed by different endpoints such as JSON-RPC, JSON-WS or GraphQL. You can connect to your already deployed node using these 3 most common endpoints.
8+
9+
### JSON-RPC
10+
11+
JSON-RPC, is a stateless, light-weight remote procedure call (RPC) protocol. Primarily, the specification defines several data structures and the rules around their processing. By default, the version of the JSON-RPC protocol needs to be 2.0, and you need to provide the node ID as well as a method and parameters.
12+
13+
There are different kinds of methods that can be used: ADMIN methods, DEBUG methods, ETH methods etc.
14+
15+
If you want to correctly connect to your node, you need to respect the right structure for the request, which is always the same:
16+
17+
```json
18+
{
19+
"jsonrpc":"2.0"
20+
"Id": nodeId
21+
"method":"methodName"
22+
"params":{
23+
}
24+
}
25+
```
26+
27+
If you want to connect to a node deployed on the SettleMint platform, go to the **Connect** tab on the **Node detail page** in the **Blockchain nodes** section of your application. Select JSON-RPC or any other endpoint and click **Try it out**. You will then be redirected to a new tab where you will be able to test different methods as well as the related Curl command line.
28+
29+
### JSON-WS
30+
31+
To make RPC requests over WebSockets, you can use wscat, which is by definition a Node.js based command-line tool. First you will need to connect to your node’s WebSocket server using wscat, as follows: `wscat -c ws://<JSON-RPC-ws-endpoint:port>`. All the credentials are provided in the **Connect** tab on the **Node detail page** in the **Blockchain nodes** section of your application. After you have established a connection, the terminal should display a '>' prompt. You will then be able to send individual requests as a JSON data package, as above, for instance:
32+
33+
```json
34+
{
35+
"jsonrpc":"2.0"
36+
"Id": 1
37+
"method":"eth_blockNumber"
38+
"params":{
39+
}
40+
}
41+
```
42+
43+
### GraphQL
44+
45+
GraphQL is a query language and server-side runtime for API’s. It is designed to make APIs fast, flexible, and developer-friendly.
46+
We have a GraphQL interface that can be used with many different queries. These queries can be tested out in our GraphQL playground. You can also test out the different graphql queries with cURL, those request would look like this:
47+
48+
```bash
49+
curl -X POST -H "Content-Type: application/json" -H “x-auth-token: <AUTH_TOKEN>” --data
50+
'{ "query": "{syncing{startingBlock currentBlock highestBlock}}"}' http://<DOMAIN>.settlemint.com/graphql
51+
```
52+
53+
If you want to connect to a node deployed on the SettleMint platform, go to the **Connect** tab on the **Node detail page** in the **Blockchain nodes section** of your application. Select Graphql and click **Try it out**. This will bring you to the GraphQL playground where you can use all the different queries.
54+
55+
## Javascript API
56+
57+
If you do not want to use the above endpoints to connect to your node, it is possible to use plain Javascript. Several convenience libraries exist within the different ecosystem which makes connection much easier. With these libraries, developers around the world can write one-line methods to easily initiate requests (still under the hood) that interact with Ethereum or any other EVM compliant network. Note that some libraries might be available for Ethereum but not for the other networks.
58+
59+
These libraries are very helpful and abstract away much of the complexity of interacting directly with your node. Most also provide useful and straightforward functions such as converting ETH to Gwei, so that you can spend less time dealing with decimal issues and more time on the functionality of your underlying application.
60+
61+
One of the most commonly used libraries, Ethers, is extremely easy to use for signing transactions, sending tokens etc. For example:
62+
63+
```typescript
64+
// If you don't specify a //url//, Ethers connects to the default
65+
// (i.e. ``http:/\/localhost:8545``)
66+
const provider = new ethers.providers.JsonRpcProvider();
67+
68+
// The provider also allows signing transactions to
69+
// send ether and pay to change state within the blockchain.
70+
// For this, we need the account signer...
71+
const signer = provider.getSigner();
72+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Network stats
2+
3+
The dashboard gives you an overview of the following stats for the network:
4+
5+
## Best block
6+
7+
Shows the "heaviest" block in terms of cumulative difficulty. In other words, the latest block number of the longest valid chain.
8+
9+
## Last block
10+
11+
Shows the time, in seconds, since the last block was mined. This value is a good indicator of whether the network is still up and running. A value noticeably above the average time between blocks indicates that the network is no longer mining blocks.
12+
13+
## Average block time
14+
15+
Shows the average time, in seconds, it takes for the network to mine a new block.
16+
17+
## Nodes
18+
19+
Shows the number of nodes in this network.
20+
21+
## Transactions
22+
23+
Shows the number of transactions for the last 10 blocks.
24+
25+
## Gas usage
26+
27+
Shows the amount of gas spent for the last 10 blocks.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Smart contracts IDE
2+
3+
The SettleMint IDE is the only tool you need to edit the smart contract set template you have selected, or **write** your own brand **new** smart contracts. The programming language used for your Fantom smart contracts is Solidity.
4+
5+
## Using the IDE
6+
7+
When you open the IDE, you land in an instance of Visual Studio Code similar to the image below.
8+
9+
![ide](../../../static/img/blockchain-guide/IDE.png)
10+
11+
On the left, in the **“Explorer”** panel, you can see all the folders and files related to the smart contract set.
12+
13+
The smart contract files are located in the **“contracts”** folder. You can edit them, or use them as they are if the template fits all your needs.
14+
15+
The **“deploy”** folder contains the scripts that enable the deployment of the smart contract set on the blockchain. You might have to edit these scripts if you add new arguments to the constructor of your smart contract.
16+
17+
The **“test”** folder contains a script that lets you test the functionalities of your smart contracts. You can add new ones if you edit the template. Do not hesitate to go through the test cases as they provide valuable information on how to use your smart contracts.
18+
19+
The **subgraph** folder holds all the files needed to index your smart contract using the Graph protocol.
20+
21+
## Scripts
22+
23+
Several scripts are defined in `package.json` to help you use the smart contract set:
24+
25+
- **lint** to lint your smart contracts, i.e. find the stylistic errors.
26+
- **compile** to compile your smart contracts.
27+
- **test** to run the test script in the “test” folder.
28+
- **smartcontract:deploy** to deploy the smart contract set on the blockchain.
29+
- **smartcontract:deploy:reset** to deploy from scratch after a first deployment.
30+
- **graph:config** to create the middleware configuration file.
31+
- **graph:compile** to compile the middleware files.
32+
- **graph:codegen** to create the middleware schema.
33+
- **graph:build** to build the middleware.
34+
- **graph:deploy** to deploy the middleware.
35+
- **graph:all** to execute all the graph scripts in one command.
36+
37+
:::warning Note
38+
39+
To execute the scripts related to the Graph middleware, you need a middleware instance in your app.
40+
41+
:::
42+
43+
You can execute these scripts in the terminal integrated with the IDE by running `yarn name-of-script`.
44+
For example, to run the `smartcontract:deploy` task using the terminal, open a new terminal (ctrl + shift + \`) and run the command`yarn smartcontract:deploy`.
45+
46+
## Private key
47+
48+
To be able to deploy your smart contract set on the blockchain you need to have a private key enabled on your node to sign the transaction, and you need to fund this key with Ether to cover the cost for the transaction. You can create a private key and fund it in the **Private keys section** of your application. [More about private keys.](../../using-platform/17_private-keys.md)
49+
50+
## Template library
51+
52+
Every instance of the IDE contains a set of pre-built smart contract templates. These templates are easily customizable to match your specific use case. [Discover the smart contract set templates for Fantom.](../11_Fantom/Template-library/1_fantom-erc-20.md)
53+
54+
## Generative AI plugin
55+
56+
The integration of an OpenAI GPT plugin into the Smart Contract IDE of the SettleMint platform brings forth significant advantages for the fast development of new smart contracts. Generative AI technology empowers developers by providing them with automated code suggestions, smart contract templates, and code completion capabilities. This accelerates the development process by reducing manual effort and improving code efficiency.
57+
58+
Additionally, the interactive debugging and explanation features offered by the GPT plugin greatly benefit developers of all skill levels. Beginners can leverage the plugin’s explanations to understand complex concepts, improve their coding skills, and gain insights into best practices. Experienced developers can utilize the debugging features to quickly identify and resolve issues, leading to more robust and error-free smart contracts.
59+
60+
Overall, the integration of the OpenAI GPT plugin into the SettleMint platform’s Smart Contract IDE combines the power of generative AI and interactive debugging to enhance productivity, code quality, and learning opportunities for developers in the blockchain space.
61+
62+
You can find this plugin in the sidebar (magic lamp icon), in context menu and the action panel. The first time you use the plugin you will get asked for an OpenAI API key. Depending on your OpenAI API access you can use the default GPT 3.5 model or the GPT 4 model which is slower, but more accurate. Check out the settings in the IDE to configure this and other settings (like using your own Azure GPT service)
63+
64+
Here are some prompts to get you started:
65+
66+
- Write a Solidity ERC20 token representing a bond, based on OpenZeppelin. Include a bond repayment and coupon payments.
67+
- Write a Solidity ERC721 token representing real estate, based on OpenZeppelin and allow fractional ownership of this NFT in the form of ERC20 tokens.
68+
- Write The Graph indexing code that indexes an ERC721 token on the Ethereum Mainnet.
69+
70+
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/-e4weLqbYjk" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

0 commit comments

Comments
 (0)