PluginV2 --- Manual Operation ---

# STEPS TO SETUP PLUGIN 2.0 NODE ON LINUX VPS

This is a list of commands I used to set up Plugin 2.0. Right now, inv4fee has created an amazing script that the Plugin team is adopting. This is the original procedure.

I'm also trying to document the job as much as possible. Looking at it now, there may be some changes, but most of it should still be useful.

I hope this helps you all understand how to set up Plugin 2.0.

@11ppm

## 1. Login as root to your new VPS

## 2. Update the system and add in base packages before proceeding by executing below command on the root terminal.

```sh:2
sudo apt update -y && sudo apt upgrade -y && sudo apt install -y git nano curl && sudo apt autoremove -y
```

## 3. Allow permissions on below ports.

```sh:3-1
sudo apt install ufw
```
Port `22` is a common SSH port, but please adjust it according to your specifications.
```sh:3-2
sudo ufw allow 6688/tcp
sudo ufw allow 6689/tcp
sudo ufw allow 22/tcp
# sudo ufw allow YOUR_PORT_NUMBER/tcp
```

```sh:3-3
sudo ufw enable
# If prompted, please enter `y` and press Enter key.
```

## 4. Create a new admin user account

```sh:4-1
sudo groupadd my_new_user
sudo useradd -p $(openssl passwd -6 my_new_password) my_new_user -m -s /bin/bash -g my_new_user -G sudo
```

:::note 
**In this guide, you will set up as follows:**
* Username : Doraemon
* Password : Nobita10Shizuka
```sh:4-2
sudo groupadd Doraemon
sudo useradd -p $(openssl passwd -6 Nobita10Shizuka) Doraemon -m -s /bin/bash -g Doraemon -G sudo
```
:::

## 5. Now open a new terminal session to your VPS and logon with your new admin user account and complete the rest of the steps.

```sh:5
sudo -i -u Doraemon
```

## 6. Install GO 1.20.6 version and set GOROOT, GOPATH and PATH

```sh:6-1
cd ~ && wget https://dl.google.com/go/go1.20.6.linux-amd64.tar.gz
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/e80cedcd-1154-01c3-19ef-34637b987513.png)

```sh:6-2
sudo tar -xvf go1.20.6.linux-amd64.tar.gz
```
```sh:6-3
sudo mv go /usr/local
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
go version
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/01a6205c-87c2-4a00-4f67-f3d0177c1c1b.png)


## 7. Install NVM(node version manager) and Node 16.14.0

```sh:7-1
cd ~ && curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/a7712309-8532-dcf9-6932-63c07ffb69b6.png)

```sh:7-2
nvm install 16.14.0
nvm use 16.14.0
node --version
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/c6c29835-5600-6810-49d0-b90b6bf453d8.png)



## 8. Install [Postgres (> 11.x and <=15.x)]

```sh:8-1
cd ~ && sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
```

```sh:8-2
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/b74f4d30-e2ea-2622-9bad-08080609562e.png)

```sh:8-3
sudo apt install postgresql postgresql-client -y
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/f73f7680-69f1-41da-f224-59efe872e3eb.png)

```sh:8-4
sudo systemctl status postgresql
psql --version
```
Status should be active
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/21557127-3556-3906-7f28-8e965ba50515.png)


## 9. Create Data Base for plugin_mainnet_db in Postgres and set password

:::note warn
**Note: Restriction for Database Password**
      - Must be at least 16 characters long
      - Must not comprise: Leading or trailing whitespace / user's API email.

**The Plugin node requires three passwords, but with the script used in Plugin 1.0, you can freely generate them. Please save the generated passwords in a memo.**
```sh:9-1
cd ~ && wget -O gen_passwd.sh https://raw.githubusercontent.com/11ppm/plugin-deployment/main/gen_passwd.sh
chmod +x gen_passwd.sh 
```

### Method A
```sh:9-2
./gen_passwd.sh
./gen_passwd.sh -keys
./gen_passwd.sh -db
./gen_passwd.sh -api
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/12af9adf-f368-1086-c6c3-ff7a8664552a.png)
* `./gen_passwd.sh -keys`
=> 0iP5So8lGt3eJM:K=unsix2;58*.gT32
* `./gen_passwd.sh -db`
=> cmGip2lu5imYLIlcOUeEUakZe1Qysf
* `./gen_passwd.sh -api`
=> fvSNoxI2c1Z1znx3lt

```sh:9-3
echo $(tr -cd A-Za-z < /dev/urandom | fold -w10 | head -n1)@plinode.local
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/caf315ca-070b-9eec-960e-89cfa727091e.png)
* `echo $(tr -cd A-Za-z < /dev/urandom | fold -w10 | head -n1)@plinode.local`
=> uGxLfwxBfC@plinode.local

---
### Method B
**Alternatively, after executing the command `9-1`, please copy and paste the following command into the terminal and execute it. This will randomly create the necessary password and other requirements for setting up the node.**
```sh:9-4
#!/bin/bash 

# Set Colour Vars
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Important Infomation
IP_ADDRESS=$(ip addr show | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v '127.0.0.1' | head -n1)
NEW_KEYSTORE="$(./gen_passwd.sh -keys)"
NEW_DB_PWD="$(./gen_passwd.sh -db)"
_AUTOGEN_API_USER=$(tr -cd A-Za-z < /dev/urandom | fold -w10 | head -n1)
NEW_API_EMAIL="$_AUTOGEN_API_USER@plinode.local"
NEW_API_PWD="$(./gen_passwd.sh -api)"

 # Print
    echo \ &&
    echo -e "${GREEN}#########################################################################${NC}" \ &&
    echo \ &&
    echo -e "${RED}##  IMPORTANT INFORMATION - PLEASE RECORD TO YOUR PASSWORD SAFE${NC}" \ &&
    echo \ &&
    echo -e "${GREEN}#########################################################################${NC}" \ &&
    echo \ &&
    echo -e "${RED}##  KEY STORE SECRET:        $NEW_KEYSTORE${NC}" \ &&
    echo \ &&
    echo -e "${RED}##  POSTGRES DB PASSWORD:    $NEW_DB_PWD${NC}" \ &&
    echo \ &&
    echo -e "${RED}##  API USERNAME:    $NEW_API_EMAIL${NC}" \ &&
    echo -e "${RED}##  API PASSWORD:    $NEW_API_PWD${NC}" \ &&
    echo \ &&
    echo -e "${GREEN}#########################################################################${NC}" \ &&
    echo \ &&
    echo -e "${GREEN}Your Plugin node GUI IP address is as follows:${NC}" \ &&
    echo \ &&
    echo -e "            ${RED}http://$IP_ADDRESS:6688${NC}" \ &&
    echo \ &&
    echo -e "${GREEN}#########################################################################${NC}"
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/bd29b6bd-5d45-ffd2-d677-69834b59986a.png)

:::

```sh:9-5
sudo systemctl start postgresql.service
```

this will login to Postgres
```sh:9-6
sudo -i -u postgres psql
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/36612a3a-60f2-a8b2-df44-98669f4d745a.png)

```sql:9-7
CREATE DATABASE plugin_mainnet_db;
```


:::note
```sql:9-8
ALTER USER postgres WITH PASSWORD 'new_password';
```
It is recommended to use the password outputted by the command `./gen_passwd.sh -db` for `9-1`. 

In this demo, I have created the following password:

* `./gen_passwd.sh -db`
cmGip2lu5imYLIlcOUeEUakZe1Qysf


```sql:9-9
ALTER USER postgres WITH PASSWORD 'cmGip2lu5imYLIlcOUeEUakZe1Qysf';
```
Please keep a note of this password as it will be used for the command `13-3`.
:::

Command to exit Postgres
```sql:9-10
\q
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/bf0d336a-6be7-f006-ce12-6d488e7a8238.png)


## 10. Ensure you have python3
    
```sh:10
python3 --version
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/c0a755be-ae17-d7ca-61e5-4d26369e27c6.png)


## 11. Download Plugin 2.0 codebase
    
```sh:11-1
cd ~ && git clone https://github.com/GoPlugin/pluginV2.git && cd pluginV2
```

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/f7af5a7d-f5a1-c0d6-a673-aab0fa094884.png)

```sh:11-2
ls -la
# ll
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/58686de5-68f2-b153-4ac9-5fd433499151.png)

## 12. Install pnpm
    
```sh:12
npm install -g pnpm
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/b7d50d30-8508-c0cb-53f1-77adfd94ddef.png)

## 13. Setup Environment:

### apicredentials.txt
- Modify `apicredentials.txt` file with a valid email id and complex password

    ```sh:13-1
    nano apicredentials.txt
    ```
    ![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/5569f5df-dbe8-4bc8-4032-3dd307411cf6.png)
    **↓**
    ![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/ca9dbbda-c425-bc75-b9fe-7808fa497d2a.png)
    
    :::note info
    To save the changes made to the file in `nano`, follow these steps:
    
    1. Press the `"Ctrl"` and `"X"` keys on your keyboard at the same time.
    2. Press the `"Y"` key on your keyboard to confirm that you want to save the changes.
    3. Press the `"Enter"` key on your keyboard to exit the editor.
    
    These steps will save the changes you made to the file and exit the nano editor.
    :::

### config.toml
- Modify `config.toml` with appropriate RPC, WSS, and ChainID
    ```sh:13-2
    nano config.toml
    ```
    * Mainnet
        ```toml:Mainnet
        RPC : https://erpc.xinfin.network
        WSS : wss://ws.xinfin.network
        PluginContractAddress : 0xFf7412Ea7C8445C46a8254dFB557Ac1E48094391
        Chain ID : 50
        ```

        **https://chainlist.org/chain/50**


    * Apothem
        ```toml:Apothem
        RPC : https://erpc.apothem.network
        WSS : wss://ws.apothem.network/ws
        PluginContractAddress : 0x33f4212b027E22aF7e6BA21Fc572843C0D701CD1
        Chain ID : 51
        ```
        **https://chainlist.org/chain/51**
