Skip to content

Getting Started ​

This guide will walk you through integrating the Turing Wallet browser API into your DApp from scratch.

Prerequisites ​

  • A front-end project (React, Vue, Vanilla JS, etc.)
  • Users of your DApp need the Turing Wallet browser extension or mobile app installed

Access the Wallet API ​

The wallet extension injects the Turing global object into the page. No package installation is required.

ts
if (!window.Turing) {
  throw new Error("Turing Wallet is not installed");
}

const addresses = await window.Turing.connect();

Minimal DApp Example ​

Here is a complete end-to-end flow — detect wallet → connect → get address → send a transaction:

ts
// 1. Connect to wallet
const addresses = await Turing.connect();
console.log("Connected:", addresses);
// BVM account: { tbcAddress, btcAddress }
// EVM account: { ethAddress, bnbAddress }

// 2. Check connection status
const connected = await Turing.isConnected();
console.log("Is connected:", connected);

// 3. Get wallet info
const { name, platform, version } = await Turing.getInfo();
console.log(`Wallet: ${name} v${version} on ${platform}`);

// 4. Get public key
const { tbcPubKey } = await Turing.getPubKey();
console.log("Public key:", tbcPubKey);

// 5. Send a simple P2PKH transaction
try {
  const { txid, error } = await Turing.sendTransaction([
    {
      flag: "P2PKH",
      address: "recipient_tbc_address_here",
      satoshis: 10000,
      broadcastEnabled: true,
    },
  ]);

  if (txid) {
    console.log("Transaction sent! txid:", txid);
  }
  if (error) {
    console.error("Transaction failed:", error);
  }
} catch (err) {
  console.error("Unexpected error:", err);
}

// 6. Disconnect when done
await Turing.disconnect();

Supported Chains ​

Turing Wallet is a multi-chain wallet. Different API methods target different chains:

ChainMethodsAddress Format
TBC (Turing BitChain)sendTransaction, signTransaction, signAssociatedTransaction, sendBatchRequesttbcAddress
BTC (Bitcoin)btc.sendTransaction, btc.signTransaction, btc.sendBatchRequestbtcAddress
Ethereumevm.sendTransactionethAddress
BSCevm.sendTransactionbnbAddress

Error Handling ​

Most API methods return an error field on failure rather than throwing exceptions. Always check for errors:

ts
const result = await Turing.sendTransaction(params);

if (result.error) {
  // Handle the error — display to user, retry, etc.
  console.error("Error:", result.error);
  return;
}

// Success path
console.log("txid:", result.txid);

For methods like signMessage, encrypt, and decrypt, errors are thrown as exceptions. Wrap these in try-catch:

ts
try {
  const { sig } = await Turing.signMessage({
    message: "hello",
    encoding: "utf-8",
  });
} catch (error) {
  console.error("Signing failed:", error);
}

Offline Signing (broadcastEnabled) ​

Many transaction methods support a broadcastEnabled parameter:

  • true (default) — The wallet signs and broadcasts the transaction, returning txid.
  • false — For non-Merge requests, the wallet returns the requested business transaction as txraw for you to broadcast.

The dedicated FT_MERGE, STABLECOIN_MERGE, POOLNFT_MERGE, and FTLP_MERGE requests always broadcast and return txid. If a non-Merge business operation returns multiple raw transactions, handle them in order.

ts
// Get raw signed transaction without broadcasting
const { txraw } = await Turing.sendTransaction([
  {
    flag: "P2PKH",
    address: "recipient_address",
    satoshis: 10000,
    broadcastEnabled: false,
  },
]);

// Broadcast later via your own node / API

Next Steps ​

Now that you have the basics, explore the full API: