# Task 4

### Install Dependencies

```
sudo apt update -y && sudo apt upgrade -y
sudo apt install -y make bzip2 automake libbz2-dev libssl-dev doxygen graphviz libgmp3-dev \
autotools-dev libicu-dev python2.7 python2.7-dev python3 python3-dev \
autoconf libtool curl zlib1g-dev sudo ruby libusb-1.0-0-dev \
libcurl4-gnutls-dev pkg-config patch llvm-7-dev clang-7 vim-common jq libncurses5 git
```

### Create Contract CRUD

Buat folder

```
mkdir -p $HOME/inrcrud
```

Create

```
sudo tee $HOME/inrcrud/inrcrud.cpp >/dev/null <<EOF
#include <inery/inery.hpp>
#include <inery/print.hpp>
#include <string>

using namespace inery;

using std::string;

class [[inery::contract]] inrcrud : public inery::contract {
  public:
    using inery::contract::contract;


        [[inery::action]] void create( uint64_t id, name user, string data ) {
            records recordstable( _self, id );
            auto existing = recordstable.find( id );
            check( existing == recordstable.end(), "record with that ID already exists" );
            check( data.size() <= 256, "data has more than 256 bytes" );

            recordstable.emplace( _self, [&]( auto& s ) {
               s.id         = id;
               s.owner      = user;
               s.data       = data;
            });

            print( "Hello, ", name{user} );
            print( "Created with data: ", data );
        }

         [[inery::action]] void read( uint64_t id ) {
            records recordstable( _self, id );
            auto existing = recordstable.find( id );
            check( existing != recordstable.end(), "record with that ID does not exist" );
            const auto& st = *existing;
            print("Data: ", st.data);
        }

        [[inery::action]] void update( uint64_t id, string data ) {
            records recordstable( _self, id );
            auto st = recordstable.find( id );
            check( st != recordstable.end(), "record with that ID does not exist" );


            recordstable.modify( st, get_self(), [&]( auto& s ) {
               s.data = data;
            });

            print("Data: ", data);
        }

            [[inery::action]] void destroy( uint64_t id ) {
            records recordstable( _self, id );
            auto existing = recordstable.find( id );
            check( existing != recordstable.end(), "record with that ID does not exist" );
            const auto& st = *existing;

            recordstable.erase( st );

            print("Record Destroyed: ", id);

        }

  private:
    struct [[inery::table]] record {
       uint64_t        id;
       name     owner;
       string          data;
       uint64_t primary_key()const { return id; }
    };

    typedef inery::multi_index<"records"_n, record> records;
 };
EOF

```

Compile

```
cd inrcrud
cd; source .bashrc; cd -
inery-cpp -abigen -o inrcrud.wasm inrcrud.cpp
```

Set Contract

```
cline set contract namaAkun ./
```

{% hint style="info" %}
Unlock wallet dulu jika ke lock
{% endhint %}

```
cline wallet unlock -n namaAkun --password passwordDariFileTXT
```

Jika muncul seperti ini

<figure><img src="https://2662825537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FI3uyPQUnfzoZEU60Wqmq%2Fuploads%2FVyXkM7dwv8plllwRnZy7%2F344_1.png?alt=media&#x26;token=e5146d74-719f-4b61-9eae-ec180bf5ffce" alt=""><figcaption></figcaption></figure>

Edit file `config.ini`&#x20;

```
cd ~/inery-node/inery.setup/master.node/blockchain/config
```

```
nano config.ini
```

Temukan `max-transaction-time` (yang paling bawah) ganti dari 15000 ke 30000

<figure><img src="https://2662825537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FI3uyPQUnfzoZEU60Wqmq%2Fuploads%2FFsiKJbdQ9usprckSu8Pv%2F344.png?alt=media&#x26;token=510a6b66-d960-4281-8068-06cb553ced7a" alt=""><figcaption></figcaption></figure>

SAVE, `CTRL+X` `Y` `Enter`

> Contract siap ,lanjut membuat JSON RPC

### Install Nodejs

```
sudo apt update
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
```

#### Clone Repo

```
cd
git clone https://github.com/alteregogi/ineryjs.git
cd ineryjs
```

#### Install

```
npm install
```

Jika muncul seperti itu ,update menggunakan

```
npm install -g npm@9.2.0
```

<figure><img src="https://2662825537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FI3uyPQUnfzoZEU60Wqmq%2Fuploads%2F3noC5nGoDiBkY1eMSiYt%2F344_3.png?alt=media&#x26;token=ec8b1094-50f9-48f4-bc69-1fa9a317addb" alt=""><figcaption></figcaption></figure>

#### Copy dan Edit file .env

```
cp .env-sample /root/ineryjs/.env
nano .env
```

Isi dengan data mu sesuai di dashboard. `http://you_node_url:8888` ganti dengan `http://IP.VPSMU:8888`\
Save

#### Jalankan

```
npm run rpc-example
```

OKAY!

<figure><img src="https://2662825537-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FI3uyPQUnfzoZEU60Wqmq%2Fuploads%2FgqqTpOx5bCNLjEWAinw7%2F344_4.png?alt=media&#x26;token=2123202c-7bb6-4b7f-9441-1ce28d50f991" alt=""><figcaption></figcaption></figure>

Jika ada error seperti ini;

> cause:  Error: connect ECONNREFUSED IP.VPS:8888

Cara fix nya open port 8888

```
sudo ufw allow 8888; sudo ufw enable
```
