12.1 Inizio


12.1.1 Installing Rust

  • Linux or Mac OS:
    $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    • When shown choose the default settings
    • require git, curl and build-essential:
      # apt install git curl build-essential
      
  • Windows: see the rust official site

12.1.2 Download, compile and Run T.R.I.N.C.I. Node

  • The T.R.I.N.C.I. Node and Rust SDK source code can be found on github: Affidaty Blockchain

  • In order to build T.R.I.N.C.I. we need to install the following dependencies:

    clang libclang-dev protobuf-compiler
    
  • We can download the T.R.I.N.C.I. node repository and then build the node:

    $ git clone https://github.com/affidaty-blockchain/T.R.I.N.C.I.-node.git
    
  • Then we can build the executables.

    To download the needed Rust crates from crates.io

    $ cargo check
    

    To build the executables:

    $ cargo build --release
    

    To run the T.R.I.N.C.I. node:

    $ ./start
    

    This will execute the T.R.I.N.C.I. node using the config.toml configuration file.

12.1.3 Download T.R.I.N.C.I. Smart Contract Development Environment

$ git clone https://github.com/affidaty-blockchain/T.R.I.N.C.I.-smartcontracts.git
  • This crate depends on the T.R.I.N.C.I.-sdk crate.
  • The T.R.I.N.C.I. Rust SDK documentation can be found here.

12.1.3.1 Create a new contract

  • Use the script create_new_contract.sh in the directory /app-rs/:
    $ ./create_new_contract.sh
    
    then insert the new contract name. A project with the name provided will be created.
12.1.3.1.1 Launch the same cargo command for all the contracts:
$ ./cargo_broadcast.sh <COMMAND>

Example used to test all the contracts:

$ ./cargo_broadcast.sh test
12.1.3.1.2 Compile all the contracts with the rust installed on our computer
$ ./build_wasm.sh
  • Note: require rust with target wasm32-unknown-unknown
12.1.3.1.3 Compile all the contracts with a docker image
$ ./build_wasm_docker.sh
  • Note: requires docker installed on the system

12.1.3.2 registry directory

  • The registry directory contains the .wasm contracts

12.1.3.3 integration directory

  • The integration directory is a rust module that provide an environment for testing

12.1.3.4 Register a new smart contract

  • There are many ways to register a smart contract in T.R.I.N.C.I. Blockchain
    • Through a transaction to the Service account with arguments:

      args: {
          "name": string,          // contract name
          "version": string,       // contract version
          "description": string,   // contract description
          "url": string,           // contract web site
          "bin": binary,           // contract binary
      }
      
    • With the T.R.I.N.C.I. CLI:

      $ T.R.I.N.C.I.-cli 
            --host <T.R.I.N.C.I._host> \
            --port <T.R.I.N.C.I._port> \
            --path <T.R.I.N.C.I._path>/api/v1 \
            --network <T.R.I.N.C.I._network>
      
      • Enter in the cheats section:
      Enter 'help' to show available commands
      > cheats
      
      • Launch the register command:
      >>> register
      
      • Fill with the needed information:
        Service account: Qm...xyz                          # the Service account-id
        Service contract (optional multihash hex string):  # just press `enter`
        New contract name: My Cool Contract                # the contract name
        New contract version: 0.2.1                        # the contract version
        New contract description: This is my cool contract 
        New contract url: www.cool-contract.org
        New contract filename: <absolute_path>/my_cool_contract.wasm # contract file in our filesystem
      

12.1.4 Build a contract from scratch

  • In this section will are going to build a smart contract from zero