All Projects → harpagon210 → Sscjs

harpagon210 / Sscjs

Licence: mit
a light javascript library to interact with the Steem Smart Contracts Sidechain

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sscjs

Blockchainstore
💰 Retail Store that runs on Ethereum
Stars: ✭ 425 (+2136.84%)
Mutual labels:  smart-contracts
Btcrelay
Ethereum contract for Bitcoin SPV: Live on https://etherscan.io/address/0x41f274c0023f83391de4e0733c609df5a124c3d4
Stars: ✭ 533 (+2705.26%)
Mutual labels:  smart-contracts
Hardhat
Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software. Get Solidity stack traces & console.log.
Stars: ✭ 727 (+3726.32%)
Mutual labels:  smart-contracts
Web3swift
Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions on Ethereum network.
Stars: ✭ 462 (+2331.58%)
Mutual labels:  smart-contracts
Condenser
The greatest application front-end to the Steem Blockchain.
Stars: ✭ 516 (+2615.79%)
Mutual labels:  steem
Dtube
📺 d.tube app. A full-featured video sharing website, decentralized.
Stars: ✭ 569 (+2894.74%)
Mutual labels:  steem
Eth Crypto
Cryptographic javascript-functions for ethereum and tutorials to use them with web3js and solidity
Stars: ✭ 420 (+2110.53%)
Mutual labels:  smart-contracts
Eth.social
An Ethereum dApp for posting social events.
Stars: ✭ 17 (-10.53%)
Mutual labels:  smart-contracts
Go Iost
Official Go implementation of the IOST blockchain
Stars: ✭ 523 (+2652.63%)
Mutual labels:  smart-contracts
Ethlint
(Formerly Solium) Code quality & Security Linter for Solidity
Stars: ✭ 698 (+3573.68%)
Mutual labels:  smart-contracts
Baseline
The Baseline Protocol is an open source initiative that combines advances in cryptography, messaging, and blockchain to execute secure and private business processes at low cost via the public Ethereum Mainnet. The protocol will enable confidential and complex collaboration between enterprises without leaving any sensitive data on-chain
Stars: ✭ 479 (+2421.05%)
Mutual labels:  smart-contracts
Web3.php
A php interface for interacting with the Ethereum blockchain and ecosystem. Native ABI parsing and smart contract interactions.
Stars: ✭ 507 (+2568.42%)
Mutual labels:  smart-contracts
Echidna
Ethereum smart contract fuzzer
Stars: ✭ 571 (+2905.26%)
Mutual labels:  smart-contracts
Smart Contract Best Practices
A guide to smart contract security best practices
Stars: ✭ 4,784 (+25078.95%)
Mutual labels:  smart-contracts
Ethereum Development With Go Book
📖 A little book on Ethereum Development with Go (golang)
Stars: ✭ 754 (+3868.42%)
Mutual labels:  smart-contracts
Plutus
The Plutus language implementation and tools
Stars: ✭ 418 (+2100%)
Mutual labels:  smart-contracts
Skycoin
Skycoin Core and Wallet
Stars: ✭ 549 (+2789.47%)
Mutual labels:  smart-contracts
Snax
Decentralized Social Media Overlay
Stars: ✭ 18 (-5.26%)
Mutual labels:  smart-contracts
Oyente
An Analysis Tool for Smart Contracts
Stars: ✭ 820 (+4215.79%)
Mutual labels:  smart-contracts
Go Apla
A blockchain platform with a simplified programming language
Stars: ✭ 625 (+3189.47%)
Mutual labels:  smart-contracts

sscjs Build Status

Light javascript library to interact with the JSON RPC server of a Steem Smart Contracts node

Installation

Via npm

For node.js or the browser with browserify or webpack.

npm install sscjs

From a cdn or self-hosted script

Grab dist/ssc.min.js from a release and include in your html:

<script src="ssc.min.js"></script>

or from the jsdelivr cdn:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ssc.min.js"></script>

Usage

In the browser

This library requires the axios library

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ssc.min.js"></script>
<script>
    const ssc = new SSC('https://testapi.steem-engine.com');
    ssc.getLatestBlockInfo((err, result) => {
		console.log(err, result);
	});
</script>

In node.js

const SSC = require('sscjs');

const ssc = new SSC('https://testapi.steem-engine.com');
ssc.stream((err, res) => {
	console.log(err, res);
});

Available methods

/**

* Get the information of a contract (owner, source code, etc...)

* @param  {String}  name contract name

* @param  {Function}  callback callback called if passed

* @returns  {Promise<JSON>} returns a promise if no callback passed

*/

getContractInfo(contract, callback  =  null)

