create account

[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3 by anpigon

View this thread on: hive.blogpeakd.comecency.com
· @anpigon · (edited)
$1.66
[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3
![](https://steemitimages.com/640x0/https://cdn.steemitimages.com/720x0/https://cdn.steemitimages.com/DQmTBYPHABLZoXJMWL9msssEoTsXz9LvVaK7dT49uXXGQi7/galaxy-2.png)



이번에는 니모닉으로 지갑키(PrivateKet)와 지갑주소를 생성합니다. 지갑주소는 공개키(PublicKey)에서 계산됩니다. 

<br><center>* * *</center><br>

# ethereumjs-util 라이브러리 설치

이더리움 주소를 계산하기 위해 아래 라이브러리를 설치합니다.

```bash
$ npm install --save ethereumjs-util
```

&nbsp;

이더리움 지갑키와 주소 계산에 필요한 라이브러리를 import 합니다.

```jsx
import bip32 from 'bip32';
import ethUtil from 'ethereumjs-util';
```

&nbsp;

마지막으로 `CreateWalletScreen.js`를 수정합니다.

```jsx
export default class CreateWalletScreen extends Component {

  // (...)

  _createWallet = async () => {
    const seed = bip39.mnemonicToSeed(this.state.mnemonic);
    // 마스터 키 생성
    const root = bip32.fromSeed(seed);
    // 이더리움 차일드 개인키 생성
    const xPrivKey = root.derivePath("m/44'/60'/0'/0/0");
    const privKey = xPrivKey.privateKey.toString('hex');
    // 이더리움 주소 생성
    let address = ethUtil.pubToAddress(xPrivKey.publicKey, true).toString('hex');
    // 이더리움 EIP-55 체크섬 주소로 변환
    address = ethUtil.toChecksumAddress(address).toString('hex');
    alert(address);
  }

  render() {
    return (
      <Container style={styles.container}>
        <View style={{ flex: 1, padding: 10 }}>
          <View style={{ flex: 1 }}>
            {/* (...) */}
          </View>
          <View style={{ flex: 1 }}>
            <Button block primary
              onPress={() => this._createWallet()}>
              <Text>생성하기</Text>
            </Button>
          </View>
        </View>
      </Container>
    );
  }
}
```

> 1. 지갑 생성하는 `_createWallet()` 함수를 생성합니다. 그리고 생성하기 버튼의 `onPress` 속성에 `{() => this._createWallet()}`를 입력합니다. 이제 생성하기 버튼을 누르면 `_createWallet()` 함수를 호출할 것입니다.
> 2. `_createWallet()` 함수는 니모닉에서 시드(*SEED*) 를 계산합니다.
> 3. 그리고 [BIP-32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki)를 사용하여 시드에서 확장 개인키(*HDPrivateKey*)를 계산합니다.
> 4. 그다음 **HDPrivateKey**에서 이더리움 **PrivateKey**를 계산합니다. 이더리움 **PrivateKey는** [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)에 따라 생성(derivation) 됩니다. 그리고 **derivePath**는 이와 같은 형태입니다.  `m/purpose'/coin_type'/account'/change/address_index` 
>   우리는 HD지갑이 목적이 아니므로 단순하게 `m/44'/60'/0'/0/0`를 사용하여 지갑키를 생성합니다.
> 5. 마지막으로 공개키(PublicKey)에서 주소를 계산합니다. 그리고 [EIP-55](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md) 규칙에 따라 체크섬이 포함된 주소로 변환합니다.

&nbsp;

이제 생성 버튼을 누르면 아래와 같이 지갑 주소가 생성됩니다. 확인하기 쉽게 **Alert** 으로 출력하였습니다.

![](https://cdn.steemitimages.com/300x0/https://cdn.steemitimages.com/DQmNpZzkAyNvbWbU6RtKkgEt4XwbrkvNahB4HhAXoUR8SG7/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202019-02-03%2016.11.31.png)

&nbsp;

이더리움 모바일 지갑앱 개발을 하면서, 개발 과정을 정리하여 포스팅까지 하려니 시간이 2~3배 정도 걸리네요.

여기까지 읽어주셔서 감사합니다.



👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authoranpigon
permlinkreact-native-ethereum-mobile-wallet-3
categorykr
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["kr","kr-dev","busy","jjangjjangman","ethereum"],"links":["https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki","https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki","https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md"],"image":["https://steemitimages.com/640x0/https://cdn.steemitimages.com/720x0/https://cdn.steemitimages.com/DQmTBYPHABLZoXJMWL9msssEoTsXz9LvVaK7dT49uXXGQi7/galaxy-2.png","https://cdn.steemitimages.com/300x0/https://cdn.steemitimages.com/DQmNpZzkAyNvbWbU6RtKkgEt4XwbrkvNahB4HhAXoUR8SG7/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202019-02-03%2016.11.31.png"],"users":[]}
created2019-02-04 02:00:21
last_update2019-02-04 05:51:33
depth0
children7
last_payout2019-02-11 02:00:21
cashout_time1969-12-31 23:59:59
total_payout_value1.295 HBD
curator_payout_value0.368 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,798
author_reputation17,258,940,000,931
root_title"[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,364,110
net_rshares3,555,510,443,317
author_curate_reward""
vote details (38)
@bukio ·
짱짱맨 호출에 응답하여 보팅하였습니다. 
properties (22)
authorbukio
permlinkre-bukio-jjangjjangman-1549246548286
categorykr
json_metadata"{"tags":["bukio", "jjangjjangman"],"app":"steemer/1.0"}"
created2019-02-04 02:15:48
last_update2019-02-04 02:15:48
depth1
children1
last_payout2019-02-11 02:15:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length22
author_reputation11,545,563,591,097
root_title"[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,364,514
net_rshares0
@anpigon ·
감사합니다.
properties (22)
authoranpigon
permlinkre-bukio-re-bukio-jjangjjangman-1549246548286-20190204t055245048z
categorykr
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["kr"],"users":[],"links":[],"image":[]}
created2019-02-04 05:52:48
last_update2019-02-04 05:52:48
depth2
children0
last_payout2019-02-11 05:52:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6
author_reputation17,258,940,000,931
root_title"[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,370,294
net_rshares0
@codingman ·
대단하네요
properties (22)
authorcodingman
permlinkre-anpigon-react-native-ethereum-mobile-wallet-3-20190204t112759748z
categorykr
json_metadata{"tags":["kr"],"app":"steemit/0.1"}
created2019-02-04 11:28:00
last_update2019-02-04 11:28:00
depth1
children0
last_payout2019-02-11 11:28:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5
author_reputation23,188,231,710,844
root_title"[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,379,905
net_rshares0
@gomdory ·
![](https://ipfs.busy.org/ipfs/QmSpSf3UTPCZUwCEfi1sWKKcUXWKH3SnpEaYaqRuWu7omz)
properties (22)
authorgomdory
permlinkre-react-native-ethereum-mobile-wallet-3-20190204t104713
categorykr
json_metadata""
created2019-02-04 10:47:15
last_update2019-02-04 10:47:15
depth1
children0
last_payout2019-02-11 10:47:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length78
author_reputation38,104,394,235,725
root_title"[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,378,661
net_rshares0
@ravenkim ·
멋지세요^^ 이더리움 지갑을 직접 만드시다니 대단하세요👍👍
properties (22)
authorravenkim
permlinkre-anpigon-react-native-ethereum-mobile-wallet-3-20190204t022554114z
categorykr
json_metadata{"tags":["kr"],"app":"steemit/0.1"}
created2019-02-04 02:25:57
last_update2019-02-04 02:25:57
depth1
children1
last_payout2019-02-11 02:25:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length32
author_reputation107,302,486,367,072
root_title"[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,364,805
net_rshares0
@anpigon ·
감사합니다. 지갑앱 만드는 개발 과정을 공개함으로써, 다양한 형태의 모바일앱이 출시되었으면 좋겠습니다. 
properties (22)
authoranpigon
permlinkre-ravenkim-re-anpigon-react-native-ethereum-mobile-wallet-3-20190204t055234141z
categorykr
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["kr"],"users":[],"links":[],"image":[]}
created2019-02-04 05:52:36
last_update2019-02-04 05:52:36
depth2
children0
last_payout2019-02-11 05:52:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length58
author_reputation17,258,940,000,931
root_title"[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,370,291
net_rshares0
@steem-ua ·
#### Hi @anpigon!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your **UA** account score is currently 2.910 which ranks you at **#11533** across all Steem accounts.
Your rank has improved 6 places in the last three days (old rank 11539).

In our last Algorithmic Curation Round, consisting of 196 contributions, your post is ranked at **#83**.
##### Evaluation of your UA score:

* Only a few people are following you, try to convince more people with good work.
* The readers like your work!
* Good user engagement!


**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-react-native-ethereum-mobile-wallet-3-20190204t175227z
categorykr
json_metadata"{"app": "beem/0.20.18"}"
created2019-02-04 17:52:27
last_update2019-02-04 17:52:27
depth1
children0
last_payout2019-02-11 17:52:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length658
author_reputation23,214,230,978,060
root_title"[React Native] 이더리움 모바일 지갑(Ethereum Mobile Wallet) 만들기 #3"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,394,145
net_rshares0