Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INERY_ACCOUNT="your_inery_account"
PRIVATE_KEY="your_private_key"
NODE_URL="http://your_node_url:8888"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules
52 changes: 52 additions & 0 deletions example/json-rpc.mjs
Original file line number Diff line number Diff line change
@@ -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")
139 changes: 139 additions & 0 deletions example/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# 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)
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"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",
"license": "MIT",
Expand All @@ -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",
Expand Down