// example
ssc.getContractInfo('tokens', (err, result) => {
	console.log(err, result);
	/*
	{
	    "name": "tokens",
	    "owner": "steemsc",
	    "code": "...source code of the contract...",
	    "tables": [
	        "tokens_tokens",
		...
	    ],
	    "$loki": 1
	}
	*/
})
/**

* retrieve a record from the table of a contract

* @param  {String}  contract contract name

* @param  {String}  table table name

* @param  {JSON}  query query to perform on the table

* @param  {Function}  callback callback called if passed

* @returns  {Promise<JSON>} returns a promise if no callback passed

*/

findOne(contract, table, query, callback  =  null)

// example
// See https://github.com/techfort/LokiJS/wiki/Query-Examples for the available params
ssc.findOne(
	'tokens', 
	'balances', 
	{ 
		account:  'harpagon' 
	}, (err, result) => {

	console.log(err, result);
	/*
	{
            "account": "harpagon",
            "symbol": "SSC",
            "balance": 3.0005,
            "$loki": 6
        }
	*/
})
/**
   * retrieve records from the table of a contract
   * @param {String} contract contract name
   * @param {String} table table name
   * @param {JSON} query query to perform on the table
   * @param {Integer} limit limit the number of records to retrieve
   * @param {Integer} offset offset applied to the records set
   * @param {Array<Object>} indexes array of index definitions { index: string, descending: boolean }
   * @param {Function} callback callback called if passed
   * @returns {Promise<JSON>} returns a promise if no callback passed
*/

find(contract, table, query, limit = 1000, offset = 0, indexes = [], callback = null) 

// example
// See https://github.com/techfort/LokiJS/wiki/Query-Examples for the available params

ssc.find('tokens', 'tokens', { }, 1000, 0, [], (err, result) => {
	console.log(err, result);
	/*
	[
	    	{
		    "issuer": "steemsc",
		    "symbol": "STEEMP",
		    "name": "STEEM Pegged",
		    "precision": 3,
		    "maxSupply": 1000000000000,
		    "supply": 1000000000000,
		    "$loki": 1
		},
		{
		    "issuer": "null",
		    "symbol": "SSC",
		    "name": "Steem Smart Contracts Token",
		    "url": "https://steemsmartcontracts.com",
		    "precision": 8,
		    "maxSupply": 1000000000000,
		    "supply": 250000000,
		    "$loki": 2
		},
	]
	*/
})
/**

* retrieve the latest block info of the sidechain

* @param  {Function}  callback callback called if passed

* @returns  {Promise<JSON>} returns a promise if no callback passed

*/

getLatestBlockInfo(callback  =  null)

// example
ssc.getLatestBlockInfo((err, result) => {
	console.log(err, result);
	/*
	{
	    "blockNumber": 12,
	    "refSteemBlockNumber": 25797141,
	    "previousHash": "9389c132270c7335b806a43bd063110fe3868015f96db80470bef2f48f1c2fcb",
	    "timestamp": "2018-09-09T02: 48: 48",
	    "transactions": [
	        {
	            "refSteemBlockNumber": 25797141,
	            "transactionId": "b299d24be543cd50369dbc83cf6ce10e2e8abc9b",
	            "sender": "smmarkettoken",
	            "contract": "smmkt",
	            "action": "updateBeneficiaries",
	            "payload": {
	                "beneficiaries": [
	                    "harpagon"
	                ],
	                "isSignedWithActiveKey": true
	            },
	            "hash": "ac33d2fcaf2d72477483ab1f2ed4bf3bb077cdb55d5371aa896e8f3fd034e6fd",
	            "logs": "{}"
	        }
	    ],
	    "hash": "e97e4b9a88b4ac5b8ed5f7806738052d565662eec962a0c0bbd171672a4a54d4",
	    "merkleRoot": "2f1221ae1938bc24f3ed593e8c57ea41882fedc5d31de21da9c9bd613360f3a6"
	}
	*/
})
/**

* retrieve the specified block info of the sidechain

* @param  {Number}  blockNumber block number

* @param  {Function}  callback callback called if passed

* @returns  {Promise<JSON>} returns a promise if no callback passed

*/

getBlockInfo(blockNumber, callback  =  null)

// example
ssc.getBlockInfo(12, (err, result) => {
	console.log(err, result);
	/*
	{
	    "blockNumber": 12,
	    "refSteemBlockNumber": 25797141,
	    "previousHash": "9389c132270c7335b806a43bd063110fe3868015f96db80470bef2f48f1c2fcb",
	    "timestamp": "2018-09-09T02: 48: 48",
	    "transactions": [
	        {
	            "refSteemBlockNumber": 25797141,
	            "transactionId": "b299d24be543cd50369dbc83cf6ce10e2e8abc9b",
	            "sender": "smmarkettoken",
	            "contract": "smmkt",
	            "action": "updateBeneficiaries",
	            "payload": {
	                "beneficiaries": [
	                    "harpagon"
	                ],
	                "isSignedWithActiveKey": true
	            },
	            "hash": "ac33d2fcaf2d72477483ab1f2ed4bf3bb077cdb55d5371aa896e8f3fd034e6fd",
	            "logs": "{}"
	        }
	    ],
	    "hash": "e97e4b9a88b4ac5b8ed5f7806738052d565662eec962a0c0bbd171672a4a54d4",
	    "merkleRoot": "2f1221ae1938bc24f3ed593e8c57ea41882fedc5d31de21da9c9bd613360f3a6"
	}
	*/
})
/**

* retrieve the specified transaction info of the sidechain

* @param  {String}  txid transaction id

* @param  {Function}  callback callback called if passed

* @returns  {Promise<JSON>} returns a promise if no callback passed

*/

getTransactionInfo(txid, callback  =  null)

// example
ssc.getTransactionInfo('b299d24be543cd50369dbc83cf6ce10e2e8abc9b', (err, result) => {
	console.log(err, result);
	/*
	{
	    "blockNumber": 12,
	    "refSteemBlockNumber": 25797141,
	    "transactionId": "b299d24be543cd50369dbc83cf6ce10e2e8abc9b",
	    "sender": "smmarkettoken",
	    "contract": "smmkt",
	    "action": "updateBeneficiaries",
	    "payload": {
		"beneficiaries": [
		    "harpagon"
		],
		"isSignedWithActiveKey": true
	    },
	    "hash": "ac33d2fcaf2d72477483ab1f2ed4bf3bb077cdb55d5371aa896e8f3fd034e6fd",
	    "logs": "{}"
	}
	*/
})
/**

* stream part of the sidechain

* @param  {Number}  startBlock the first block to retrieve

* @param  {Number}  endBlock if passed the stream will stop after the block is retrieved

* @param  {Function}  callback callback called everytime a block is retrieved

* @param  {Number}  pollingTime polling time, default 1 sec

*/

streamFromTo(startBlock, endBlock  =  null, callback, pollingTime  =  1000)

// example
ssc.streamFromTo(0, 12, (err, result) => {
	console.log(err, result);
	/*
	{
	    "blockNumber": 12,
	    "refSteemBlockNumber": 25797141,
	    "previousHash": "9389c132270c7335b806a43bd063110fe3868015f96db80470bef2f48f1c2fcb",
	    "timestamp": "2018-09-09T02: 48: 48",
	    "transactions": [
	        {
	            "refSteemBlockNumber": 25797141,
	            "transactionId": "b299d24be543cd50369dbc83cf6ce10e2e8abc9b",
	            "sender": "smmarkettoken",
	            "contract": "smmkt",
	            "action": "updateBeneficiaries",
	            "payload": {
	                "beneficiaries": [
	                    "harpagon"
	                ],
	                "isSignedWithActiveKey": true
	            },
	            "hash": "ac33d2fcaf2d72477483ab1f2ed4bf3bb077cdb55d5371aa896e8f3fd034e6fd",
	            "logs": "{}"
	        }
	    ],
	    "hash": "e97e4b9a88b4ac5b8ed5f7806738052d565662eec962a0c0bbd171672a4a54d4",
	    "merkleRoot": "2f1221ae1938bc24f3ed593e8c57ea41882fedc5d31de21da9c9bd613360f3a6"
	}
	*/
})
/**

* stream the sidechain (starting from the latest block produced)

* @param  {Function}  callback callback called everytime a block is retrieved

* @param  {Number}  pollingTime polling time, default 1 sec

*/

stream(callback, pollingTime  =  1000)

// example
ssc.stream((err, result) => {
	console.log(err, result);
	/*
	{
	    "blockNumber": 12,
	    "refSteemBlockNumber": 25797141,
	    "previousHash": "9389c132270c7335b806a43bd063110fe3868015f96db80470bef2f48f1c2fcb",
	    "timestamp": "2018-09-09T02: 48: 48",
	    "transactions": [
	        {
	            "refSteemBlockNumber": 25797141,
	            "transactionId": "b299d24be543cd50369dbc83cf6ce10e2e8abc9b",
	            "sender": "smmarkettoken",
	            "contract": "smmkt",
	            "action": "updateBeneficiaries",
	            "payload": {
	                "beneficiaries": [
	                    "harpagon"
	                ],
	                "isSignedWithActiveKey": true
	            },
	            "hash": "ac33d2fcaf2d72477483ab1f2ed4bf3bb077cdb55d5371aa896e8f3fd034e6fd",
	            "logs": "{}"
	        }
	    ],
	    "hash": "e97e4b9a88b4ac5b8ed5f7806738052d565662eec962a0c0bbd171672a4a54d4",
	    "merkleRoot": "2f1221ae1938bc24f3ed593e8c57ea41882fedc5d31de21da9c9bd613360f3a6"
	}
	*/
})
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].