diff --git a/murnicitawa/README.md b/murnicitawa/README.md new file mode 100644 index 000000000..dade83f50 --- /dev/null +++ b/murnicitawa/README.md @@ -0,0 +1,24 @@ +## Prerequisites + +- Node.js: This script uses the `eosjs` library, which requires Node.js. You can download the latest version of Node.js from the official website (https://nodejs.org/). +- EOS node: This script interacts with an EOS node through its HTTP API. You will need to have an EOS node running and its HTTP API endpoint URL available. + +## Setting up the environment + +1. Clone the repository or download the script. +2. Create a file named `.env` in the same directory as the script. +3. In the `.env` file, define the following environment variables: + - `NODE_URL`: The URL of the HTTP API endpoint of your EOS node. + - `PRIVATE_KEY`: The private key of the account that will sign and broadcast the transaction. + - `INERY_ACCOUNT`: Your Inery account name. + - `TOKEN`: The token you created in your Inery account. +4. Install the dependencies by running `npm install` in the terminal. + +## Running the script + +1. Open a terminal and navigate to the directory where the script is located. +2. Run the script with the following command: `node ./inerynoderpc.mjs` or `npm run MC-RPC` + +## Expected output + +If the script runs successfully, you should see the signed transaction object and the console output of the `transfer` action of the `inery.token` contract, depending on the script. If an error occurs, the error message will be printed to the console. \ No newline at end of file diff --git a/murnicitawa/inerynoderpc.mjs b/murnicitawa/inerynoderpc.mjs new file mode 100644 index 000000000..1f7ffebc5 --- /dev/null +++ b/murnicitawa/inerynoderpc.mjs @@ -0,0 +1,128 @@ +import { Api, JsonRpc, JsSignatureProvider } from 'ineryjs' +import * as dotenv from 'dotenv' +import axios from 'axios' + +dotenv.config() + +const url = process.env.NODE_URL + +const json_rpc = new JsonRpc(url) +const private_key = process.env.PRIVATE_KEY; + +const account = process.env.INERY_ACCOUNT +const actor = process.env.INERY_ACCOUNT +const token = process.env.TOKEN +const signature = new JsSignatureProvider([private_key]); + +const api = new Api({ + rpc: json_rpc, + signatureProvider: signature +}) + + +var lastBlockNum = 0; +var lastFiveProducers = []; + +// Get Last Block Info For Latest Block Number +await GetLastBlockInfo(); + +// If The Last Block Info Was Retrieved Succesfully +if (lastBlockNum != 0) { + // Get Last 5 Producers Account + await FillLastProducers(); + + // If The Last Producers Were Successfully Imported + if(lastFiveProducers.length > 0) + { + // Send Sample Token To Last Producers + lastFiveProducers.forEach(async item => { + await SendToken(item); + }); + } + +} +async function GetLastBlockInfo() { + try { + + let get_info = { + method: 'post', + url: url + '/v1/chain/get_info', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }, + }; + + await axios(get_info) + .then((response) => { + lastBlockNum = response.data["head_block_num"]; + }) + .catch((error) => { + console.log(error); + }); + } catch (error) { + console.log(error) + } +} + +async function FillLastProducers() { + for (let index = (lastBlockNum - 4); index <= lastBlockNum; index++) { + await GetBlockInfo(index); + } +} + +async function GetBlockInfo(block_num) { + + try { + + let data = JSON.stringify({ + "block_num_or_id": block_num.toString() + }); + + let get_block = { + method: 'post', + url: url + '/v1/chain/get_block', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }, + data: data + }; + + await axios(get_block) + .then((response) => { + lastFiveProducers.push(response.data["master"]); + }) + .catch((error) => { + console.log(error); + }); + } + catch (error) { + console.log(error) + } +} + +async function SendToken(to) { + try { + const result = await api.transact({ + actions: [{ + account: 'inery.token', + name: 'transfer', + authorization: [{ + actor: actor, + permission: 'active', + }], + data: { + from: account, + to: to, + quantity: '0.0001 ' + token, + memo: 'Here 0.0001 ' + token + ' for you :)', + } + }] + }); + + console.log(result); + } catch (error) { + console.log(error) + } +} \ No newline at end of file diff --git a/murnicitawa/package.json b/murnicitawa/package.json new file mode 100644 index 000000000..a2561ae20 --- /dev/null +++ b/murnicitawa/package.json @@ -0,0 +1,17 @@ +{ + "name": "murnicitawa", + "version": "1.0.0", + "description": "", + "type": "module", + "scripts": { + "MC-RPC": "node ./inerynoderpc.mjs" + }, + "dependencies": { + "axios": "^1.2.2", + "dotenv": "^16.0.3", + "ineryjs": "github:inery-blockchain/ineryjs" + }, + "keywords": [], + "author": "murnicitawa", + "license": "ISC" +}