Convert Figma logo to code with AI

trustwallet logowallet-core

Cross-platform, cross-blockchain wallet library.

2,765
1,558
2,765
42

Top Related Projects

:lock: Trezor Firmware Monorepo

78,260

Bitcoin Core integration/staging tree

Go implementation of the Ethereum protocol

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites

a free (libre) open source, mobile OS for Ethereum

Quick Overview

Wallet Core is a cross-platform library that implements low-level cryptographic operations for all blockchains supported by Trust Wallet. It provides a consistent interface for developers to interact with various cryptocurrencies, enabling secure key management, address generation, and transaction signing across multiple platforms.

Pros

  • Cross-platform support (iOS, Android, and any platform that supports C++)
  • Extensive blockchain support with a unified API
  • Strong focus on security and audited codebase
  • Active development and community support

Cons

  • Steep learning curve for newcomers to blockchain development
  • Limited documentation for some advanced features
  • Requires careful integration to ensure security best practices
  • May be overkill for simple blockchain applications

Code Examples

  1. Generating a wallet:
#include <TrustWalletCore/TWHDWallet.h>

auto wallet = TWHDWalletCreate(128, "");
auto mnemonic = TWHDWalletMnemonic(wallet);
  1. Creating a Bitcoin address:
#include <TrustWalletCore/TWBitcoinAddress.h>

auto address = TWBitcoinAddressCreateWithString("1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2");
auto addressString = TWBitcoinAddressDescription(address);
  1. Signing an Ethereum transaction:
#include <TrustWalletCore/TWEthereumSigner.h>

auto input = TWEthereumSigningInput();
input.chainId = 1;
input.nonce = 9;
input.gasPrice = 20000000000;
input.gasLimit = 21000;
input.toAddress = "0x3535353535353535353535353535353535353535";
input.amount = 1000000000000000000;

auto key = TWPrivateKeyCreateWithData(privateKeyData);
input.privateKey = TWPrivateKeyData(key);

auto output = TWEthereumSignerSign(&input);
auto signedTx = TWEthereumSignerSignedTx(output);

Getting Started

  1. Add Wallet Core to your project:

    • For iOS: Use CocoaPods and add pod 'TrustWalletCore' to your Podfile
    • For Android: Add implementation 'com.trustwallet:wallet-core:x.y.z' to your build.gradle
  2. Import the necessary headers:

#include <TrustWalletCore/TWHDWallet.h>
#include <TrustWalletCore/TWCoinType.h>
  1. Initialize a wallet and generate an address:
auto wallet = TWHDWalletCreate(128, "");
auto key = TWHDWalletGetKeyForCoin(wallet, TWCoinTypeBitcoin);
auto address = TWCoinTypeDeriveAddress(TWCoinTypeBitcoin, key);
  1. Use the generated address in your application.

Competitor Comparisons

:lock: Trezor Firmware Monorepo

Pros of Trezor-firmware

  • Focused on hardware wallet security, providing robust protection for private keys
  • Supports a wide range of cryptocurrencies and tokens
  • Open-source firmware allows for community audits and contributions

Cons of Trezor-firmware

  • Limited to Trezor hardware devices, less flexible for other wallet types
  • May have a steeper learning curve for developers not familiar with hardware wallets

Code Comparison

Trezor-firmware (Python):

def derive_node_without_passphrase(
    path: list[int], curve_name: str = "secp256k1"
) -> bip32.HDNode:
    node = bip32.from_seed(mnemonic.get_seed(), curve_name)
    node.derive_path(path)
    return node

Wallet-core (C++):

HDWallet::HDWallet(int strength, const std::string& passphrase)
    : entropy(Data(strength / 8)) {
    std::random_device rd;
    std::generate(entropy.begin(), entropy.end(), std::ref(rd));
    mnemonic = Mnemonic::generateMnemonic(entropy);
    seed = Mnemonic::generateSeed(mnemonic, passphrase);
    setSecret(seed);
}

