Skip to content

Instantly share code, notes, and snippets.

MiniMeToken

MiniMeToken does not use Truffle framework.

Directory structure

project
│───build
│───contracts
│───js
└───test

Truffle docs

Creating Project

> mkdir MetaCoin
> cd MetaCoin
> truffle unbox metacoin
  • library를 사용하면 modular, reusable elegant한 contract를 짤 수 있다.

Solidity is a limited language

  • standard library가 아직 개발되지 않았다.
  • deployed contract는 업그레이드할 수 없다.
  • EVM 외부에서 data를 가져올 수 없다. 이는 Oracle을 포함하는 트랜잭션을 날려야만 가능하다.

What is a Library

  • library는 contract와는 다른 type이다.

Onward with Ethereum Smart Contract Security

before starting

smart contract security를 improve해주는 전략과 이 전략을 따르지 않았을 때 문제가 발생할 수 있는 코드를 함께 제시한다. 또한 smart contract를 protect할 수 있는 방법에 대한 코드도 함께 제시한다.

Fail as early and loudly as possible

  • code가 silently하게 fail하는 것을 피해야 한다. 또한 unstable하거나 inconsistent한 state로 실행이 계속되는 것을 피해야 한다.

참고

sending a transaction costs 21000 gas

A recipient contract's fallback function only gets a 2300 gas stipend if it was invoked with recipient.transfer or recipient.send

fallback 함수가 호출되는 여러 경우가 있는데 그 중 receiver.send 함수 또는 receiver.transfer 함수로 인해 receiver의 fallback 함수가 호출된다. 이 때 fallback 함수 호출과 함께 2300gas를 봉급으로 주어지게 된다.

This is the same as an external account paying recipient with web3.eth.sendTransaction({to:recipient, gas:21000, ...}).

Infura

Infura is a hosted Ethereum node cluster that lets your users run your application without requiring them to set up their own Ethereum node or wallet. Infura behaves just like a local install of Ethereum running RPC.

For security reasons, Infura does not manage your private keys, which means infura cannot sign transactions on your behalf.

However, Truffle can sign transactions through the use of its HDWalletProvider. This provider can handle the transaction signing as well as the connection to the Ethereum network.

Install HDWalletProvider:

Parity Multisig Hacked

address of sender

contract A {
    B b;

    function A(address _b) public {
        b = B(_b);
    }
pragma solidity ^0.4.24;
contract Storage {
uint256 n;
function setN(uint256 _n) public {
n = _n;
}
function getN() public view returns(uint256) {
web3.eth.accounts
const owner = web3.eth.accounts[0]
owner
moment = require('moment')
const expireDates = [moment().add(100, 'minutes').unix(), moment().add(200, 'minutes').unix(),]
let token1, token2
HanwhaToken.new('HanwhaToken1', 'HWT1', '18', expireDates, {from: owner}).then(instance => token1 = instance)
HanwhaToken.new('HanwhaToken2', 'HWT2', '18', expireDates, {from: owner}).then(instance => token2 = instance)