Skip to content

Instantly share code, notes, and snippets.

View evias's full-sized avatar
👻
One man’s constant is another man’s variable.

Grégory Saive evias

👻
One man’s constant is another man’s variable.
View GitHub Profile
@evias
evias / read_credits.js
Last active May 29, 2017 22:27
NEM-sdk: Read Mosaics owned of a given account (Game Credits stored as Mosaic on the NEM Blockchain)
console.log("Hello, NEMber");
// Configure a Blockchain endpoint and include SDK
var NEM_HOST = "http://bob.nem.ninja"; // bob is Testnet!
var NEM_PORT = 7890;
var nem = require("nem-sdk").default;
var node = nem.model.objects.create("endpoint")(NEM_HOST, NEM_PORT);
// Issue the Mosaics request for the given Account (insert Player XEM address here)
nem.com.requests.account.mosaics(node, "TCTIMURL5LPKNJYF3OB3ACQVAXO3GK5IU2BJMPSU")
@evias
evias / read_scores.js
Created May 29, 2017 22:30
NEM-sdk: Read outgoing Transactions for a given Account (Scores stored as Mosaic Transfer Transactions)
console.log("Hello, NEMber");
// Configure a Blockchain endpoint and include SDK
var NEM_HOST = "http://bob.nem.ninja"; // bob is Testnet!
var NEM_PORT = 7890;
var nem = require("nem-sdk").default;
var node = nem.model.objects.create("endpoint")(NEM_HOST, NEM_PORT);
// Read Outgoing Transactions for the given game/application Account (pacnem-business)
nem.com.requests.account.outgoingTransactions(node, "TCTIMURL5LPKNJYF3OB3ACQVAXO3GK5IU2BJMPSU")
@evias
evias / save_score.js
Created May 29, 2017 22:32
NEM-sdk: Send a Multi Signature Mosaic Transfer Transaction (Save a High Score as a Mosaic Transfer Transaction on the NEM Blockchain)
console.log("Hello, NEMber");
// Configure a Blockchain endpoint and include SDK
var NEM_HOST = "http://bob.nem.ninja"; // bob is Testnet!
var NEM_PORT = 7890;
var nem = require("nem-sdk").default;
var node = nem.model.objects.create("endpoint")(NEM_HOST, NEM_PORT);
// Define the player data
var playerXEM = "TATKHV5JJTQXCUCXPXH2WPHLAYE73REUMGDOZKUW";
@evias
evias / nem_sdk_last_block.js
Last active August 26, 2018 11:22
retrieve last block from the NEM blockchain using the Node.js NEM-sdk
// include the NEM-sdk package in your package.json first.
// nem-sdk: npmjs.com/package/nem-sdk
let nem_ = require("nem-sdk").default;
let connectedNode = nem_.model.objects.create("endpoint")("http://bigalice2.nem.ninja", "7890");
nem_.com.requests.chain.lastBlock(connectedNode)
.then(function(err, block)
{
if (! err && block) {
@evias
evias / nem_sdk_read_transactions.js
Last active July 29, 2017 12:26
read all outgoing transactions of a given Wallet with Node.js and the NEM-sdk
/**
* Class OutgoingTransactionStream can be used to read
* outgoing transactions of a given NEM Account.
*
* This class is kept quite simple and only defines a
* function to read *all* outgoing transactions of an
* account.
*
* @param {Object} sdk use `require('nem-sdk').default`
* @param {Object} endpoint
@evias
evias / nem_sdk_interpret_mosaic_transfer.js
Last active July 30, 2017 12:13
Interpret a Mosaic Transfer Transaction on the NEM blockchain with Node.js and NEM-sdk
// nem-sdk: npmjs.com/package/nem-sdk
// class OutgoingTransactionStream from gist: https://gist.github.com/evias/aea14ff6bea618239ca21a7f3802773e.js
let sdk = require("nem-sdk").default;
/**
* The Transaction class defines some utilities methods to keep
* reading data from NEM Transactions organized a little bit.
*
* @param {Object} transactionMetaDataPair Transaction object received in NIS response
@evias
evias / nem-convert-to-multisig.js
Created April 12, 2018 16:31
NEM-SDK@1.6.2: Convert Account to Multisig
let endpoint = {
'host': 'http://bigalice2.nem.ninja',
'port': 7890
};
let networkId = -104;
let privateKeyOfAccountToConvert = "PRIV_KEY_HEX_ACCOUNT_TO_CONVERT";
let privateKeyOfCosig = "PRIV_KEY_HEX_ACCOUNT_SINGLE_COSIG";
let kpc = sdk.crypto.keyPair.create(privateKeyOfAccountToConvert);
@evias
evias / composer.json
Last active June 19, 2018 11:18
PHP KeyPair Creation - Case Reproduction
{
"require": {
"php": ">=5.5.9",
"evias/nem-php": "dev-master",
"kornrunner/keccak": "@dev"
},
"require-dev": {
},
"autoload": {
"classmap": [
@evias
evias / nem-sdk-v1.6.2.js
Last active December 27, 2018 04:40
nem-sdk-v1.6.2.js
This file has been truncated, but you can view the full file.
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var _helpers = require('../../utils/helpers');
var _helpers2 = _interopRequireDefault(_helpers);
var _headers = require('./headers');
var _headers2 = _interopRequireDefault(_headers);
@evias
evias / nem-php-broadcast_tx.php
Last active October 31, 2018 15:12
nem-php: broadcast transaction
<?php
use NEM\API;
use NEM\Models\MosaicAttachments;
use NEM\Models\MosaicAttachment;
use NEM\Models\Mosaic;
use NEM\Models\Transaction\Transfer;
use NEM\Infrastructure\Transaction as TransactionService;
// prepare the transaction