Both repositories focus on cryptocurrency wallet functionality, but Trezor-firmware is specifically designed for hardware wallets, while Wallet-core provides a more general-purpose solution for software wallets. Trezor-firmware's code emphasizes secure key derivation, while Wallet-core's example shows wallet creation with mnemonic generation.

78,260

Bitcoin Core integration/staging tree

Pros of Bitcoin

  • Larger and more established community with extensive documentation
  • Focused solely on Bitcoin, providing deep expertise in this specific cryptocurrency
  • More comprehensive test suite and rigorous code review process

Cons of Bitcoin

  • Limited to Bitcoin-specific functionality
  • Steeper learning curve for developers new to cryptocurrency
  • Slower development cycle due to its size and importance in the ecosystem

Code Comparison

Bitcoin (C++):

CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
    int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
    // Force block reward to zero when right shift is undefined.
    if (halvings >= 64)
        return 0;

Wallet Core (C++):

Data Signer::sign() const {
    auto key = PrivateKey(privateKey);
    auto pubKey = key.getPublicKey(TWPublicKeyTypeSECP256k1);
    return sign(key, pubKey);
}

Summary

Bitcoin is a specialized repository focused solely on Bitcoin, with a large community and extensive testing. Wallet Core, on the other hand, is a multi-cryptocurrency wallet implementation that supports various blockchain networks. Bitcoin offers deeper Bitcoin-specific expertise, while Wallet Core provides broader cryptocurrency support. The code examples demonstrate Bitcoin's focus on block rewards and mining, whereas Wallet Core emphasizes general cryptographic operations for multiple cryptocurrencies.

Go implementation of the Ethereum protocol

Pros of go-ethereum

  • Full Ethereum node implementation, offering complete blockchain functionality
  • Extensive documentation and community support
  • Widely used and battle-tested in production environments

Cons of go-ethereum

  • Larger codebase and resource requirements
  • Steeper learning curve for developers new to Ethereum
  • Focused primarily on Ethereum, limiting multi-chain support

Code Comparison

go-ethereum (Ethereum client implementation):

func (s *Ethereum) Start() error {
    // Start up the node
    err := s.node.Start()
    if err != nil {
        return err
    }
    // Start the blockchain
    s.blockchain.Start()
    return nil
}

wallet-core (Multi-chain wallet implementation):

bool Wallet::startBlockchain(const std::string& coin) {
    auto blockchain = BlockchainFactory::createBlockchain(coin);
    if (!blockchain) {
        return false;
    }
    blockchains[coin] = std::move(blockchain);
    return true;
}

The code snippets demonstrate the different focus of each project. go-ethereum initializes a full Ethereum node, while wallet-core provides a more generic approach for supporting multiple blockchains in a wallet context.

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites

Pros of metamask-extension

  • Larger community and more extensive documentation
  • Browser-based, offering seamless web3 integration
  • Regular updates and active development

Cons of metamask-extension

  • Limited to Ethereum and EVM-compatible chains
  • Higher complexity due to browser extension architecture
  • Potential security risks associated with browser-based wallets

Code Comparison

metamask-extension:

const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const contract = new ethers.Contract(address, abi, signer);

wallet-core:

auto wallet = HDWallet(mnemonic, passphrase);
auto key = wallet.getKey(TWCoinTypeEthereum, derivationPath);
auto address = key.getAddressString();

metamask-extension focuses on browser integration and user interface, while wallet-core provides a lower-level, multi-chain core for wallet development. The metamask-extension code snippet demonstrates interaction with Ethereum using ethers.js, whereas wallet-core's example shows key derivation and address generation in C++.

Both repositories serve different purposes: metamask-extension is a complete browser-based wallet solution, while wallet-core is a foundational library for building multi-chain wallets. The choice between them depends on the specific requirements of the project and the desired level of customization and control over the wallet implementation.

a free (libre) open source, mobile OS for Ethereum

Pros of Status-mobile

  • More comprehensive mobile app functionality, including messaging and social features
  • Broader ecosystem integration with Ethereum and decentralized applications
  • Active development with frequent updates and community engagement

