Skip to content

Instantly share code, notes, and snippets.

@hm0429
Created April 30, 2018 06:17
Show Gist options
  • Save hm0429/7f34c1e4839ac3f7a40dc3f09a0a0eaf to your computer and use it in GitHub Desktop.
Save hm0429/7f34c1e4839ac3f7a40dc3f09a0a0eaf to your computer and use it in GitHub Desktop.
iOS で Ethereum のアカウントを作成
import Geth
// keystore ファイルを保存するディレクトリのパスを取得
let dataDir = NSSearchPathForDirectoriesInDomains(.documentDirectory,
.userDomainMask,
true)[0]
let keyStorePath = dataDir + "/keystore"
print("keyStorePath: \(keyStorePath)")
// keystore を管理してくれるやつのインスタンスを取得
// keyStoreManager のほうが適切な名前ではないかな?
let keyStoreManager = GethNewKeyStore(keyStorePath, GethLightScryptN, GethLightScryptP)
// パスワードを指定してアカウントを作成
let account = try! keyStoreManager?.newAccount("password")
// 16進数表記のアカウントのアドレスを取得
let address = account?.getAddress().getHex()
print("address: \(address!)")
// keystore ファイルの URL (パス) を表示
let url = account?.getURL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment