Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new account #29

Closed
soulCorw opened this issue Sep 12, 2018 · 4 comments
Closed

new account #29

soulCorw opened this issue Sep 12, 2018 · 4 comments
Labels
question Further information is requested

Comments

@soulCorw
Copy link

Can have an example of creating a new account?

@matijakregar
Copy link

matijakregar commented Sep 12, 2018

Here's an example for a password protected keystore called EthereumKeystoreV3 ... you'll need to sort out the optionals and preferably remove the fatalError calls.

//First you need a `KeystoreManager` instance:
guard let userDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first,
    let keystoreManager = KeystoreManager.managerForPath(userDirectory + "/keystore")
else {
    fatalError("Couldn't create a KeystoreManager.")
}

//Next you create the a new Keystore:

let newKeystore = try? EthereumKeystoreV3(password: "YOUR_PASSWORD")

// Then you save the created keystore to the file system:

let newKeystoreJSON = try? JSONEncoder().encode(newKeystore.keystoreParams)
FileManager.default.createFile(atPath: "\(keystoreManager.path)/keystore.json", contents: newKeystoreJSON, attributes: nil)

// Later you can retreive it:

if let address = keystoreManager.addresses?.first,
let retrievedKeystore = keystoreManager.walletForAddress(address) as? EthereumKeystoreV3 {
    return retrievedKeystore
}

@shamatar
Copy link
Contributor

shamatar commented Sep 13, 2018

Now there is an example in README how to create it, will also add how to attach it and why

@skywinder skywinder added the question Further information is requested label Sep 17, 2018
@skywinder
Copy link
Collaborator

thanks, @matijakregar for great example

Btw, here is "How to create account" example in readme: https://github.com/matterinc/web3swift#create-account

@BaldyAsh
Copy link
Collaborator

It seems that the issue is resolved, so its closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants