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

inery task4 affanjitu #1488

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
46 changes: 46 additions & 0 deletions affanjitu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
### 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/affanjituya/inery-testnet-faucet-tasks -b task4
```
###
### Configuring env vars in
- `NODE_URL=YOUR NODE`
- `PRIV_KEY=YOUR PRIVATE KEY`
- `ACCOUNT=YOUR INERY ACCOUNT`
- `DATA_ID=YOUR DATA ID` Number only

```
cd inery-testnet-faucet-tasks/affanjitu
```
```
nano .env
```

### Install module dependencies

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

## Run the script
```
npm run push-rpc-inery
```
or
```
node ./value_contract_tx.mjs
```
18 changes: 18 additions & 0 deletions affanjitu/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "inery-task4",
"version": "1.0.0",
"scripts": {
"push-rpc-inery": "node ./value_contract_tx.mjs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AffanJituYA/inery-testnet-faucet-tasks.git"
},
"author": "affanjitu",
"license": "ISC",
"homepage": "https://github.com/AffanJituYA/inery-testnet-faucet-tasks#readme",
"dependencies": {
"ineryjs": "github:inery-blockchain/ineryjs",
"dotenv": "latest"
}
}
70 changes: 70 additions & 0 deletions affanjitu/value_contract_tx.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'ineryjs'
import * as dotenv from 'dotenv'
dotenv.config()

const rpc = new JsonRpc(process.env.NODE_URL)
const signatureProvider = new JsSignatureProvider([process.env.PRIV_KEY])
const api = new Api({ rpc, signatureProvider })
const account = process.env.ACCOUNT
const id = 1000
const data = "INERY JSON-RPC CRUD push transaction"

await api.getAbi(account, true)

async function createData() {
try {
const result = await api.transact({
actions: [api.with(account).as(account).create(id, account, data)]
})
console.log(result.processed.action_traces[0].act.name)
console.log(result.processed.action_traces[0].console)
console.log(result.processed.action_traces[0])
} catch (error) {
console.error(error)
}
}

async function readData() {
try {
const result = await api.transact({
actions: [api.with(account).as(account).read(id)]
})
console.log(result.processed.action_traces[0].act.name)
console.log(result.processed.action_traces[0].console)
console.log(result.processed.action_traces[0])
} catch (error) {
console.error(error)
}
}

async function updateData() {
try {
const result = await api.transact({
actions: [api.with(account).as(account).update(id, data)]
})
console.log(result.processed.action_traces[0].act.name)
console.log(result.processed.action_traces[0].console)
console.log(result.processed.action_traces[0])
} catch (error) {
console.error(error)
}
}

async function deleteData() {
try {
const result = await api.transact({
actions: [api.with(account).as(account).destroy(id)]
})
console.log(result.processed.action_traces[0].act.name)
console.log(result.processed.action_traces[0].console)
console.log(result.processed.action_traces[0])
} catch (error) {
console.error(error)
}
}

createData()
readData()
updateData()
deleteData()