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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
// buyer - puts the funds in the account | |
// arbiter - ability to move the funds | |
// recipient - receiver of the funds | |
// ERC20s common standard for tokens | |
interface IWethGateway { |
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
// https://goerli.etherscan.io/address/0xa423c1448d195d9cf2e06d343e30b35f501159ed | |
contract First { | |
event Winner(address); | |
function test() external { | |
emit Winner(msg.sender); | |
} | |
} | |
// https://goerli.etherscan.io/address/0x9a9a776bc00eb386fb56bb3a57e6b78595d93bf3 |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
contract HelloWorld { | |
bool public success; | |
function doTheMath(uint _x, uint _y) external { | |
require(_x + _y == 42); | |
require(_x > 0 && _y > 0); | |
success = true; |
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 EC = require('elliptic').ec; | |
const ec = new EC('secp256k1'); | |
// private/public key pair generation | |
const key = ec.genKeyPair(); | |
// to public key hex string (04...) | |
const hexPublicKey = key.getPublic().encode('hex'); | |
// from hex string back to the elliptic key object (this key can verify) |
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
// For learning purposes only! | |
// Don't pollute the Array prototype in an application | |
// map synonym | |
Array.prototype.transform = function(callback) { | |
const newArr = []; | |
for(let i = 0; i < this.length; i++) { | |
newArr.push(callback(this[i])); | |
} | |
return newArr; |
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
class MerkleTree { | |
constructor(leaves, concat) { | |
this.leaves = leaves; | |
this.concat = concat; | |
} | |
getProof(index, leaves = this.leaves, proof = []) { | |
if (leaves.length === 1) { | |
return proof; | |
} | |
let newLayer = []; |
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 SHA256 = require('crypto-js/sha256'); | |
const TARGET_DIFFICULTY = BigInt(0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); | |
const MAX_TRANSACTIONS = 10; | |
const mempool = []; | |
const blocks = []; | |
function addTransaction(transaction) { | |
mempool.push(transaction); | |
} |
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 ethers = require('ethers'); | |
const provider = ethers.getDefaultProvider('kovan'); | |
const CONTACT_ADDR = "0xae4b4bda19d53178ebbad7737ba34beaa0107c18"; | |
const ABI = [ | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "activeLength", | |
"outputs": [ |
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
{ | |
"difficulty": "0x153886c1bbd", | |
"extraData": "0x657468706f6f6c2e6f7267", | |
"gasLimit": "0x520b", | |
"gasUsed": "0x5208", | |
"hash": "0x4e3a3754410177e6937ef1f84bba68ea139e8d1a2258c5f85db9f1cd715a1bdd", | |
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | |
"miner": "0xe6a7a1d47ff21b6321162aea7c6cb457d5476bca", | |
"mixHash": "0xb48c515a9dde8d346c3337ea520aa995a4738bb595495506125449c1149d6cf4", | |
"nonce": "0xba4f8ecd18aab215", |
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
function verifyProof(proof, node, root, concat) { | |
for(let i = 0; i < proof.length; i++) { | |
let { left, data } = proof[i]; | |
if(left) { | |
node = concat(data, node); | |
} | |
else { | |
node = concat(node, data); | |
} | |
} |
NewerOlder