:::note
### Preliminary RPC
```:Mainnet  Websocket
wss://ws.xinfin.network
```

**Compeleted** : The following four RPCs can respond to requests with "Oracle request received" and complete within the limits of OCA's four seats.
```http:Mainnet RPC
https://xdcpayrpc.blocksscan.io/
https://rpc-xdc.icecreamswap.com/
https://erpc.xdcrpc.com/
https://earpc.xinfin.network/
```

**ERROR** : The following five RPCs display the same error as the image.
```http:Mainnet RPC - ERROR -
https://xdcfnode1.goplugin.co/
https://rpc.xinfin.network/
https://rpc.xdcrpc.com/
https://rpc1.xinfin.network/
http://my_fullnode_ip:8989/
```
:::

Apothem(default)
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/2de5fbb3-1308-1573-22df-0ab6755c5120.png)


### secrets.toml
- Modify secrets.toml with appropriate Keystore and Database URL
    ```sh:13-3
    nano secrets.toml
    ```
    ```TOML:secrets.toml (Sample)
    [Password]
    Keystore = 'uXgNT04ZvGLBe%CoZFn8R%NJ!'
    [Database]
    URL = 'postgresql://postgres:NIMh8ePEg58881F88DCw2wnsN0zX82@127.0.0.1:5432/plugin_mainnet_db?sslmode=disable'
    ```

:::note warn
**Note: This password uses the password used in the command `9-5`. Restriction for Database Password**
      - Must be at least 16 characters long
      - Must not comprise: Leading or trailing whitespace / user's API email
:::

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/8ce7b622-fe4a-b194-0b85-26e5f52b27fd.png)



## 14. Install and build all plugin dependencies

```sh:14-1
cd ~/pluginV2/ && sudo apt install build-essential
# y
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/39438d67-a13b-c8d7-1ca8-953cb2d2b885.png)

```sh:14-2
make install
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/8d965441-1048-817a-7820-f67bcdfcebb4.png)
**↓**
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/fbe3430f-97ea-2c26-cd7d-ac2e332e7df8.png)
**↓**
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/2c2530a3-6971-5d76-6ca1-5cfd988ffd97.png)



## 15. Setup the profile

Modify the .profile file in $Home directory of the admin account with below content and run the command “source ~/.profile”

```sh:15-1
nano ~/.profile
```

```sh:15-2
GOROOT=/usr/local/go
GOPATH=$HOME/go
PATH=$GOPATH/bin:$GOROOT/bin:$PATH
SECURE_COOKIES=false
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/8df29e7f-6c4a-c9ec-5e1f-6ec1ba376501.png)

```sh:15-3
source ~/.profile
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/5528a1b9-954d-a682-8ebc-6bb7f9e711e5.png)


## 16. Start the plugin node

```sh:16-1
plugin --admin-credentials-file apicredentials.txt -c config.toml -s secrets.toml node start
```
Please provide a valid `email` and `password` from `apicredentials.txt` which will be used to login to `http://localhost:6688`
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/e6116d36-e83c-2f75-5d58-ffdc3c1a1376.png)

:::note
To run a node in the background, you can add `&` at the end of the command. However, **I recommend installing `pm2` for this purpose. Please follow the steps below.**

To stop the flowing logs, press `Control + C`. This will pause the logs and at the same time, you won't be able to access the dashboard.

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/4bd7ae67-8708-c5d1-920c-a6403a57aa24.png)


```sh:16-2
cd ~/pluginV2/ && npm install pm2 -g
```

The command `npm install pm2 -g` installs the pm2 package globally. Global installation is done to make pm2 available throughout the system.
Therefore, you can use the pm2 command from any directory. Even if you run it in the home directory and then move to another directory, pm2 will still be available.
<details><summary>【日本語】</summary>

<!--(上に空行が必要)-->
`npm install pm2 -g`コマンドは、グローバルにpm2パッケージをインストールします。グローバルインストールは、システム全体でpm2を使用できるようにするために行われます。

したがって、どのディレクトリにいてもpm2コマンドを使用することができます。ホームディレクトリで実行した場合でも、他のディレクトリに移動しても、pm2は利用可能です。

</details>

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/b2b7d94f-318e-bb90-94c7-eb989e8ee89c.png)


```sh:16-3
cat > NodeStartPM2.sh
# Of course, you can also use `nano`.
```

Copy and paste the following script, and close it with `Control + D`.

```sh:16-4
echo "<<<<<<<<<------------------STARTING PLUGIN NODE--------------------->>>>>>>>>"
plugin --admin-credentials-file apicredentials.txt -c config.toml -s secrets.toml node start
echo "<<<<<<<<<<<-------------------Plugin node is running .. use "pm2 status" to check the status-------->>>>>>>>>>>"
# Press enter on the next line and close the terminal by pressing Control + D
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/876abc6d-ff68-4be8-f0a8-12d33af1047a.png)
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/a79c142e-dbe9-9e40-aa9e-d1d233dadd21.png)

```sh:16-5
ls -la
# ll
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/85a1c496-d554-cb30-1195-dec619852041.png)

