rocketchain-package

0.0.16-RC0 • Public • Published

Rocketchain-package.

Summary

Package used for web3 provider integration between client side and API.

A repository to integrate required interaction between platform user (on client app) and blockchain actions signatures. Then the info generated and logs are sent to the related API endpoints.

Index

  • Installation
  • Specification

Installation

npm install rocketchain-package

Dependencies used:

Axios, web3

Specification

Function: setClientServerUrl

Sets the client server url received. setClientServerUrl(param1)

Parameters:

param1: client server url address

Example:

setClientServerUrl("http://localhost:5000")

Return:

No return.

Function: metamaskConnect

Checks if client app user is logged in with Metamask (to be able to receive transaction signature requests) and returns a promise with the user wallet address. If not, Metamask prompts asking to log in.

Parameters:

No parameters

Example:

    const someFunctionThatNeedsTheUserWalletAddress = async() => {
        const walletAddress = await metamaskConnect()
        ...
    }

Return:

Returns a promise.

Success:

console.log(walletAddress)
0xECf8C3205B230a39a71354214561dAA83433Ae3B

Failure - string with error description if fails (depending on where the problem was)

console.log(connect)
"There is no account to connect to"
console.log(connect)
"There was a problem connecting to your Metamask wallet. Do you have Metamask installed?"

Function: clientTokenTransfer

Transfer -that must be signed- of some amount of token from the user to another receiver

clientTokenTransfer(param1, param2, param3)

Parameters:

  • param1: address receiver of the tokens
  • param2: address of the token contract that will be transferred
  • param3: amount of token to be transferred

Example:

tokenTransfer(0xe4513a7BCd98dE50Fe7984C82dAf5611beBa7170, 0xa6c99e129cecf74865f6ed847a62c63cd6e0c045, 17) 

Return:

Returns a promise:

Success: transaction object from Blockchain

{
  "blockHash": "0x59ae5fc6af98787806d2733e97bc749e057ef0bf6d1c85d2f42f3eed92b9cba1",
  "blockNumber": 9245548,
  "contractAddress": null,
  "cumulativeGasUsed": 8907523,
  "effectiveGasPrice": "0x3b9aca0e",
  "from": "0x212f260404a05e954bc9285bfae89d6b2bb45134",
  "gasUsed": 34494,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000008000000000000010000008000000000000000000000000000000000040000000000000000000000000000000000000010000000000000000000000100000000004000000000004000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": true,
  "to": "0xa6c99e129cecf74865f6ed847a62c63cd6e0c045",
  "transactionHash": "0xe8992e16afc720381390cb54f1bb3a6a0e3a30fc143797dced38417b2a02f99e",
  "transactionIndex": 37,
  "type": "0x2",
  "events": {
    "Transfer": {
      "address": "0xa6C99E129cecF74865F6eD847a62c63cD6E0C045",
      "blockHash": "0x59ae5fc6af98787806d2733e97bc749e057ef0bf6d1c85d2f42f3eed92b9cba1",
      "blockNumber": 9245548,
      "logIndex": 92,
      "removed": false,
      "transactionHash": "0xe8992e16afc720381390cb54f1bb3a6a0e3a30fc143797dced38417b2a02f99e",
      "transactionIndex": 37,
      "id": "log_696ad3a5",
      "returnValues": {
        "0": "0x212f260404A05E954BC9285BFAe89D6B2bB45134",
        "1": "0xe4513a7BCd98dE50Fe7984C82dAf5611beBa7170",
        "2": "17",
        "from": "0x212f260404A05E954BC9285BFAe89D6B2bB45134",
        "to": "0xe4513a7BCd98dE50Fe7984C82dAf5611beBa7170",
        "value": "17"
      },
      "event": "Transfer",
      "signature": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
      "raw": {
        "data": "0x0000000000000000000000000000000000000000000000000000000000000011",
        "topics": [
          "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
          "0x000000000000000000000000212f260404a05e954bc9285bfae89d6b2bb45134",
          "0x000000000000000000000000e4513a7bcd98de50fe7984c82daf5611beba7170"
        ]
      }
    }
  }
}

