MiniMeToken does not use Truffle framework.
project
│───build
│───contracts
│───js
└───test
smart contract security를 improve해주는 전략과 이 전략을 따르지 않았을 때 문제가 발생할 수 있는 코드를 함께 제시한다. 또한 smart contract를 protect할 수 있는 방법에 대한 코드도 함께 제시한다.
참고
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 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:
| 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) |