### Start Plugin Node

```sh:16-6
pm2 start NodeStartPM2.sh
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/c918de9d-cd63-9579-35d0-39c956d31e1f.png)


### pm2 startup

If the server is restarted as it is, the pm2 process will not start automatically. To start it automatically even if the server is restarted, please execute the following command:

```sh:16-7
pm2 startup
```

Then, you will see the following message:

**[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:**

Copy and paste the command in the yellow box as instructed and press enter.

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/1de5ea63-837a-ca8c-e983-bf9efb6ca10f.png)

Finally, make sure that the following screen is displayed. 

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/d8e924dd-3aa8-0afc-57ff-0244580e6129.png)

Then, it is recommended to execute the following command before actually restarting the server:


```sh:16-8
pm2 save
```

```sh:16-9
sudo reboot
```

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/1f3d1bd9-0805-9c13-62cf-982a6fee1031.png)

After restarting the server, please log in again and execute the following command:

```sh:16-9
pm2 ls
```

Make sure that `NodeStartPM2` is running.

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/473ad588-7d00-6b56-fbfc-3d53fb23f10c.png)
:::

### Log in to the dashboard

provide a valid email and password from `apicredentials.txt` which will be used to login to `http://localhost:6688`.

```sh:16-7
cat apicredentials.txt 
echo http://$(hostname -i):6688
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/22126360-5aea-d91e-9084-e6413af3c82c.png)
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/eeaedfc5-faf4-f028-9e6a-9b6f64b80538.png)
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/1e1c987c-d96b-d849-0f05-066881c48863.png)

### Deposit XDC and PLI to Node Address.



![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/5c69f90f-e819-7165-81f8-9fdc6b85b043.png)

1. Click on the gear icon located in the top right corner of the dashboard.
2. Click on 'Key Management'.
3. Scroll down to the bottom of the screen and locate the 'Address' under 'EVM Chain Accounts'. This will be your 'Node Address'.
4. Send 1XDC and 1PLI to this Node Address.
5. Verify that the balances of XDC and PLI have increased.

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/7a3894fb-172c-cf1a-28e2-af5b7d8468de.png)



# Setup of Job and Deployment of Contract

## 17. Oracle Contract
Using Remix, create an Oracle contract.

```javascript:17-1
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;
import "@goplugin/test/src/v0.7/Operator.sol";
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/ceecdddf-7116-2019-d5de-597072c0c17d.png)

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/49dc8506-9ab5-700a-48a1-fcc11dba4324.png)

Please enter the contract address of PLI (either on the mainnet or Apothem) and your Wallet Address (replace "xdc" at the beginning with "0x").

Your Wallet Address will be the owner of this contract.

* Mainnet PLI Contract : 
    ```:Mainnet PLI Contract
    0xFf7412Ea7C8445C46a8254dFB557Ac1E48094391
    ```
* Apothem PLI Contract : 
    ```:Apothem PLI Contract
    0x33f4212b027E22aF7e6BA21Fc572843C0D701CD1
    ```

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/176aea01-a791-b6cf-dd6c-c3377a2d3894.png)
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/490580d7-53ae-939c-7b0d-43b536871b39.png)





:::note

```:Mainnet PLI Contract
0xFf7412Ea7C8445C46a8254dFB557Ac1E48094391
```

```:Apothem PLI Contract
0x33f4212b027E22aF7e6BA21Fc572843C0D701CD1
```
:::

## 18. Job setup
```toml
type = "directrequest"
schemaVersion = 1
name = "Cryptocompare_XDC-USD"
# It is recommended to give a memorable name to 'name'. You can use it for searching later.
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
# Please replace contractAddress with your oracle address.
minContractPaymentLinkJuels = "0"
observationSource = """
 
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"] 

decode_cbor [type="cborparse" data="$(decode_log.data)"] 

fetch [type=http method=GET url="https://min-api.cryptocompare.com/data/price?fsym=XDC&tsyms=USD" allowUnrestrictedNetworkAccess="true"]

parse [type="jsonparse" path="USD" data="$(fetch)"] 

multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"] 

encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"] 

encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)" 
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ] 

submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"]

decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx 
"""
# Please paste your oracle address in the 'to' field on the second line from the bottom.
```

:::note
JOB SETUP
1. The value of the name key should be changed.
2. The Oracle Address will be changed in two locations.
3. The URL will be modified.
Regarding CMC, the APIKEY will be updated.
4. The path will be modified.


#### # Cryptocompare
* https://min-api.cryptocompare.com/data/price?fsym=XDC&tsyms=USD
* path="USD"

<details><summary>Sample Job Code - Cryptocompare -</summary>

