How to Use TokenCore: Your All-in-One Blockchain Library

Mar 13, 2022 | Blockchain

Welcome to the world of TokenCore! This powerful blockchain library is designed for seamless management of your wallets and signing transactions across multiple chains, specifically BTC, ETH, and EOS. In this guide, we’ll walk you through installing TokenCore, creating an identity, and signing transactions like a pro.

Installation

To get started with TokenCore, installation is a breeze using CocoaPods. Just follow these simple steps:

pod TokenCore, git: https://github.com/consenlabs/token-core-ios.git, branch: master

Running the Example

TokenCore comes with an example project that demonstrates wallet management and transaction signing. Note that EOS signing will be available soon, so keep an eye out for updates. To run the example:

$ cd Example
$ pod install

Trying Out the API

Before diving into wallet management, you’ll first need to set up an identity. This identity function will act like your secure vault across the three different chains. Let’s see how to create a new identity and derive wallets for Ethereum and Bitcoin.

var metadata = WalletMeta(source: .newIdentity)
metadata.network = Network.mainnet
metadata.segWit = .p2wpkh
metadata.name = MyFirstIdentity

let (mnemonic, identity) = try Identity.createIdentity(password: TestData.password, metadata: metadata)

let ethereumWallet = identity.wallets[0]
let bitcoinWallet = identity.wallets[1]

Think of this process as crafting a multi-tool: you are setting the foundation of your device (the identity) that will allow you to access different functions (the wallets) efficiently.

Exporting Your Wallet

Once you’ve created your wallet, you might want to export sensitive information like private keys and mnemonic phrases. Here’s how you can do that:

let prvKey = try WalletManager.exportPrivateKey(walletID: ethereumWallet.walletID, password: TestData.password)
print(PrivateKey: (prvKey))

let mnemonics = try WalletManager.exportMnemonic(walletID: ethereumWallet.walletID, password: TestData.password)
print(Mnemonic: (mnemonics))

let keystore = try WalletManager.exportKeystore(walletID: ethereumWallet.walletID, password: TestData.password)
print(Keystore: (keystore))

This step can be imagined as unlocking various cabinets in your vault to retrieve your essential items—private keys, mnemonic, and keystore. Here’s what you’re retrieving:

  • Private Key: A secret code that allows you to manage your assets.
  • Mnemonic: A set of words that can be used to recover your identity.
  • Keystore: A secure JSON file that stores your private key.

Signing Transactions

Now, let’s delve into the process of signing transactions. This is where you execute the magic of completing the process:

let signResult = WalletManager.ethSignTransaction(
    walletID: String,
    nonce: String,
    gasPrice: String,
    gasLimit: String,
    to: String,
    value: String,
    data: String,
    password: String,
    chainID: Int
)

let signedTx = signResult.signedTx
let txHash = signResult.txHash

Imagine you’re sending a letter. Signing a transaction is like applying your signature to ensure the recipient knows the message is authentic and comes from you. Upon signing, you generate a transaction hash (txHash), which you can use to trace the status of your transaction.

Troubleshooting

Running into issues? Here are some common troubleshooting steps:

  • If you’re using macOS 10.14 Mojave and Xcode 10, install the following:
    macOS_SDK_headers_for_macOS_10.14.pkg
    since Xcode command line tools may not install to /usr/include anymore.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

In Conclusion

In this article, we explored how to use TokenCore to manage wallets seamlessly across BTC, ETH, and EOS chains. As you dive into creating identities, exporting wallets, and signing transactions, may you find success in your blockchain endeavors!

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox