Guidelines
- Introduction
- Installation
- Quick Start
Guides
- Introductions
- Build local test node
- Smart Contract - ABI Files
- Smart Contract——JS Contract
- Deploy Contracts
- Test Contract
- Develop DApp Client
Smart Contracts
- Contract Introduction
- ABI File
- Database
- Account Authority
- Call In-contract
- Notification
System Contracts
- Resources
- Account
- Permission
Token Contracts
- Transfer
- Token
- Token Exchange
- Contract Sub-Wallet
Node Guide
- Node Introduction
- Add to nodes network
- Node Data Persistence
Access Guide
- FO 接入安全指南
Deploy Contracts
In the previous article, we have finished the js contract code and ABI file, and initiated the local test node.
Now, we will deploy the contract to the environment and test the contract.
Create an account
Create config.js
under the root directory and save the following code for configuring the basic information.
1 | const config = { |
The release of contract needs to be performed via a fibos account, so initially, we need to create a fibos account and call the method of newaccountSync()
to create the contract account.
Create a new folder named scripts
,and save the code to scripts/deploy.js
:
1 | const FIBOS = require('fibos.js'); |
Compress JS contract
We read the js contract file through the fs module and package the contract with the compileCode()
method.
Save the following code to scripts/deploy.js
:
1 | const jsCode = fs.readTextFile(`${__dirname}/../contracts/todo.js`); |
Upload JS contract
Call the setcodeSync()
method to upload the compressed content to the node.
Save the following code to scripts/deploy.js
:
1 | fibosClient.setcodeSync(config.contract.name, 0, 0, zipCode); |
Get JS contract
Use getCodeSync()
method to read js files,and it is suggested to compare the js files with the provided js contracts from projects and see whether the two are consistent with each other.
Save the following code to scripts/deploy.js
:
1 | const code = fibosClient.getCodeSync(config.contract.name, true); |
Upload ABI file
Obtain the ABI file using the fs module and deploy the ABI file to the node viasetabiSync()
Save the following code to scripts/deploy.js
:
1 | const abi = JSON.parse(fs.readTextFile(`${__dirname}/../contracts/todo.abi`)); |
Deploy contracts
We need to deploy the compiled wasm and ABI files to the node.
Run command
1 | fibos-todomvc$ fibos scripts/deploy.js |
Note: A new window is required to ensure that the node.js is working properly. If an account already exist error is reported, it is suggested to close the node and restart
fibos start_fibos/node.js
.
Output (partial):
1 | code: { |
So far, the contract has been successfully deployed to the node!
The GitHub source code of this article: under scripts
folder of
https://github.com/fengluo/fibos-todomvc
Next Chapter
👉 【Test Contract】