Skip to content

Latest commit

 

History

History
117 lines (86 loc) · 2.92 KB

Development_and_deployment_of_Smart_Contract(JavaScript_Version).md

File metadata and controls

117 lines (86 loc) · 2.92 KB

1. Using C++ to Write Smart Contracts

Note:
This tutorial is based on the node.js development environment. If you do not have it installed on your computer, please install the node.js environment yourself.

1.1. Initialize the project

Download contracts integrated development framework contract-tool-js, and initialize the project

sudo npm i contract-tool-js -g
contract-tool-js init MyDapp
cd MyDapp

The following project structure can be generated by the appeal initialization step

- config
    - config.js //Store your configuration files
    - keystore.json  // Store your deployment contractor's keystore secret key file
- contract
    - abi.json  // An Abi structure for placing smart contracts
    - contract.js // Store your smart contract codes
- tools  
    - deploy.js  // Store your smart contract deploy codes
- test  
    - test.js  // Store your smart contract testing codes

1.2. Developing for Smart Contract and ABI

The smart contract is developed under the directory of contract

File contract/contract.js: Store the smart contract codes File contract/abi.json: The abi description file that corresponding to smart contract

Bottos currently supports only single-contract files with the following points:

1. Cannot use NPM installed third-party dependencies
2. Only contract file deployment is supported under one account, not multi-contract file deployment

The abi file describes the template as follows.

{
    "to":{"type":"string"},
    "value":{"type":"uint32"},
    "from":{"type":"string"},
    "contract":{
      "type":"object",
      "name":{"type":"string"},
      "sdfkjds":{
        "type":"object",
        "ksjdfl":{"type":"string"}
      }
    }
}

There are several types of all fields

uint8
uint16
uint32
uint64
uint256
string
bin16
object
array

1.3. Deploy the Smart Contract and ABI

After the smart contract and ABI have been developed done, we need to deploy the smart contract and ABI files to the chain.

Note:You can create an account with Bottos's official wallet to get the keystore.

  • Paste the account's keystore entire file contents into file config/keystore json
  • Configure the keystore_pwd from the keystore's account in file config/config.js
  • Run the command to deploy the contract and ABI files
npm run deployContract  // Deploy the smart contract
npm run deployAbi  // Deploy the ABI file

1.4. Testing your Smart Contract

Write the testing codes in file test/test.js and run following command to test that smart contract.

npm test

1.5. Related built-in libraries

Storage

  • Storage.set(table,key,value)
  • Storage.get(contract,table,key)

�Lib

  • Lib.getParams()
  • Lib.getPack(obj:object)
  • Lib.getUnpack(packstr:string)

1.6. Related documentations