Skip to content

Instantly share code, notes, and snippets.

View buddies2705's full-sized avatar
🏠
Working from home

Gaurav buddies2705

🏠
Working from home
  • Bangalore
View GitHub Profile
import Maker from '@makerdao/dai';
const infuraProjectId = 'c3f0f26a4c1742e0949d8eedfc47be67'; //dai.js project id
export const started = () => ({
type: 'STARTED'
});
export const makerCreated = () => ({
type: 'MAKER_CREATED'
});
dispatch(started());
const maker = Maker.create(process.env.REACT_APP_NETWORK, {
privateKey: process.env.REACT_APP_PRIVATE_KEY,
overrideMetamask: true,
provider: {
infuraProjectId
}
});
console.log('maker:', maker);
dispatch(makerCreated());
@buddies2705
buddies2705 / Fortune.sol
Last active May 7, 2019 08:46
Fortune Cookie Smart contract
pragma solidity ^0.4.10;
contract Fortune {
string[] public fortunes; // automatically generates an indexed getter (only)
function Fortune( string initialFortune ) public {
addFortune( initialFortune );
}
function addFortune( string fortune ) public {
pragma solidity >=0.4.24;
contract Timelock {
address public owner;
uint public releaseDate;
constructor( uint _days, uint _seconds ) public payable {
require( msg.value > 0, "There's no point in creating an empty Timelock!" );
owner = msg.sender;
releaseDate = now + (_days * 1 days) + (_seconds * 1 seconds);
@buddies2705
buddies2705 / SimpleToken.sol
Last active June 21, 2019 12:51
Simple ERC20 Token
pragma solidity ^0.4.2;
contract SimpleToken {
string public name = "Simple Token";
string public symbol = "SMPL";
uint256 public totalSupply;
event Transfer(
address indexed _from,
address indexed _to,
@buddies2705
buddies2705 / Wallet.sol
Created June 26, 2019 09:44
Wallet.sol
pragma solidity ^ 0.5.0;
import "zos-lib/contracts/Initializable.sol";
contract Wallet is Initializable {
address owner;
function initialize(address _owner) initializer public {
owner = _owner;
}

Create2

Vitalik originally proposed Create2 in EIP-1014. With Create2, developers can generate contract addresses without actually deploying a contract, and this allows reserving an address on Ethereum blockchain in a deterministic way.

Create vs. Create2 Create opcode uses the sender’s address and a nonce to generate a new address for the contract, this method does not provide a secure and deterministic way to reserve an address. Create2 uses an arbitrary address, a salt (random number) and contract creation code to generate an address. As these values are independent and fixed, this allows a secure way to compute addresses for future use.

@buddies2705
buddies2705 / pmlib.js
Created June 26, 2019 13:13
Using the ZeppelinOS programmatic library
'use strict';
// Required by zos-lib when running from truffle
global.artifacts = artifacts;
global.web3 = web3;
const { Contracts, SimpleProject, ZWeb3 } = require('zos-lib')
ZWeb3.initialize(web3.currentProvider)
Contracts.setArtifactsDefaults({
pragma solidity ^ 0.5.0;
import "zos-lib/contracts/Initializable.sol";
contract Wallet is Initializable {
address owner;
function initialize(address _owner) initializer public {
owner = _owner;
}
@buddies2705
buddies2705 / create2.md
Last active July 4, 2019 14:18
create2 md
id title
create2
Upgradable Create2 Contracts with zOS

Create2 opcode gives us the ability to calculate smart contracts addresses without actually deploying them on Ethereum blockchain. This opens up a lot of possibilities to improve user onboarding and scalability.

In this guide, we will create an upgradableWallet contract with a transfer method, then we will reserve an address using Create2 without actually deploying Wallet contract and send some ethers to this address. At last, we will actually deploy our Wallet contract and execute transfer method to transfer contract funds to another account.