Skip to content

Instantly share code, notes, and snippets.

View CHAOWEICHIU's full-sized avatar
🎯
Focusing

Wayne Chiu CHAOWEICHIU

🎯
Focusing
View GitHub Profile
pragma solidity ^0.5.0;
contract DonationContract {
address payable[] public donationList = [
0x8A1DfD12b5B0D28296a14076D5Da56a97216B929
];
function multiTransfer() public payable {
uint256 amount = msg.value / donationList.length;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20Detailed.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract CustomToken is ERC20, ERC20Detailed {
constructor () public ERC20Detailed("陳之汗😓", "SWEAT", 0) {
_mint(_msgSender(), 100 * (10 ** uint256(decimals())));
}
}
@CHAOWEICHIU
CHAOWEICHIU / private_public_key.js
Created September 24, 2019 23:29
getting public key from private key using javascript
/* Requirement node: v8.10.0 */
const Wallet = require('ethereumjs-wallet');
const EthUtil = require('ethereumjs-util');
const keyPrivate = '0x61ce8b95ca5fd6f55cd97ac60817777bdf64f1670e903758ce53efc32c3dffeb'
const keyPublic = 'fff49b58b83104ff16875452852466a46c7169ba4e368d11830c9170624e0a9509080a05a38c18841718ea4fc13483ac467d3e2d728d41ff16b73b9c943734f8'
const privateKeyBuffer = EthUtil.toBuffer(keyPrivate);
const wallet = Wallet.fromPrivateKey(privateKeyBuffer);
@CHAOWEICHIU
CHAOWEICHIU / install.sh
Created September 23, 2019 02:41
cloud9 needed script
git clone https://github.com/Homebrew/brew ~/.linuxbrew/Homebrew
mkdir ~/.linuxbrew/bin
ln -s ../Homebrew/bin/brew ~/.linuxbrew/bin
eval $(~/.linuxbrew/bin/brew shellenv)
# Uninstall the older version of SAM Local
npm uninstall -g aws-sam-local
# Uninstall the older version of SAM CLI
pip uninstall aws-sam-cli
import * as functions from "firebase-functions";
import * as express from "express";
const { ApolloServer, gql } = require("apollo-server-express");
require("graphql");
const typeDefs = gql`
type Query {
hello: String
}
`;
@CHAOWEICHIU
CHAOWEICHIU / storyblok_upload_asset.js
Last active June 13, 2019 04:21
example code uploading asset to storyblok
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const file = './test.txt';
const accessToken = 'YOUR_PERSONAL_ACCESS_TOKEN'; // Can be found at https://app.storyblok.com/#!/me/account
const spaceId = 'YOUR_SPACE_ID';
const fileUpload = function (signed_request, success, failed) {
const form = new FormData();
pragma solidity ^0.5.2;
pragma experimental ABIEncoderV2;
contract RandPicker {
address payable public owner;
uint public entryFee = 0;
uint public pickOneFee = 0;
uint public namePurposeFee = 0;
@CHAOWEICHIU
CHAOWEICHIU / RandPicker.sol
Last active November 8, 2019 05:29
RandPicker Solution
pragma solidity ^0.5.2;
pragma experimental ABIEncoderV2;
contract RandPicker {
address payable public owner;
uint public entryFee = 0;
uint public pickOneFee = 0;
uint public namePurposeFee = 0;
// Node Version: 10.15.1
// NPM Version: 6.8.0
const Web3 = require('web3'); // Version: 1.0.0-beta.37
const EthereumTx = require('ethereumjs-tx'); // Version: 1.3.7
const web3 = new Web3('http://testnet.dexon.org:8545');
const myAddress = '0x89c24a88BaD4abE0A4F5b2EB5a86db1fb323832C';
const myPrivateKey = Buffer.from('61ce8b95ca5fd6f55cd97ac60817777bdf64f1670e903758ce53efc32c3dffeb', 'hex');
const message = 'DEXON-DS';
@CHAOWEICHIU
CHAOWEICHIU / downloadEncryptedZipFile.js
Last active March 8, 2019 00:04
implementation for storing encrypted zip file on the blockchain - 2/2 download and decrypt
const fetch = require('node-fetch')
const EthCrypto = require('eth-crypto')
const FileSaver = require('file-saver')
const { binaryStringToBlob } = require('blob-util')
const keyPrivate = '0x61ce8b95ca5fd6f55cd97ac60817777bdf64f1670e903758ce53efc32c3dffeb'
const keyPublic = 'fff49b58b83104ff16875452852466a46c7169ba4e368d11830c9170624e0a9509080a05a38c18841718ea4fc13483ac467d3e2d728d41ff16b73b9c943734f8'
const hashFromSmartContract = 'Qme9JXnWExQLxXS5U1Hd1QdbTCNBQqAiVy5UrR3dwZxmmU' // a zip file contains a image
function encryptStringWithPublicKey({ message, publicKey }) {