Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task4 tanjuni RPC #1484

Open
wants to merge 1 commit into
base: task4
Choose a base branch
from
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
41 changes: 41 additions & 0 deletions tanjuni/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
### Install dependencies

- [NodeJS](https://nodejs.org/en/)

- NPM

- GIT

```
curl http://deb.nodesource.com/setup_lts.x | sudo bash -
sudo apt install git nodejs -y
```

### Clone
```
git clone https://github.com/LampanKesuma/inery-testnet-faucet-tasks -b task4
```
###
### Configuring env vars in
- `NODE_URL="NODE_URL"`
- `ACCOUNT="YOUR_INERY_ACCOUNT_NAME"`
- `PRIV_KEY="PRIVATE_KEY_OF_INERY_ACCOUNT_NAME"`
- `ID=""` ID record number
```
cd inery-testnet-faucet-tasks/tanjuni
```
```
nano .env
```

### Install module dependencies

```
npm install -g npm
npm install
```

## Run the script
```
npm run push-crud-tanjuni
```
39 changes: 39 additions & 0 deletions tanjuni/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Api, JsonRpc, JsSignatureProvider } from'ineryjs'
import dotenv from'dotenv'
dotenv.config()

const { NODE_URL, PRIV_KEY, ID, ACCOUNT } = process.env

const api = new Api({
rpc: new JsonRpc(NODE_URL),
signatureProvider: new JsSignatureProvider([PRIV_KEY])
})

const abi = await api.getAbi(ACCOUNT, true)

async function create() {
try{
const tx = api.buildTransaction()
tx.with(ACCOUNT).as(ACCOUNT).create(...Object.values({ id: ID, ACCOUNT, data: 'tanjuni' }))
console.log(await tx.send())
}
catch(error){
console.error(error)
}
}

async function destroy() {
try{
const tx = api.buildTransaction()
tx.with(ACCOUNT).as(ACCOUNT).destroy(...Object.values({ id: ID }))
console.log(await tx.send())
}
catch(error){
console.error(error)
}
}

(async () => {
await create()
await destroy()
})()
18 changes: 18 additions & 0 deletions tanjuni/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "tanjuni",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"push-crud-tanjuni": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.3",
"ineryjs": "github:inery-blockchain/ineryjs"
}
}