This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signature = signature.substr(2); //remove 0x | |
const r = '0x' + signature.slice(0, 64) | |
const s = '0x' + signature.slice(64, 128) | |
const v = '0x' + signature.slice(128, 130) | |
const v_decimal = web3.toDecimal(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3') | |
const provider = new Web3.providers.HttpProvider('http://localhost:8545') | |
const web3 = new Web3(provider) | |
function toHex(str) { | |
var hex = '' | |
for(var i=0;i<str.length;i++) { | |
hex += ''+str.charCodeAt(i).toString(16) | |
} | |
return hex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3') // Works with web3 1.0.0-beta27 | |
const contractArtifact = require('./build/contracts/TutorialToken.json') | |
const web3 = new Web3() | |
const providerUrl = 'ws://localhost:8545' // requires # https://github.com/trufflesuite/ganache-cli/releases/tag/v7.0.0-beta.0 or https://github.com/trufflesuite/ganache/releases/tag/v1.1.0-beta.0 | |
const provider = new Web3.providers.WebsocketProvider(providerUrl) | |
web3.setProvider(provider) | |
web3.eth.net.getId() | |
.then(networkId => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.8; | |
contract Verifier { | |
function recoverAddr(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (address) { | |
return ecrecover(msgHash, v, r, s); | |
} | |
function isSigned(address _addr, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (bool) { | |
return ecrecover(msgHash, v, r, s) == _addr; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
const SignVerifyArtifact = require('./contracts/SignAndVerifyExample') | |
const SignVerify = contract(SignVerifyArtifact) | |
SignVerify.setProvider(provider) | |
//... | |
SignVerify | |
.deployed() | |
.then(instance => { | |
let fixed_msg = `\x19Ethereum Signed Message:\n${msg.length}${msg}` | |
let fixed_msg_sha = web3.sha3(fixed_msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3') // Works with web3 0.20.4 | |
const contractArtifact = require('./build/contracts/TutorialToken.json') | |
const web3 = new Web3() | |
const providerUrl = 'http://localhost:8545' | |
const provider = new Web3.providers.HttpProvider(providerUrl) | |
web3.setProvider(provider) | |
const networkId = web3.version.network | |
const contractAddr = contractArtifact.networks[networkId].address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3') // Web3 0.20.4 or web3 1 beta | |
const truffleContract = require("truffle-contract") | |
const contractArtifact = require('./build/contracts/TutorialToken.json') | |
const providerUrl = 'http://localhost:8545' | |
const provider = new Web3.providers.HttpProvider(providerUrl) | |
const contract = truffleContract(contractArtifact) | |
contract.setProvider(provider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>JavaScript file upload</title> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<script src="https://wzrd.in/standalone/buffer"></script> | |
<script src="https://unpkg.com/ipfs-api@9.0.0/dist/index.js" | |
integrity="sha384-5bXRcW9kyxxnSMbOoHzraqa7Z0PQWIao+cgeg327zit1hz5LZCEbIMx/LWKPReuB" | |
crossorigin="anonymous"></script> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.18; | |
contract D { | |
uint public n; | |
address public sender; | |
function callSetN(address _e, uint _n) public { | |
_e.call(bytes4(keccak256("setN(uint256)")), _n); // E's storage is set, D is not modified | |
} | |
function callcodeSetN(address _e, uint _n) public { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const graphqlHTTP = require('express-graphql') | |
const Web3 = require('web3') | |
const TFcontract = require('truffle-contract') | |
const MetaCoinArtifact = require('./build/contracts/Metacoin') | |
const MetCoinContract = TFcontract(MetaCoinArtifact) | |
MetCoinContract.setProvider(new Web3.providers.HttpProvider('http://localhost:8545')) | |
const { genGraphQlProperties } = require('ethereum-to-graphql') |
NewerOlder