<!--(上に空行が必要)-->
```toml:Sample Job Code - Cryptocompare -
type = "directrequest"
schemaVersion = 1
name = "Sample Request Cryptocompare_XDC_USD"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
minContractPaymentLinkJuels = "0"
observationSource = """
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"]
 
decode_cbor [type="cborparse" data="$(decode_log.data)"]
 
fetch [type="http" method=GET url="https://min-api.cryptocompare.com/data/price?fsym=XDC&tsyms=USD"]
parse [type="jsonparse" path="USD" data="$(fetch)"]
 
multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"]
 
encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"]
 
encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ]
 
submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"] //paste the Oracle Address which you deployed in ‘to’ field
 
decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx
"""
```
</details>

#### # Coingecko
* https://api.coingecko.com/api/v3/simple/price?ids=plugin&vs_currencies=usd
* path="plugin,usd"

<details><summary>Sample Job Code - Coingecko -</summary>

<!--(上に空行が必要)-->
```toml:Sample Job Code - Coingecko -
type = "directrequest"
schemaVersion = 1
name = "Sample Request CoinGecko_PLI_USD"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
minContractPaymentLinkJuels = "0"
observationSource = """
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"]
 
decode_cbor [type="cborparse" data="$(decode_log.data)"]
 
fetch [type="http" method=GET url="https://api.coingecko.com/api/v3/simple/price?include_last_updated_at=true&precision=10&ids=plugin&vs_currencies=usd"]
parse [type="jsonparse" path="plugin,usd" data="$(fetch)"]
 
multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"]
 
encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"]
 
encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ]
 
submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"] //paste the Oracle Address which you deployed in ‘to’ field
 
decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx
"""
```
</details>

#### # Binance
* https://api1.binance.com/api/v3/ticker/price?symbol=XRPUSDT
* path="price"

#### # Bitrue
* https://openapi.bitrue.com/api/v1/ticker/price?symbol=XDCUSDT
* path="price"

<details><summary>Sample Job Code - Bitrue -</summary>

<!--(上に空行が必要)-->
```toml:Sample Job Code - Bitrue -
type = "directrequest"
schemaVersion = 1
name = "Sample Request Bitrue_XDC_USDT"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
minContractPaymentLinkJuels = "0"
observationSource = """
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"]
 
decode_cbor [type="cborparse" data="$(decode_log.data)"]
 
fetch [type="http" method=GET url="https://openapi.bitrue.com/api/v1/ticker/price?symbol=XDCUSDT"]
parse [type="jsonparse" path="price" data="$(fetch)"]
 
multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"]
 
encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"]
 
encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ]
 
submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"] //paste the Oracle Address which you deployed in ‘to’ field
 
decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx
"""
```
</details>

#### # Kucoin
* https://api.kucoin.com/api/v1/market/orderbook/level1?symbol=XDC-USDT
* path="data,price"

<details><summary>Sample Job Code - Kucoin -</summary>

<!--(上に空行が必要)-->
```toml:Sample Job Code - Kucoin -
type = "directrequest"
schemaVersion = 1
name = "Sample Request Kucoin_XDC_USDT"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
minContractPaymentLinkJuels = "0"
observationSource = """
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"]
 
decode_cbor [type="cborparse" data="$(decode_log.data)"]
 
fetch [type="http" method=GET url="https://api.kucoin.com/api/v1/market/orderbook/level1?symbol=XDC-USDT"]
parse [type="jsonparse" path="data,price" data="$(fetch)"]
 
multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"]
 
encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"]
 
encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ]
 
submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"] //paste the Oracle Address which you deployed in ‘to’ field
 
decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx
"""
```
</details>

#### # CMC
* Please change YOUR_API_KEY to your own API.

```TOML
fetch [type=http method=GET url="https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?symbol=XDC&convert=USDT" allowUnrestrictedNetworkAccess="true" headers="[\\"X-CMC_PRO_API_KEY\\", \\"YOUR_API_KEY\\"]"]
```
* parse [type="jsonparse" path="data,XDC,0,quote,USDT,price" data="$(fetch)"]

#### # Coinranking
- **[Website](https://coinranking.com/)**
- **[API Document](https://developers.coinranking.com/api/documentation)**
- Please change YOUR_API_KEY to your own API.

```toml
fetch [type=http method=GET url="https://api.coinranking.com/v2/coin/77jGXSqWJ1ofG?referenceCurrencyUuid=yhjMzLPhuIDl" allowUnrestrictedNetworkAccess="true" headers="[\\"x-access-token\\", \\"YOUR_API_KEY\\"]"]
```

- path="data,coin,price"
 
<details><summary>Sample Job Code - coinranking -</summary>

<!--(上に空行が必要)-->
```toml:coinranking Sample
type = "directrequest"
schemaVersion = 1
name = "Coinranking_XDC-USD"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
minContractPaymentLinkJuels = "0"
observationSource = """
 
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"] 

decode_cbor [type="cborparse" data="$(decode_log.data)"] 

fetch [type=http method=GET url="https://api.coinranking.com/v2/coin/77jGXSqWJ1ofG?referenceCurrencyUuid=yhjMzLPhuIDl" allowUnrestrictedNetworkAccess="true" headers="[\\"x-access-token\\", \\"YOUR_API_KEY\\"]"]

parse [type="jsonparse" path="data,coin,price" data="$(fetch)"] 

multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"] 

encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"] 

encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)" 
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ] 

submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"]

decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx 
"""
```
</details>


#### # Coinpaprika
- **[Website](https://coinpaprika.com/)**
- **[API Document](https://api.coinpaprika.com/)**
- The free version does not require an API key, but please note that **the paid version requires an API key and the base URL may also change**.
- Please change YOUR_API_KEY to your own API.
    | Plan   | Base URL                           |
    |--------|------------------------------------|
    | Free   | https://api.coinpaprika.com/v1/     |
    | Starter| https://api-pro.coinpaprika.com/v1/ |
- path="quotes,USD,price"

```toml :Coinpaprika - Free
fetch [type=http method=GET url="https://api.coinpaprika.com/v1/tickers/cgo-comtech-gold?quotes=USD" allowUnrestrictedNetworkAccess="true"]
```
```toml :Coinpaprika - Paid
fetch [type=http method=GET url="https://api-pro.coinpaprika.com/v1/tickers/cgo-comtech-gold?quotes=USD" allowUnrestrictedNetworkAccess="true" headers="[\\"Authorization\\", \\"YOUR_API_KEY\\"]"]
```
 
<details><summary>Sample Job Code - Coinpaprika -</summary>

<!--(上に空行が必要)-->
```toml:Coinpaprika Sample
type = "directrequest"
schemaVersion = 1
name = "Coinpaprika_CGO-USD"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
minContractPaymentLinkJuels = "0"
observationSource = """
 
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"] 

decode_cbor [type="cborparse" data="$(decode_log.data)"] 

fetch [type=http method=GET url="https://api.coinpaprika.com/v1/tickers/cgo-comtech-gold?quotes=USD" allowUnrestrictedNetworkAccess="true" headers="[\\"Authorization\\", \\"YOUR_API_KEY\\"]"]
parse [type="jsonparse" path="quotes,USD,price" data="$(fetch)"] 

multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"] 

encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"] 

encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)" 
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ] 

submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"]

decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx 
"""
```
</details>

#### # Tradermade
- **[Website](https://marketdata.tradermade.com/)**
- **[API Document](https://marketdata.tradermade.com/docs/restful-api)**
- Please change YOUR_API_KEY to your own API.
- path="quotes,0,mid"

```toml :Tradermade
fetch [type=http method=GET url="https://marketdata.tradermade.com/api/v1/live?api_key=YOUR_API_KEY&currency=USDJPY" allowUnrestrictedNetworkAccess="true"]
```
 
<details><summary>Sample Job Code - Tradermade -</summary>

<!--(上に空行が必要)-->
```toml:Tradermade Sample
type = "directrequest"
schemaVersion = 1
name = "Tradermade_USD-JPY"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
minContractPaymentLinkJuels = "0"
observationSource = """
 
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"] 

decode_cbor [type="cborparse" data="$(decode_log.data)"] 

fetch [type=http method=GET url="https://marketdata.tradermade.com/api/v1/live?api_key=YOUR_API_KEY&currency=USDJPY" allowUnrestrictedNetworkAccess="true"]
parse [type="jsonparse" path="quotes,0,mid" data="$(fetch)"] 

multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"] 

encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"] 

encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)" 
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ] 

submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"]

decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx 
"""
```
</details>

#### # Bitfinex
- **[Website](https://www.bitfinex.com/)**
- **[API Document](https://docs.bitfinex.com/docs)**
- path="6"

```toml :Bitfinex
fetch [type=http method=GET url="https://api-pub.bitfinex.com/v2/ticker/tXDCUSD" allowUnrestrictedNetworkAccess="true"]
parse [type="jsonparse" path="6" data="$(fetch)"] 
```

<details><summary>Sample Job Code - Bitfinex -</summary>

<!--(上に空行が必要)-->
```toml:Bitfinex Sample
type = "directrequest"
schemaVersion = 1
name = "Bitfirex_XDC-USD"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
minContractPaymentLinkJuels = "0"
observationSource = """
 
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"] 

decode_cbor [type="cborparse" data="$(decode_log.data)"] 

fetch [type=http method=GET url="https://api-pub.bitfinex.com/v2/ticker/tXDCUSD" allowUnrestrictedNetworkAccess="true"]
parse [type="jsonparse" path="6" data="$(fetch)"] 

multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"] 

encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"] 

encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)" 
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ] 

submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"]

decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx 
```
</details>


#### # BitMart

- **[Website](https://www.bitmart.com/)**
- **[API Document](https://developer-pro.bitmart.com/en/spot/#get-ticker-of-a-trading-pair-v3)**
- path="data,last"

```toml :Bitfinex
fetch [type="http" method=GET url="https://api-cloud.bitmart.com/spot/quotation/v3/ticker?symbol=PLI_USDT"]
parse [type="jsonparse" path="data,last" data="$(fetch)"]
```

<details><summary>Sample Job Code - BitMart -</summary>

<!--(上に空行が必要)-->
```toml:Sample Job Code - BitMart -
type = "directrequest"
schemaVersion = 1
name = "Sample Request BitMart_PLI_USDT"
forwardingAllowed = false
maxTaskDuration = "0s"
contractAddress = "YOUR_ORACLE_ADDRESS"
minContractPaymentLinkJuels = "0"
observationSource = """
decode_log [type="ethabidecodelog" abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)" data="$(jobRun.logData)" topics="$(jobRun.logTopics)"]
 
decode_cbor [type="cborparse" data="$(decode_log.data)"]
 
fetch [type="http" method=GET url="https://api-cloud.bitmart.com/spot/quotation/v3/ticker?symbol=PLI_USDT"]
parse [type="jsonparse" path="data,last" data="$(fetch)"]
 
multiply [type="multiply" input="$(parse)" times="$(decode_cbor.times)"]
 
encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 value)" data="{ \\"requestId\\": $(decode_log.requestId), \\"value\\": $(multiply) }"]
 
encode_tx [type="ethabiencode" abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}" ]
 
submit_tx [type="ethtx" to="YOUR_ORACLE_ADDRESS" data="$(encode_tx)"] //paste the Oracle Address which you deployed in ‘to’ field
 
decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx
"""
```
</details>


:::





Bitrue
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/7aebb042-51fe-d4ef-5dcd-0c9c251b548c.png)

Cryptocomapre
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/7b373ee8-cb39-8ad0-ff0c-3752071f3b31.png)




JOBIDを取得し、ハイフン`-`を取り除きます。


## 19. CONSUMER CONTRACT

:::note
Please feel free to make any necessary modifications to the following:

* Mainnet or Apothem
    * Mainnet - 0xFf7412Ea7C8445C46a8254dFB557Ac1E48094391
    * Apothem - 0x33f4212b027E22aF7e6BA21Fc572843C0D701CD1
* Oracle Address
    * Please change the leading 'xdc' to '0x'.
* JOBID
    * Please remove the hyphen `-`.
* API(peer)
    * Please make the URL the same as when creating the JOB.

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/d10d92cd-3de6-4169-a1c5-291f8693a411.png)

:::

:::note warn
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/80981084-9ae1-f4f4-c5d6-be5b7136147a.png)

:::



```javascript:CryptocompareAPI
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@goplugin/test/src/v0.8/PluginClient.sol";
import "@goplugin/test/src/v0.8/ConfirmedOwner.sol";

/**
* THIS IS AN EXAMPLE CONTRACT WHICH USES HARDCODED VALUES FOR CLARITY.
* THIS EXAMPLE USES UN-AUDITED CODE.
* DO NOT USE THIS CODE IN PRODUCTION.
*/

contract APIConsumer is PluginClient, ConfirmedOwner {
using Plugin for Plugin.Request;

uint256 public volume;
bytes32 private jobId;
uint256 private fee;

event RequestVolume(bytes32 indexed requestId, uint256 volume);

/**
* @notice Initialize the pli token and target oracle
*
* Details:
* A. Pli Token: 0x33f4212b027E22aF7e6BA21Fc572843C0D701CD1
* B. Oracle: 0x6090149792dAAeE9D1D568c9f9a6F6B46AA29eFD (Plugin DevRel)
* C. jobId: ca98366cc7314957b8c012c72f05aeeb
*
*/

constructor() ConfirmedOwner(msg.sender) {
setPluginToken(0x33f4212b027E22aF7e6BA21Fc572843C0D701CD1);//Pli address as mentioned in ‘A’
setPluginOracle(0x06b321e3da4a5c67fBF074bb48C6408074bDD785);//Oracle address
jobId = "53034a3f099949f787937a96fa3e9a32";//Job ID as stored in ‘C’ JOB SUBMISSION
fee = (0.001 * 1000000000000000000) / 10;
}

/**
* Create a Plugin request to retrieve API response, find the target
* data, then multiply by 1000000000000000000 (to remove decimal places from data).
*/

function requestVolumeData() public returns (bytes32 requestId) {
Plugin.Request memory req = buildPluginRequest(
jobId,
address(this),
this.fulfill.selector
);

// Set the URL to perform the GET request on
// req.add(
// "get",
// "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD"
// );

req.add(
"get",
"https://min-api.cryptocompare.com/data/price?fsym=XDC&tsyms=USD"
);

// Set the path to find the desired data in the API response, where the response format is:
// {"RAW":
// {"ETH":
// {"USD":
// {
// "VOLUME24HOUR": xxx.xxx,
// }
// }
// }
// }
// request.add("path", "RAW.ETH.USD.VOLUME24HOUR"); // Plugin nodes prior to 1.0.0 support this format
//req.add("path", "RAW.ETH.USD.VOLUME24HOUR"); // Plugin nodes 1.0.0 and later support this format
//req.add("path", "USD"); // Plugin nodes 1.0.0 and later support this format
//req.add("path", "Result,data,result"); // Plugin nodes 1.0.0 and later support this format

// Multiply the result by 1000000000000000000 to remove decimals
int256 timesAmount = 10 ** 18;
req.addInt("times", timesAmount);

// Sends the request
return sendPluginRequest(req, fee);
}

/**
* Receive the response in the form of uint256
*/

function fulfill(
bytes32 _requestId,
uint256 _volume
) public recordPluginFulfillment(_requestId) {
emit RequestVolume(_requestId, _volume);
volume = _volume;
}


/**
* Allow withdraw of Link tokens from the contract
*/

function withdrawPli() public onlyOwner {
PliTokenInterface pli = PliTokenInterface(PluginTokenAddress());
require(
pli.transfer(msg.sender, pli.balanceOf(address(this))),
"Unable to transfer"
);
}
}
```

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/e58666a1-ba3e-0622-211a-eeab09316dac.png)

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/6a3c0a49-c013-b316-795e-109196550e42.png)

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/5d228625-5009-c58e-a146-cec48c0c4521.png)

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/58b73154-462c-4248-dbad-d8c4a7068ab4.png)

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/c6e672af-211b-51ec-42c2-9f348b25a8c1.png)

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/0da4bdbf-e316-084a-e974-4e5ffae7faa7.png)






