From 4c156882726bcff534ba56a15b929337c3575bb7 Mon Sep 17 00:00:00 2001 From: risodss <118058080+risodss@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:15:36 +0700 Subject: [PATCH 1/8] Add files via upload --- json-rpc.mjs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 json-rpc.mjs diff --git a/json-rpc.mjs b/json-rpc.mjs new file mode 100644 index 0000000..f2b0be7 --- /dev/null +++ b/json-rpc.mjs @@ -0,0 +1,52 @@ +import { Api, JsonRpc, RpcError, JsSignatureProvider } from '../dist/index.js' +import * as dotenv from 'dotenv' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import +dotenv.config() + +// our Node URL, when we first setup our node, inery has created our RPC in port :8888 +// check it on your node, /inery-node/inery.setup/tools/config.json HTTP_ADDRESS key +const url = process.env.NODE_URL + +const json_rpc = new JsonRpc(url) // create new JsonRPC using our node url +const private_key = process.env.PRIVATE_KEY; // private key + +const account = process.env.INERY_ACCOUNT // Inery Smart Contract Account to Call +const actor = process.env.INERY_ACCOUNT // The Signer, should match with your provided Private Key +const signature = new JsSignatureProvider([private_key]); // creating Signer from private key + +// calling API +const api = new Api({ + rpc: json_rpc, + signatureProvider: signature +}) + +// A Function to create new data in our Valued Smart Contract, and call "create" function on our Smart contract +async function create(id, user, data){ + try{ + // create new transaction and sign it + const tx = await api.transact({ + actions:[ + { + account, + name:"create", + authorization:[ + { + actor, + permission:"active" + } + ], + data:{ + id, user, data + } + } + ] + },{broadcast:true,sign:true}) + + console.log(tx) // output the tx to terminal, it's Json Object + console.log(tx.processed.action_traces[0].console) + }catch(error){ + console.log(error) + } +} + +// call RPC that we created in create function +create(5, account, "Create new Data via JSON RPC") \ No newline at end of file From 008c56c5be791d1c630ded2983e255a33f2e9dbf Mon Sep 17 00:00:00 2001 From: risodss <118058080+risodss@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:16:26 +0700 Subject: [PATCH 2/8] Rename json-rpc.mjs to example/json-rpc.mjs --- json-rpc.mjs => example/json-rpc.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename json-rpc.mjs => example/json-rpc.mjs (97%) diff --git a/json-rpc.mjs b/example/json-rpc.mjs similarity index 97% rename from json-rpc.mjs rename to example/json-rpc.mjs index f2b0be7..b792007 100644 --- a/json-rpc.mjs +++ b/example/json-rpc.mjs @@ -49,4 +49,4 @@ async function create(id, user, data){ } // call RPC that we created in create function -create(5, account, "Create new Data via JSON RPC") \ No newline at end of file +create(5, account, "Create new Data via JSON RPC") From 8b1bc9b33f9565de3b119d7e7c50f4a38c758d5f Mon Sep 17 00:00:00 2001 From: risodss <118058080+risodss@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:16:55 +0700 Subject: [PATCH 3/8] Create readme.md --- example/readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 example/readme.md diff --git a/example/readme.md b/example/readme.md new file mode 100644 index 0000000..5547e9f --- /dev/null +++ b/example/readme.md @@ -0,0 +1 @@ +inery task 4 test From 5c329d6cca0dde92f1b605098894ba0b3d3875bb Mon Sep 17 00:00:00 2001 From: risodss <118058080+risodss@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:22:04 +0700 Subject: [PATCH 4/8] Add files via upload --- example/json-rpc.mjs | 2 +- example/readme.md | 140 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 140 insertions(+), 2 deletions(-) diff --git a/example/json-rpc.mjs b/example/json-rpc.mjs index b792007..f2b0be7 100644 --- a/example/json-rpc.mjs +++ b/example/json-rpc.mjs @@ -49,4 +49,4 @@ async function create(id, user, data){ } // call RPC that we created in create function -create(5, account, "Create new Data via JSON RPC") +create(5, account, "Create new Data via JSON RPC") \ No newline at end of file diff --git a/example/readme.md b/example/readme.md index 5547e9f..72bc349 100644 --- a/example/readme.md +++ b/example/readme.md @@ -1 +1,139 @@ -inery task 4 test +# Json RPC Sample for Task 4 Inery Blockchain +A Sample code to call JSON RPC on Inery Blockchain + +## Getting Started + +JSON RPC Sample code are available at [example](https://github.com/alteregogi/ineryjs/blob/master/example/) directory, you can try to modify and understand how it works, you also need to have Valued Smart Contract ( Task 3 ) in your Account, to able run your code and call the valued contract function. + + +### Prerequisites + +- Your Favorite Code Editor +- Git +- [Node.Js](https://nodejs.dev/en/) + + - Ubuntu Installation Tutorial + + Remove Previous Nodejs + + ``` + sudo apt-get remove nodejs + ``` + + Install Curl + + ``` + sudo apt-get install curl + ``` + + Install NodeJS + + ``` + curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\ + sudo apt-get install -y nodejs + ``` + + + + - [Windows Installation](https://nodejs.org/dist/v18.12.1/node-v18.12.1-x64.msi) + +- npm + + - Ubuntu + + ``` + sudo apt install npm + ``` + + +### Installation + +1. Clone the repo + + ``` + git clone https://github.com/alteregogi/ineryjs.git + ``` + +2. Change directory to cloned repo + + ``` + cd ineryjs + ``` + +3. Install NPM packages + + ``` + npm install + ``` + +4. Copy `.env-sample` and rename it to `.env` + + ``` + cp .env-sample .env + ``` + +5. Edit ```.env``` file with your information + + + +## Usage + +Run RPC Example + +``` +npm run rpc-example +``` + + + +#### Successful Example + +if you see similar error message after running ``npm run rpc-example``, it means your transaction has been executed on blockchain using JsonRPC +![](https://snipboard.io/JQ1hnc.jpg) + +image credit : **Zyprexh#0331** + +## FAQ + +#### 1. Error : Serialization time limit 15000us exceeded: + +![](https://snipboard.io/a0drGN.jpg) + +**How To Fix:** + +Change ``max-transaction-time`` to more than ``15000`` in your ``config.ini`` +```shell +nano ./inery-node/inery.setup/master.node/blockchain/config/config.ini +``` + +Thanks to **Kairos#2656**! + + +#### 2. Error : connect ECONNREFUSED NODE_IP_ADDRESS:8888 + +![](https://snipboard.io/UgSMH2.jpg) + +**How To Fix:** + +Make sure your port **8888** is open, try to check it on [portchecker.co](https://portchecker.co/) , each vps will have different settings, usually you need to open the port using this command +``` +sudo ufw allow 8888 +``` + +else, make sure to open your port setting on your VPS provider dashboard + +#### 3. Error: missing create.issuer ( type=name ) + +It means that you doesn't have Valued Smart Contract on your account, which you created on Task 3. + +![](https://snipboard.io/aTBHL3.jpg) + +To check if you have your CRUD Smart Contract on your account + +``` +cline get abi your_inery_account +``` + +Make sure that you have this output on **actions** key + +![](https://snipboard.io/0vsnOq.jpg) From 77786b714a8e7b0e378132862c5faeae12da816f Mon Sep 17 00:00:00 2001 From: risodss <118058080+risodss@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:25:17 +0700 Subject: [PATCH 5/8] Update package.json --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 217d247..37bfca6 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "doc": "jsdoc -c jsdoc.json", "generate-docs": "jsdoc --configure jsdoc.json --verbose", "build-web": "webpack --config webpack.config.js" + "rpc-example": "node ./example/json-rpc.mjs" }, "author": "Inery", "license": "MIT", @@ -17,6 +18,7 @@ "homepage": "https://github.com/inery-blockchain/ineryjs", "dependencies": { "bn.js": "^5.2.0", + "dotenv": "^16.0.3", "elliptic": "^6.5.4", "hash.js": "^1.1.7", "node-fetch": "^2.6.7", From 62632b9e2faac9bcbbc142f44afa0e789b06b957 Mon Sep 17 00:00:00 2001 From: risodss <118058080+risodss@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:29:35 +0700 Subject: [PATCH 6/8] Update package-lock.json --- package-lock.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/package-lock.json b/package-lock.json index 538a8da..479f6b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "bn.js": "^5.2.0", + "dotenv": "^16.0.3", "elliptic": "^6.5.4", "hash.js": "^1.1.7", "node-fetch": "^2.6.7", @@ -1170,6 +1171,14 @@ "node": ">=0.8.0" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/diffie-hellman": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", @@ -4608,6 +4617,11 @@ "typedarray": "^0.0.6" } }, + "dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" + }, "console-browserify": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.2.0.tgz", From df921b0e1b542ad6d562ef905aad174af7a82f72 Mon Sep 17 00:00:00 2001 From: risodss <118058080+risodss@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:35:07 +0700 Subject: [PATCH 7/8] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 37bfca6..0dba4b4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "doc": "jsdoc -c jsdoc.json", "generate-docs": "jsdoc --configure jsdoc.json --verbose", - "build-web": "webpack --config webpack.config.js" + "build-web": "webpack --config webpack.config.js", "rpc-example": "node ./example/json-rpc.mjs" }, "author": "Inery", From 25be8b3703e1d1fd9381b52dd80f2d261cc2687f Mon Sep 17 00:00:00 2001 From: risodss <118058080+risodss@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:36:55 +0700 Subject: [PATCH 8/8] Add files via upload --- .env-sample | 3 +++ .gitignore | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 .env-sample create mode 100644 .gitignore diff --git a/.env-sample b/.env-sample new file mode 100644 index 0000000..f8402d4 --- /dev/null +++ b/.env-sample @@ -0,0 +1,3 @@ +INERY_ACCOUNT="your_inery_account" +PRIVATE_KEY="your_private_key" +NODE_URL="http://your_node_url:8888" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ed48a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +node_modules