This file contains hidden or 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
contract MetaCoin { | |
//...Code | |
uint endTime; | |
//...Code | |
modifier onlyAfterDate() { | |
if(now <= endTime) { | |
throw; | |
} | |
_; | |
} |
This file contains hidden or 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 timeTravel = function (time) { | |
return new Promise((resolve, reject) => { | |
web3.currentProvider.sendAsync({ | |
jsonrpc: "2.0", | |
method: "evm_increaseTime", | |
params: [time], // 86400 is num seconds in day | |
id: new Date().getTime() | |
}, (err, result) => { | |
if(err){ return reject(err) } | |
return resolve(result) |
This file contains hidden or 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
it("should successfully call specialFn because enough time passed", async function () { | |
let meta = await MetaCoin.new(); | |
await timeTravel(86400 * 3) //3 days later | |
await mineBlock() // workaround for https://github.com/ethereumjs/testrpc/issues/336 | |
let status = await meta.specialFn.call(); | |
assert.equal(status, true, "specialFn should be callable after 1 day") | |
}) |
This file contains hidden or 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
it("should send coin correctly", function() { | |
var meta; | |
// Get initial balances of first and second account. | |
var account_one = accounts[0]; | |
var account_two = accounts[1]; | |
var account_one_starting_balance; | |
var account_two_starting_balance; | |
var account_one_ending_balance; |
This file contains hidden or 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
it("should send coin correctly", async function () { | |
// Get initial balances of first and second account. | |
var account_one = accounts[0]; | |
var account_two = accounts[1]; | |
var amount = 10; | |
let meta = await MetaCoin.deployed(); | |
let balance1 = await meta.getBalance.call(account_one); | |
let balance2 = await meta.getBalance.call(account_two); |
This file contains hidden or 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 blacklist = require('./blacklist') | |
const levenshtein = require('fast-levenshtein') | |
const math = require('mathjs') | |
const comparison = 'myetherwallet' | |
const allScores = blacklist.map(item => { | |
return { | |
domain: item, | |
score: levenshtein.get(item.replace(/\./g,''), comparison) | |
} |
This file contains hidden or 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/[email protected]/dist/index.js" | |
integrity="sha384-5bXRcW9kyxxnSMbOoHzraqa7Z0PQWIao+cgeg327zit1hz5LZCEbIMx/LWKPReuB" | |
crossorigin="anonymous"></script> | |
</head> |
This file contains hidden or 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 fs = require('fs') | |
const ethereumURL = 'http://0.0.0.0:8545' | |
const provider = new Web3.providers.HttpProvider(ethereumURL) | |
const web3 = new Web3(provider) | |
const contractInfo = JSON.parse(fs.readFileSync('./MetaCoinABI.js', 'utf8')) | |
const MyContract = web3.eth.contract(contractInfo.abi); | |
const contractInstance = MyContract.at(contractInfo.address); |
This file contains hidden or 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 MyContract { | |
event Transfer(address indexed from, address indexed to, uint256 value); /* This is an event */ | |
function MyContract() {} /* a constructor */ | |
function transfer(address _to) public { | |
Transfer(msg.sender, _to, msg.value); |
This file contains hidden or 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) |