# Git Command

The following command is commonly used when using Git for version control.

### git fetch
```sh
git fetch
```
- `git fetch`: Retrieves the latest changes from the remote repository, but does not apply them to the local branch. The fetched changes can be used later for merging or checking out.

### git log --oneline origin/main
```sh
git log --oneline origin/main
```
- `git log --oneline origin/main`: Displays the commit history of the `origin/main` branch in a one-line format. The `--oneline` option shows the commit messages in a concise form.
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/d251237c-e18f-6497-2981-a97796caa953.png)

    In the given output of the `git log --oneline origin/main` command, there are two mentions of "HEAD". 
    
    - `b7a5ee2 (HEAD -> main) contracts updated`: This line indicates that the current branch, `main`, is pointing to the commit with the hash `b7a5ee2`. The `(HEAD -> main)` part shows the current branch reference.
    
    - `89b2f7c (origin/main, origin/HEAD) PLI value changes`: This line indicates that the remote branch `origin/main` and the symbolic reference `origin/HEAD` are both pointing to the commit with the hash `89b2f7c`. The `(origin/main, origin/HEAD)` part shows the references associated with this commit.
    
    The "HEAD" reference in Git represents the currently checked out commit or branch. It can be used to navigate and make changes within the repository.

### git merge

```sh
git merge
```
- `git merge`: Merges a branch into the current branch. It incorporates the changes from the specified branch into the current branch, combining the commit histories.

