Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

how to create account on rinkby and store account in keystore? #287

Open
Gagan6696 opened this issue Mar 1, 2019 · 7 comments
Open

how to create account on rinkby and store account in keystore? #287

Gagan6696 opened this issue Mar 1, 2019 · 7 comments

Comments

@Gagan6696
Copy link

Gagan6696 commented Mar 1, 2019

i succesfully connect with local and do transection. Now i want to shift my code to rinkby network. is we have to manually create account on rinkby and store into keystore??

@v57
Copy link
Contributor

v57 commented Mar 1, 2019

You can generate account from mnemonics.

let mnemonics = Mnemonics()
print(mnemonics.string, BIP32Keystore(mnemonics: mnemonics).addresses[0])

Then request some ether on Rinkeby Faucet. https://faucet.rinkeby.io

@Gagan6696
Copy link
Author

Hello @v57
i succesfully created account using metamask and also i request ether and succesfully i got some ether .Now i want to send ether on another account. But gives error
"Failed to locally sign a transaction"
So my question is How to unlock accounts created by metamask and signed those account for transaction.

@v57
Copy link
Contributor

v57 commented Mar 4, 2019

If you have mnemonics from metamask then you can load all your accounts

do {
  // Setting default Web3 provider (rinkeby)
  Web3.default = Web3(infura: .rinkeby)
  
  let mnemonics = try Mnemonics("devote tourist cube waste bicycle season kiss century hood bamboo combine allow dry antenna axis wave wish skill wrong seminar melt economy crawl talent")
  let password = "yourPassword"
  let numberOfYourAccounts = 10
  let keystore = try BIP32Keystore(mnemonics: mnemonics, password: password)
  
  // loading child accounts
  for _ in 1..<numberOfYourAccounts {
    try keystore.createNewChildAccount(password: password)
  }
  
  // adding your keystore to the default keystore manager
  Web3.default.keystoreManager.append(keystore)
  
  // sending some ether from one of your accounts
  let sender = keystore.addresses[0]
  let recipient = keystore.addresses[1]
  let amount = BigUInt("0.001", units: .eth)!
  
  // setting transaction options
  var options = Web3Options.default
  options.from = sender
  // you don't need to set options.to and options.value here
  
  // sending transaction
  let transaction = try Web3.default.eth.sendETH(to: recipient, amount: amount).send(password: password, options: options)
  // printing transaction hash
  print("transaction hash: \(transaction.hash.hex)")
} catch {
  print(error)
}

@v57
Copy link
Contributor

v57 commented Mar 4, 2019

If you exported account in json format then:

let json = "your json"
if let keystore = EthereumKeystoreV3(json) {
  Web3.default.keystoreManager.append(keystore)
}

But you cannot create sub-accounts using this way

@Gagan6696
Copy link
Author

hello @v57
i just want to create account without any mnemonics .
Example--
user signup on app and using that details i want to create account or wallet?
is it possible?
if not how to create wallet for every user and how to generate diffirent mnemonics for evry user signup on my app?

@Gagan6696
Copy link
Author

Gagan6696 commented Mar 5, 2019

I think your library doesn't provide functionality of create account as provided by web3js.
Am i right?

@v57
Copy link
Contributor

v57 commented Mar 5, 2019

You can generate mnemonics and private keys by using

let mnemonics = Mnemonics()
let privateKey = PrivateKey()

If you want to use login/password as account, you can generate it by using:

let login = "SomeLogin"
let password = "SomePassword"
let privateKey = (login + password).sha256()

But you cannot restore password later

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants