Boilertalk / Web3.swift

A pure swift Ethereum Web3 library
MIT License
643 stars 189 forks source link

Create and Import Accounts #46

Closed GabCas closed 6 years ago

GabCas commented 6 years ago

Is there a way to create and/or import accounts? from: http://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#create I'm looking for:

koraykoska commented 6 years ago

Yes there is. You have to create a new private key with the default initializer of EthereumPrivateKey and then use the keystore library to create a keystore 'account'.
Please visit the keystore repository for examples. But to create the raw private key which you have to do first you can use Web3. Here is an example:

import Web3

let privateKey = EthereumPrivateKey()
let privateKeyBytes = privateKey.rawPrivateKey       // Use this with the keystore.swift library to create your account.
GabCas commented 6 years ago

Thank you, that worked. I was able to create a keystore account and extract the private key.
Is it normal that each step takes around 45 seconds? Granted, I'm using an iPhone 5 with iOS 10.

koraykoska commented 6 years ago

Hey @GabCas

Long keystore creation and private key extraction times are only normal in debug builds. Once you build it for production (with speed optimizations, which is default for iOS production builds) it should be 50 to 60 times faster. I am already using it in a system which generates 'a few' per second even on older iPhones.

On Tue, Jul 3, 2018, 21:31 GabCas notifications@github.com wrote:

Closed #46 https://github.com/Boilertalk/Web3.swift/issues/46.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/Boilertalk/Web3.swift/issues/46#event-1714853674, or mute the thread https://github.com/notifications/unsubscribe-auth/AK1JzZ0sOKZaYKRGMk7xohNCfdSHw5Ujks5uC8aNgaJpZM4VBBtP .