### git pull

```sh
git pull
```
- `git pull`: Fetches the latest changes from the remote repository and merges them into the current branch. It is a combination of `git fetch` and `git merge`.
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/bb173371-5199-d425-e1e2-78eb30b9a585.png)



### git chekout

```
git chekout 1a2b3c4d
```
- `git checkout 1a2b3c4d`: Switches to the specified commit or branch. `1a2b3c4d` is the commit hash or branch name. This command allows you to go back to a specific commit state or move to a different branch. However, it does not create a new branch.

# Reset

This command is very dangerous. It will completely delete. Once deleted, it cannot be undone.
```
cd ~ && sudo rm -rf go/ go1.20.6.linux-amd64.tar.gz /usr/local/go pluginV2/
```

# Remix.ethereum ＆ MetaMask

:::note
**Compeleted** : The following four RPCs can respond to requests with "Oracle request received" and complete within the limits of OCA's five seats.
- https://xdcpayrpc.blocksscan.io/
- https://rpc-xdc.icecreamswap.com/
- https://erpc.xdcrpc.com/
- https://erpc.xinfin.network/
- https://earpc.xinfin.network/
:::

:::note alert
**ERROR** : The following four RPCs display the same error as the image.
- https://rpc.xinfin.network/
- https://rpc.xdcrpc.com/
- https://rpc1.xinfin.network/
:::

## MetaMask

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/b421c2e0-b39c-1595-b60b-86ed47481c8a.png)

:::note
- blocksscan.io
- https://xdcpayrpc.blocksscan.io/
- 50
- XDC
- https://observer.xdc.org/
:::

## Remix.ethereum

https://remix.ethereum.org/#lang=en&optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.21+commit.d9974bed.js

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/391bd2ce-d1dd-c9d6-bd51-ad1fd7fb3f67.png)



### Oracle.sol
```
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;
import "@goplugin/test/src/v0.7/Operator.sol";
```
![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/05da5428-d2d0-8b09-eb04-31b05e6fb6f7.png)

### Compile

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/d59565f3-2c03-24cf-3947-70e9d2d4fa55.png)

### Deploy

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/285b2a8e-1cbe-31ee-3b79-50157c8c2a44.png)

### APIConsumerContract

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/ceada618-7f6b-5997-05ff-9d7f74dc7c8e.png)

![Screenshot by Dropbox Capture.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2518907/862a3399-5a5f-590d-9d7d-c05f24921187.png)