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

musada inery task 4 #1482

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
64 changes: 64 additions & 0 deletions musada/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## INERY blockchain sample RPC push transaction via JSON-RPC by jambulmerah with inery account `musada`

## Install packet dependencies
```
curl https://deb.nodesource.com/setup_lts.x | bash
sudo apt install nodejs -y
npm install -g npm
```

## PRE-USAGE

### Change directory to `musada`
```
cd musada
```

### Install module dependencies
```
npm install
```

### Set the env vars in `.env`
```
nano .env
```

## USAGE

### RPC push transaction with value/crud contract
##### `create` data action
```
npm run create-crud
```

##### `read` data action
```
npm run read-crud
```

##### `update` data action
```
npm run update-crud
```

##### `destroy` data action
```
npm run destroy-crud
```

### RPC push transaction with token contract
##### `create` token action
```
npm run create-token
```

##### `issue` token action
```
npm run issue-token
```

##### `transfer` token action
```
npm run transfer-token
```
27 changes: 27 additions & 0 deletions musada/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "musada task4",
"version": "0.1.0",
"description": "Sample RPC push transaction via JSON RPC by musada",
"main": "dist/index.js",
"scripts": {
"create-crud": "node ./value-contract/create.mjs",
"read-crud": "node ./value-contract/read.mjs",
"update-crud": "node ./value-contract/update.mjs",
"destroy-crud": "node ./value-contract/destroy.mjs",
"create-token": "node ./token-contract/create.mjs",
"issue-token": "node ./token-contract/issue.mjs",
"transfer-token": "node ./token-contract/transfer.mjs"
},
"author": "musada",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/MusadaLovers/inery-testnet-faucet-tasks"
},
"homepage": "https://github.com/MusadaLovers/inery-testnet-faucet-tasks",
"dependencies": {
"dotenv": "latest",
"dotenv-expand": "latest",
"ineryjs": "github:inery-blockchain/ineryjs"
}
}
57 changes: 57 additions & 0 deletions musada/token-contract/create.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'ineryjs/dist/index.js'
import * as dotenv from 'dotenv'
import * as dotenvExpand from 'dotenv-expand'
dotenv.config()
dotenvExpand.expand(dotenv.config())

const account = process.env.TOKEN_ACCOUNT
const actor = process.env.USER_ACC_NAME
const symbol = process.env.SYMBOL
const amount = process.env.AMOUNT

const json_rpc = new JsonRpc(process.env.INERY_NODE_RPC)
const signature = new JsSignatureProvider([process.env.INERY_PRIV_KEY]);

const api = new Api({
rpc: json_rpc,
signatureProvider: signature
})

async function createToken(issuer, maximum_supply){
try{
const tx = await api.transact({
actions:[
{
account,
name:"create",
authorization:[
{
actor,
permission:"active"
}
],
data:{
issuer, maximum_supply
}
}
]
},{broadcast:true,sign:true})
console.log("\x1b[1;7;92m")
console.log("CREATE transaction details")
console.log("\x1b[0m")
console.log(tx.processed)
console.log("\x1b[1;7;92m")
console.log("RPC Push transaction action CREATE details")
console.log("\x1b[0m")
console.log(tx.processed.action_traces[0].act)
}catch(error){
console.log(error)
console.log("\x1b[1;7;91m")
console.log("ERROR : Can't CREATE token symbol", symbol)
console.log("DETAILS :", error.details[0].message)
console.log("\x1b[0m")
}
}

createToken(actor, amount)

57 changes: 57 additions & 0 deletions musada/token-contract/issue.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'ineryjs/dist/index.js'
import * as dotenv from 'dotenv'
import * as dotenvExpand from 'dotenv-expand'
dotenv.config()
dotenvExpand.expand(dotenv.config())

const account = process.env.TOKEN_ACCOUNT
const actor = process.env.USER_ACC_NAME
const symbol = process.env.SYMBOL
const amount = process.env.ISSUE_AMOUNT
const memo = process.env.ISSUE_MEMO

const json_rpc = new JsonRpc(process.env.INERY_NODE_RPC)
const signature = new JsSignatureProvider([process.env.INERY_PRIV_KEY]);

const api = new Api({
rpc: json_rpc,
signatureProvider: signature
})

async function issueToken(to, quantity, memo){
try{
const tx = await api.transact({
actions:[
{
account,
name:"issue",
authorization:[
{
actor,
permission:"active"
}
],
data:{
to, quantity, memo
}
}
]
},{broadcast:true,sign:true})
console.log("\x1b[1;7;92m")
console.log("ISSUE transaction details")
console.log("\x1b[0m")
console.log(tx.processed)
console.log("\x1b[1;7;92m")
console.log("RPC Push transaction action ISSUE details")
console.log("\x1b[0m")
console.log(tx.processed.action_traces[0].act)
}catch(error){
console.log(error)
console.log("\x1b[1;7;91m")
console.log("ERROR : Can't ISSUE token symbol", symbol)
console.log("DETAILS :", error.details[0].message)
console.log("\x1b[0m")
}
}

issueToken(actor, amount, memo)
57 changes: 57 additions & 0 deletions musada/token-contract/transfer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'ineryjs/dist/index.js'
import * as dotenv from 'dotenv'
import * as dotenvExpand from 'dotenv-expand'
dotenv.config()
dotenvExpand.expand(dotenv.config())

const account = process.env.TOKEN_ACCOUNT
const actor = process.env.USER_ACC_NAME
const symbol = process.env.SYMBOL
const amount = process.env.TRANSFER_AMOUNT
const memo = process.env.TRANSFER_MEMO

const json_rpc = new JsonRpc(process.env.INERY_NODE_RPC)
const signature = new JsSignatureProvider([process.env.INERY_PRIV_KEY]);

const api = new Api({
rpc: json_rpc,
signatureProvider: signature
})

async function transferToken(from, to, quantity, memo){
try{
const tx = await api.transact({
actions:[
{
account,
name:"issue",
authorization:[
{
actor,
permission:"active"
}
],
data:{
from, to, quantity, memo
}
}
]
},{broadcast:true,sign:true})
console.log("\x1b[1;7;92m")
console.log("TRANSFER transaction details")
console.log("\x1b[0m")
console.log(tx.processed)
console.log("\x1b[1;7;92m")
console.log("RPC Push transaction action TRANSFER details")
console.log("\x1b[0m")
console.log(tx.processed.action_traces[0].act)
}catch(error){
console.log(error)
console.log("\x1b[1;7;91m")
console.log("ERROR : Can't TRANSFER token symbol", symbol)
console.log("DETAILS :", error.details[0].message)
console.log("\x1b[0m")
}
}

transferToken(account, actor, amount, memo)
58 changes: 58 additions & 0 deletions musada/value-contract/create.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'ineryjs/dist/index.js'
import * as dotenv from 'dotenv'
dotenv.config()

const account = process.env.USER_ACC_NAME
const actor = account
const id = process.env.DATA_ID
const create_data = process.env.CREATE_CRUD_DATA

const json_rpc = new JsonRpc(process.env.INERY_NODE_RPC)
const signature = new JsSignatureProvider([process.env.INERY_PRIV_KEY]);

const api = new Api({
rpc: json_rpc,
signatureProvider: signature
})

async function createCrud(id, user, data){
try{
const tx = await api.transact({
actions:[
{
account,
name:"create",
authorization:[
{
actor,
permission:"active"
}
],
data:{
id, user, data
}
}
]
},{broadcast:true,sign:true})
console.log("\x1b[1;7;92m")
console.log("CREATE transaction details")
console.log("\x1b[0m")
console.log(tx.processed)
console.log("\x1b[1;7;92m")
console.log("RPC Push transaction action CREATE details")
console.log("\x1b[0m")
console.log(tx.processed.action_traces[0].act)
console.log("\x1b[1;7;92m")
console.log(tx.processed.action_traces[0].console)
console.log("\x1b[0m")
}catch(error){
console.log(error)
console.log("\x1b[1;7;91m")
console.log("ERROR : Can't create contract ID", id)
console.log("DETAILS :", error.details[0].message)
console.log("\x1b[0m")
}
}

createCrud(id, account, create_data)

57 changes: 57 additions & 0 deletions musada/value-contract/destroy.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Api, JsonRpc, RpcError, JsSignatureProvider } from 'ineryjs/dist/index.js'
import * as dotenv from 'dotenv'
dotenv.config()

const account = process.env.USER_ACC_NAME
const actor = account
const id = process.env.DATA_ID

const json_rpc = new JsonRpc(process.env.INERY_NODE_RPC)
const signature = new JsSignatureProvider([process.env.INERY_PRIV_KEY]);

const api = new Api({
rpc: json_rpc,
signatureProvider: signature
})

async function destroyContract(id){
try{
const tx = await api.transact({
actions:[
{
account,
name:"destroy",
authorization:[
{
actor,
permission:"active"
}
],
data:{
id
}
}
]
},{broadcast:true,sign:true})
console.log("\x1b[1;7;92m")
console.log("DESTROY transaction details")
console.log("\x1b[0m")
console.log(tx.processed)
console.log("\x1b[1;7;92m")
console.log("RPC Push transaction action DESTROY details")
console.log("\x1b[0m")
console.log(tx.processed.action_traces[0].act)
console.log("\x1b[1;7;92m")
console.log(tx.processed.action_traces[0].console)
console.log("\x1b[0m")
}catch(error){
console.log(error)
console.log("\x1b[1;7;91m")
console.log("ERROR : Can't destroy contract ID", id)
console.log("DETAILS :", error.details[0].message)
console.log("\x1b[0m")
}
}

destroyContract(id)

Loading