Trust Developers
  • Get Started
  • Developing for Trust Wallet platform
    • Browser Extension
      • Ethereum & EVM chains
    • Mobile (WalletConnect)
    • Deep Linking
  • Listing new dApps
    • A Complete Guide to Listing your dApp with Trust Wallet
    • Optimizing your dApp for Trust Wallet
    • Debugging
  • Listing new assets
    • Add Asset
    • Requirements
    • Pull Request Fee
    • FAQ
    • Repository Details
    • Universal Asset ID
  • Wallet Core
    • New Blockchain Support
      • RPC / API Requirements
      • New EVM-compatible chain
    • Developing the Library
      • Contributing
      • Building
      • WalletConsole utility
      • Coverage
      • Releasing
    • Integration Guide
      • Usage Guide
      • iOS Integration Guide
      • Android Integration Guide
      • Server-Side
    • References
      • Swift API Reference
      • Kotlin API Reference
    • FAQ
  • Barz - Smart Wallet
    • Introducing Barz. TrustWallet's Smart Wallet Solution
    • Cutting Diamonds: How to make Accounts Awesome
    • Build with Trust Wallet and Barz, A Comprehensive Guide to Integrating Barz with AA SDK
Powered by GitBook
On this page
  • Prerequisites
  • Adding Library Dependency
  • Code Examples
  • Wallet Management
  • Account Address Derivation
  • Transaction Signing

Was this helpful?

  1. Wallet Core
  2. Integration Guide

iOS Integration Guide

PreviousUsage GuideNextAndroid Integration Guide

Last updated 2 years ago

Was this helpful?

Wallet Core is available on the iOS platform, it comes with Swift bindings. In this guide we show how to use it.

A sample application is available at: https://github.com/trustwallet/wallet-core/tree/master/samples/osx .

Prerequisites

  • . If you don't have it, install it by gem install cocoapods.

  • Xcode toolchain

  • Wallet Core library

Adding Library Dependency

An easy way to add Wallet Core dependency to an iOS project is through CocoaPods, like this (the exact version may change in the future):

  pod 'TrustWalletCore'

The dependency can be installed simply by pod install:

pod install

SPM is also supported, download latest Package.swift from and put it in a local WalletCore folder.

Add this line to the dependencies parameter in your Package.swift:

.package(name: "WalletCore", path: "../WalletCore"),

Or add remote url + master branch, it points to recent (not always latest) binary release.

.package(name: "WalletCore", url: "https://github.com/trustwallet/wallet-core", .branchItem("master")),

Then add libraries to target's dependencies:

.product(name: "WalletCore", package: "WalletCore"),
.product(name: "SwiftProtobuf", package: "WalletCore"),

Code Examples

Accessing Wallet Core functionality requires one import statement:

import WalletCore

Wallet Management

Creating or Importing a Multi-Coin HD Wallet

let wallet = HDWallet(strength: 128, passphrase: "")
let wallet = HDWallet(mnemonic: "ripple scissors kick mammal hire column oak again sun offer wealth tomorrow wagon turn fatal", passphrase: "")!

Account Address Derivation

Generating the Default Address for a Coin

let addressBTC = wallet.getAddressForCoin(coin: .bitcoin)
let addressETH = wallet.getAddressForCoin(coin: .ethereum)
let addressBNB = wallet.getAddressForCoin(coin: .binance)

Generating an Address Using a Custom Derivation Path (Expert)

let key = wallet.getKey(derivationPath: "m/44\'/60\'/1\'/0/0")   // m/44'/60'/1'/0/0
let address = CoinType.ethereum.deriveAddress(privateKey: key)

Transaction Signing

In general, when creating a new blockchain transaction, a wallet has to:

  1. Put together a transaction with relevant fields (source, target, amount, etc.)

  2. Sign the transaction, using the account private key. This is done by Wallet Core.

  3. Send to a node for broadcasting to the blockchain network.

Ethereum Transaction Signing

Code example to fill in signer input parameters, perform signing, and retrieve encoded result:

let signerInput = EthereumSigningInput.with {
    $0.chainID = Data(hexString: "01")!
    $0.gasPrice = Data(hexString: "d693a400")! // decimal 3600000000
    $0.gasLimit = Data(hexString: "5208")! // decimal 21000
    $0.toAddress = "0xC37054b3b48C3317082E7ba872d7753D13da4986"
    $0.transaction = EthereumTransaction.with {
       $0.transfer = EthereumTransaction.Transfer.with {
           $0.amount = Data(hexString: "0348bca5a16000")!
       }
    }
    $0.privateKey = wallet.getKeyForCoin(coin: .ethereum).data
}
let output: EthereumSigningOutput = AnySigner.sign(input: signerInput, coin: .ethereum)
print(" data:   ", output.encoded.hexString)

In the following sections we show code examples for some common funcions. Please refer to the for detailed explanations.

CocoaPods
GitHub Releases
Wallet Usage Guide