Zapit Connect (Deprecated)
Zapit Connect is Deprecated and no longer supported from v0.8.14 onwards, Please use our WalletConnect Interface to connect with Zapit Wallet.
The Zapit Wallet Chrome Extension offers a seamless and secure way to manage Bitcoin Cash (BCH) transactions directly within your web browser. With its intuitive and powerful interface, this extension serves as a user-friendly Bitcoin Cash wallet, allowing you to connect to the Zapit service and perform various blockchain operations. Whether you're a developer looking to integrate BCH functionality into your web application or an end user wanting to manage your BCH holdings with ease, the Zapit Wallet Chrome Extension provides the necessary tools to streamline your experience.
Getting Started
Installing the extension
Install the Zapit chrome extension at the chrome web store
This Zapit Chrome Extension exposes a set of well-defined APIs that empower developers to interact with the Zapit service seamlessly. From connecting to the service and managing addresses to signing transactions and messages, the Zapit connect API offers a comprehensive suite of functionalities to cater to various Bitcoin Cash use cases.
Key Features
- Event Handling: The extension employs event listeners to ensure efficient and reactive communication. The
on
,once
, andoff
methods facilitate the integration of event-driven behavior within your applications. - Connecting to Zapit: Use the
connect
method to establish a connection with the Zapit service. This enables you to interact with your BCH holdings and perform blockchain-related tasks. - Managing Addresses: The
address
method retrieves the BCH address associated with the connected account, allowing you to easily access and display this crucial information. - Checking Connection Status: The
connected
method verifies whether your extension is currently connected to the Zapit service. This ensures that you have the most up-to-date information at your disposal. - Disconnecting: If needed, the
disconnect
method severs the connection to the Zapit service, providing you with control over your extension's access to your BCH account. - Transaction Signing: Utilize the
signTransaction
method to securely sign BCH transactions, complete with customizable options like source outputs and user prompts. - Message Signing: The
signMessage
method allows you to sign messages with your BCH account, enabling cryptographic proof of message ownership.
Methods
on(event, callback, options)
once(event, callback, options)
off(event, callback)
connect()
address()
connected()
disconnect()
signTransaction({ transaction, sourceOutputs, broadcast, userPrompt })
signMessage({ message, userPrompt })
on(event, callback, options)
Adds an event listener for the specified event.
event
(string): The name of the event to listen for.callback
(function): The function to be called when the event is triggered.options
(object, optional): An object containing options for the event listener.
Example:
window.zapit.on('addressChanged', (event) => {
console.log('Address changed:', event.detail);
});
once(event, callback, options)
Adds an event listener that will be triggered only once for the specified event.
event
(string): The name of the event to listen for.callback
(function): The function to be called when the event is triggered.options
(object, optional): An object containing options for the event listener.
Example:
window.zapit.once('addressChanged', (event) => {
console.log('Address changed:', event.detail);
});
off(event)
Removes an event listener for the specified event.
event
(string): The name of the event for which the listener should be removed.callback
(function): The original callback function passed toon
oronce
.
Example:
window.zapit.off('addressChanged');
connect()
Initiates a connection to the background service for blockchain-related tasks. It dispatches an "addressChanged" event when the connection is successful.
Returns: A promise that resolves to the blockchain address response.
Example:
const response = await window.zapit.connect();
console.log('Connected to blockchain. Address:', response.bchAddress);
address()
Retrieves the blockchain address associated with the current origin.
Returns: A promise that resolves to the blockchain address.
Example:
const blockchainAddress = await window.zapit.address();
console.log('Current blockchain address:', blockchainAddress);
connected()
Checks if the connection to the background service is established.
Returns: A promise that resolves to a boolean indicating the connection status.
Example:
const isConnected = await window.zapit.connected();
console.log('Is connected to blockchain:', isConnected);
disconnect()
Disconnects from the background service and resets the blockchain address.
Example:
window.zapit.disconnect();
console.log('Disconnected from blockchain.');
signTransaction({ transaction, sourceOutputs, broadcast, userPrompt })
Requests the background service to sign a blockchain transaction.
transaction
(object): The transaction data to be signed.sourceOutputs
(array): Array of source outputs.broadcast
(boolean): Whether to broadcast the transaction.userPrompt
(string): User prompt for the transaction.
const transactionData = { /* ... */ };
const response = await window.zapit.signTransaction({
transaction: transactionData,
sourceOutputs: [],
broadcast: true,
userPrompt: 'Please confirm the transaction.',
});
console.log('Signed transaction:', response);
Example Usage
const zapitInstance = window.zapit;
zapitInstance.on("addressChanged", (event) => {
console.log("Address changed:", event.detail);
});
(async () => {
const isConnected = await zapitInstance.connected();
if (!isConnected) {
await zapitInstance.connect();
}
const address = await zapitInstance.address();
console.log("Connected address:", address);
const transaction = /* ... */;
const response = await zapitInstance.signTransaction({ transaction, /* ... */ });
console.log("Transaction response:", response);
const message = /* ... */;
const messageResponse = await zapitInstance.signMessage({ message, /* ... */ });
console.log("Message response:", messageResponse);
})();