Error: The log depends on where the error was produced

Function: tokenCreate

Creates a token using given token parameters and the user wallet address to relate the request

tokenCreate(param1, param2, param3, param4, param5)

Parameters:

  • param1: Name given to the token by the user
  • param2: total amount of tokens that will be created
  • param3: Symbol of the token given by the user
  • param4: Decimals of the token
  • param5: wallet address of the user that requested the token creation

Example:

const RocketchainPackage = require('rocketchain-package');
const someFunction = async () => {
        const createdToken = await RocketchainPackage.tokenCreate(
             "Token Doc",
             "44",
             "TkD",
             "0",
             "0xe4513a7BCd98dE50Fe7984C82dAf5611beBa7170",
        );
    }

Return:

Returns a promise.

Database object with all the creation Blockchain data related

console.log(createdToken);
{
  "data": {
    "is_transferred": false,
    "_id": "613628fcf7a6782270588ee1",
    "token_address": "0x85398185A1CBE64D7f8Bf4aD668AB7352A93F589",
    "wallet_address": "0xe4513a7BCd98dE50Fe7984C82dAf5611beBa7170",
    "amount": "44",
    "log_id": "613628fcf7a6782270588edf",
    "created_at": "2021-09-06T12:42:55.000Z",
    "__v": 0
  },
  "status": 200,
  "statusText": "OK",
  "headers": {
    "cache-control": "no-cache, private",
    "content-length": "278",
    "content-type": "text/html; charset=UTF-8"
  },
  "config": {
    "url": "http://rocketchain-server.test/api/token_creation_response",
    "method": "post",
    "data": "{\"nameOfToken\":\"Token Doc\",\"numberOfToken\":\"44\",\"symbolOfToken\":\"TkD\",\"numberOfDecimals\":\"0\",\"userWalletAddress\":\"0xe4513a7BCd98dE50Fe7984C82dAf5611beBa7170\"}",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/json"
    },
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "timeout": 0,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "maxBodyLength": -1,
    "transitional": {
      "silentJSONParsing": true,
      "forcedJSONParsing": true,
      "clarifyTimeoutError": false
    }
  },
  "request": {}
}

Function: tokenTransferWithTokenAddressOnly

Transfer linked with the token creation (as a second step) process

tokenTransferWithTokenAddressOnly(param1)

Parameters:

param1: token smart contract address.

(Retrieved from tokenCreate method response => data.token_address)

Example:

const RocketchainPackage = require('rocketchain-package');
const someFunction = async data => {
        const tokenTransferred = await RocketchainPackage.tokenTransferWithTokenAddressOnly("0x85398185A1CBE64D7f8Bf4aD668AB7352A93F589");
    };

Return:

Returns a promise.

Database object with all the Blockchain transfer data related