Cons of Status-mobile

  • Larger codebase and potentially more complex to maintain
  • Specific to mobile platforms, less versatile for different wallet types
  • May have a steeper learning curve for developers new to the project

Code Comparison

Status-mobile (React Native):

import React from 'react';
import { View, Text } from 'react-native';
import { connect } from 'react-redux';

const WalletScreen = ({ balance }) => (
  <View>
    <Text>Balance: {balance}</Text>
  </View>
);

Wallet-core (C++):

#include <TrustWalletCore/TWHDWallet.h>
#include <TrustWalletCore/TWCoinType.h>

auto wallet = TWHDWalletCreateWithMnemonic(mnemonic);
auto address = TWHDWalletGetAddressForCoin(wallet, TWCoinTypeEthereum);

Status-mobile is a full-featured mobile application with a focus on social and messaging features integrated with cryptocurrency functionality. It uses React Native for cross-platform development. Wallet-core, on the other hand, is a lower-level library providing core wallet functionality in C++, which can be integrated into various wallet applications. Status-mobile offers a more complete user-facing solution, while Wallet-core provides flexibility for developers to build custom wallet applications across different platforms.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Trust Wallet Core is an open-source, cross-platform, mobile-focused library implementing low-level cryptographic wallet functionality for a high number of blockchains. It is a core part of the popular Trust Wallet, and some other projects. Most of the code is C++ with a set of strict C interfaces, and idiomatic interfaces for supported languages: Swift for iOS and Java (Kotlin) for Android.

iOS CI Android CI Linux CI Rust CI Wasm CI Kotlin CI Docker CI Quality Gate Status

Gitpod Ready-to-Code GitHub GitHub release (latest by date) SPM Cocoapods

Documentation

For comprehensive documentation, see developer.trustwallet.com.

Audit Reports

Security Audit reports can be found in the audit directory.

Supported Blockchains

Wallet Core supports more than 130 blockchains: Bitcoin, Ethereum, BNB, Cosmos, Solana, and most major blockchain platforms. The full list is here.

Building

For build instructions, see developer.trustwallet.com/wallet-core/building.

Using from your project

If you want to use wallet core in your project follow these instructions.

Android

Android releases are hosted on GitHub packages, you need to add GitHub access token to install it. Please check out this installation guide or build.gradle from our android sample

Don't forget replacing the version in the code with latest: GitHub release (latest by date)

iOS

We currently support Swift Package Manager and CocoaPods (will discontinue in the future).

SPM

Download latest Package.swift from GitHub Releases 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"),

CocoaPods

Add this line to your Podfile and run pod install:

pod 'TrustWalletCore'

NPM (beta)

npm install @trustwallet/wallet-core

Go (beta)

Please check out the Go integration sample.

Kotlin Multipleplatform (beta)

Please check out the Kotlin Multiplatform sample

Projects

Projects using Trust Wallet Core. Add yours too!

Trust Wallet

Coinpaprika | crypto.com | Frontier | Tokenary | MemesWallet | xPortal | Slingshot | ECOIN Wallet

Community

There are a few community-maintained projects that extend Wallet Core to some additional platforms and languages. Note this is not an endorsement, please do your own research before using them:

Contributing

The best way to submit feedback and report bugs related to WalletCore is to open a GitHub issue. If the bug is not related to WalletCore but to the TrustWallet app, please create a Customer Support ticket. If you want to contribute code please see Contributing. If you want to add support for a new blockchain also see Adding Support for a New Blockchain, make sure you have read the requirements section.

Thanks to all the people who contribute.

Disclaimer

The Wallet Core project is led and managed by Trust Wallet with a large contributor community and actively used in several projects. Our goal at Wallet Core is to give other wallets an easy way to add chain support.

Trust Wallet products leverage wallet core, however, they may or may not leverage all the capabilities, features, and assets available in wallet core due to their own product requirements.

License

Trust Wallet Core is available under the Apache 2.0 license. See the LICENSE file for more info.