import bip39 from 'react-native-bip39';
import bip32 from 'bip32';
import ethUtil from 'ethereumjs-util';
// import { ethers } from 'ethers';
// import { randomBytes } from 'react-native-randombytes'
export class CreateWalletScreen extends Component {
constructor(props) {
super(props);
this.state = {
mnemonic: null,
loading: false
}
}
componentDidMount = () => {
bip39.generateMnemonic().then(mnemonic => {
this.setState({ mnemonic })
});
}
_createWallet = async () => {
const seed = bip39.mnemonicToSeed(this.state.mnemonic);
const root = bip32.fromSeedSync(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');
address = ethUtil.toChecksumAddress(address).toString('hex');
alert(address);
}
render(){
return(
...
<Button onPress={() =>
this.createWallet()} />
...
)}
"react-native-bip39":"^2.3.0","bip32":"^2.0.5",
错误
在此处输入图像描述
由于我是一个初学者,我正在制作加密钱包。
使用bip库。
按下按钮应显示地址。
但我有麻烦了。该死的
如果你帮助我,人类的和平就会到来。
plz。。。
新错误
在此处输入图像描述
您的函数必须具有相同的调用名称:
<Button onPress={() =>
this._createWallet()} />