console.log(tokenTransferred);
{
	"blockHash": "0xd5da8d878e62ec7868e80d0df0676fe9f52a21af4a1277c40ab2cb1b7d092b95",
	"blockNumber": 9245705,
	"contractAddress": null,
	"cumulativeGasUsed": 3396087,
	"effectiveGasPrice": "0x3b9aca0d",
	"from": "0x212f260404a05e954bc9285bfae89d6b2bb45134",
	"gasUsed": 46794,
	"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000010004008000000000000000000000000000000000040000000000000000000000000000000000000010000000000000000000000100000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000002000000000000000000000000000000000000010000002000000000000000000000000000000000000000000000000000000000000000000000000000",
	"status": true,
	"to": "0x85398185a1cbe64d7f8bf4ad668ab7352a93f589",
	"transactionHash": "0x6cea70d5436e706a659ff339fc7b012576eafc6b28bcf9c93355fd19ad2a800b",
	"transactionIndex": 24,
	"type": "0x0",
	"events": {
		"Transfer": {
			"address": "0x85398185A1CBE64D7f8Bf4aD668AB7352A93F589",
			"blockHash": "0xd5da8d878e62ec7868e80d0df0676fe9f52a21af4a1277c40ab2cb1b7d092b95",
			"blockNumber": 9245705,
			"logIndex": 30,
			"removed": false,
			"transactionHash": "0x6cea70d5436e706a659ff339fc7b012576eafc6b28bcf9c93355fd19ad2a800b",
			"transactionIndex": 24,
			"id": "log_0dd77e89",
			"returnValues": {
				"0": "0x212f260404A05E954BC9285BFAe89D6B2bB45134",
				"1": "0xe4513a7BCd98dE50Fe7984C82dAf5611beBa7170",
				"2": "44",
				"from": "0x212f260404A05E954BC9285BFAe89D6B2bB45134",
				"to": "0xe4513a7BCd98dE50Fe7984C82dAf5611beBa7170",
				"value": "44"
			},
			"event": "Transfer",
			"signature": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
			"raw": {
				"data": "0x000000000000000000000000000000000000000000000000000000000000002c",
				"topics": [
					"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
					"0x000000000000000000000000212f260404a05e954bc9285bfae89d6b2bb45134",
					"0x000000000000000000000000e4513a7bcd98de50fe7984c82daf5611beba7170"
				]
			}
		}
	}
}

Function: getTokenOwnersBalance

Retrieves all the accounts that have owned (0 balance now) or currently own (positive balance) the token specified by the token contract address.

getTokenOwnersBalance(param1)

Parameters:

param1: smart contract token address.

Example:

const RocketchainPackage = require('rocketchain-package');
const someFunction = async () => {
        const ownersArray = await RocketchainPackage.getTokenOwnersBalance(0xa6c99e129cecf74865f6ed847a62c63cd6e0c045);                
    };

Return:

Returns a promise.

Array of objects. Each object represents a pair of owner-balance values.

console.log(ownersArray);
[{"owner":"0xe4513a7BCd98dE50Fe7984C82dAf5611beBa7170","balance":"41"},{"owner":"0x212f260404A05E954BC9285BFAe89D6B2bB45134","balance":"5959"}]

Function: isMetamaskInstalled

Checks if Metamask is installed in order to proceed with the rest of functionalities

isMetamaskInstalled()

Parameters:

No parameters required.

Example:

const RocketchainPackage = require('rocketchain-package');
const someFunction = async () => {
        const checkMetamask = await RocketchainPackage.isMetamaskInstalled();                
    };

Return:

Returns a response depending on Metamask is/is not installed.

{ ok: false, message: "You don't have Metamask installed." }

Function: checkWalletFormat

Checks if the wallet provided has the proper structure and format.

checkWalletFormat(param1)

Parameters:

param1: wallet address.

Example:

const RocketchainPackage = require('rocketchain-package');
const someFunction = async () => {
        const formatVerification = await RocketchainPackage.checkWalletFormat(0xLZf8C3205B230a39a71354214561dAA83433Ae4K);                
    };

Return

Returns a response depending on whether the data provided has the right format or not.

{ ok: true, message: "Proper address format" }

Function: selectOrAddPolygonMainNetwork

Selects or adds the Polygon Matic Mainnet to the Metamask wallet.

selectOrAddPolygonMainNetwork()

Parameters:

No parameters required.

Example:

const RocketchainPackage = require('rocketchain-package');
const someFunction = async () => {
        const selectOrAddPolygonMainNetwork = await RocketchainPackage.selectOrAddPolygonMainNetwork();                
    };

Return

Returns a response depending on whether the Polygon main network was previously added or needs to be added.

{ ok: true, message: "Matic Mainnet added successfully", response: ... }

Package Sidebar

Install

npm i rocketchain-package

Weekly Downloads

2

Version

0.0.16-RC0

License

MIT

Unpacked Size

35.4 kB

Total Files

4

Last publish

Collaborators

  • arturomf
  • pablinvaz
  • peraltajavieralejandro27