Skip to content

Instantly share code, notes, and snippets.

View michielmulders's full-sized avatar

Michiel Mulders michielmulders

View GitHub Profile
@michielmulders
michielmulders / main.js
Created December 28, 2017 14:47
Build Your Own Blockchain with JavaScript
const SHA256 = require('crypto-js/sha256');
class Block {
constructor(index, timestamp, data, previousHash = '') {
this.index = index;
this.previousHash = previousHash;
this.timestamp = timestamp;
this.data = data;
this.hash = this.calculateHash();
this.nonce = 0;
@michielmulders
michielmulders / chaincode.go
Created February 14, 2018 18:44
Hyperledger Fabric getHistory Golang
func (t *SimpleChaincode) getHistoryForMarble(stub shim.ChaincodeStubInterface, args []string) sc.Response {
if len(args) < 1 {
return shim.Error("Incorrect number of arguments. Expecting 1")
}
marbleName := args[0]
fmt.Printf("- start getHistoryForMarble: %s\n", marbleName)
@michielmulders
michielmulders / erc777-burn.sol
Created February 17, 2018 23:45
ERC777 Burn implementation interface Ethereum
/// @notice Burns `_amount` tokens from `_tokenHolder`
/// Sample burn function to showcase the use of the `Burned` event.
/// @param _tokenHolder The address that will lose the tokens
/// @param _amount The quantity of tokens to burn
function burn(address _tokenHolder, uint256 _amount, bytes _userData, bytes _operatorData) public onlyOwner {
requireMultiple(_amount);
require(balanceOf(_tokenHolder) >= _amount);
mBalances[_tokenHolder] = mBalances[_tokenHolder].sub(_amount);
mTotalSupply = mTotalSupply.sub(_amount);
@michielmulders
michielmulders / stellar-app.js
Last active February 9, 2022 01:27
Stellar Lumens JavaScript SDK
import express from 'express'
import bodyParser from 'body-parser'
import rp from 'request-promise'
import Stellar from 'stellar-sdk'
/* Initialize app and configure bodyParser */
const port = process.env.PORT || 4000
const app = express()
app.use(bodyParser.json())
@michielmulders
michielmulders / chaincode.go
Created March 5, 2018 14:23
Hyperledger not-complete chaincode example from Fabcar
// Define the Smart Contract structure
type SmartContract struct { }
// Define the car structure, with 4 properties.
type Car struct {
Make string `json:"make"`
Model string `json:"model"`
Colour string `json:"colour"`
Owner string `json:"owner"`
}
@michielmulders
michielmulders / nem-transfer.js
Created March 5, 2018 18:20
Nem Blockchain Transfer Transaction
// Include the library
var nem = require("../../build/index.js").default;
// Create an NIS endpoint object
var endpoint = nem.model.objects.create("endpoint")(nem.model.nodes.defaultTestnet, nem.model.nodes.defaultPort);
// Create a common object holding key
var common = nem.model.objects.create("common")("", "Private key");
// Create an un-prepared transfer transaction object
@michielmulders
michielmulders / erc223.sol
Created March 7, 2018 11:14
ERC223 New Transfer function
function transfer(address _to, uint _value, bytes _data) returns (bool success)
@michielmulders
michielmulders / cryptoconditions.js
Created March 28, 2018 07:49
BigchainDB crypto conditions
import { Router } from "express";
import logger from "logops";
import * as driver from "bigchaindb-driver";
import conn from "../helpers/bigchaindb";
const base58 = require("bs58");
const cryptoconditions = require("crypto-conditions");
const router = Router();
export default router;
@michielmulders
michielmulders / MyFirstToken.sol
Created March 30, 2018 11:22
My First Solidity ERC20 ERC223 Token
pragma solidity ^0.4.0;
interface ERC20 {
function transferFrom(address _from, address _to, uint _value) public returns (bool);
function approve(address _spender, uint _value) public returns (bool);
function allowance(address _owner, address _spender) public constant returns (uint);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
interface ERC223 {
@michielmulders
michielmulders / facetoken.sol
Created March 30, 2018 13:19
FaceToken ERC20 Full Contract Solidity Code
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;