This document is a work in progress
ARK Connect is a JavaScript API that enables communication with the ARK Connect platform via the window object. It provides methods to connect, disconnect, check connectivity status, retrieve network information, wallet address, balance, sign messages, sign transactions, and vote.
All API methods are exposed on a global window.arkconnect object that is injected into the page when the extension is active. Note that all requests can throw an ErrorResponse.
Requests the user to connect a domain to the extension
try {
const response = await window.arkconnect.connect();
} catch (error) {
// Handle connection error
}Determines whether the current domain is connected to the extension
try {
const response = await window.arkconnect.isConnected();
} catch (error) {
// Handle connection error
}Request the user to disconnect the current domain from the extension
try {
const response = await window.arkconnect.disconnect();
} catch (error) {
// Handle connection error
}Returns the version of the ARK Connect extension
const version = window.arkconnect.version();Returns a string representation of the network the currently connected address is on
try {
// Returns either 'Mainnet' or 'Devnet'
const response = await window.arkconnect.getNetwork();
} catch (error) {
// Handle connection error
}Returns a string representation of the currently connected address
try {
const response = await window.arkconnect.getAddress();
} catch (error) {
// Handle connection error
}Returns a string representation of the currently connected address' balance in ARK/DARK.
try {
const response = await window.arkconnect.getBalance();
} catch (error) {
// Handle connection error
}Request the user to sign a given message
type SignMessageRequest = {
message: string;
}
type SignMessageResponse = {
message: string;
signatory: string;
signature: string;
}
const messageRequest = {
message: 'The message you like to sign',
}
try {
const response = await window.arkconnect.signMessage(messageRequest);
} catch (error) {
// Handle connection error
}Request the user to sign a given transaction
type SignTransactionRequest = {
amount: number;
receiverAddress: string;
};
type SignTransactionResponse = {
id: string;
sender: string;
receiver: string;
exchangeCurrency: string;
amount: number;
convertedAmount: number;
fee: number;
convertedFee: BigNumber;
total: number;
convertedTotal: number;
};
const transactionRequest = {
amount: 100,
receiverAddress: 'D6Z26L69gdk9qYmTv5uzk3uGepigtHY4ax',
};
try {
const response = await window.arkconnect.signTransaction(transactionRequest);
} catch (error) {
// Handle connection error
}Request the user to sign a vote transaction (vote, unvote or vote swap)
type SignVoteRequest = {
vote?: {
amount: number;
address: string;
};
unvote?: {
amount: number;
address: string;
};
};
type SignVoteResponse = {
id: string;
sender: string;
voteAddress?: string;
voteName?: string;
votePublicKey?: string;
unvoteAddress?: string;
unvoteName?: string;
unvotePublicKey?: string;
exchangeCurrency: string;
exchangeCurrency: string;
fee: number;
convertedFee: number;
};
const voteRequest = {
vote: {
amount: 100,
address: 'DJmvhhiQFSrEQCq9FUxvcLcpcBjx7K3yLt',
},
};
try {
const response = await window.arkconnect.signVote(voteRequest);
} catch (error) {
// Handle connection error
}You can subscribe to events emitted by the extension to handle changes as the occur. The following list of events are currently available.
Emitted when an address connects to the domain
window.arkconnect?.on('connected', (data) => {
// Handle data: { type: 'connected' }
});Emitted when an address disconnects from the domain
window.arkconnect?.on('disconnected', (data) => {
// Handle data: { type: 'disconnected' }
});Emitted when the primary address in the extension changes
window.arkconnect?.on('addressChanged', (data) => {
// Handle data: { type: 'addressChanged', data: { wallet: { network: 'Mainnet|Devnet', address: <string>, coin: 'ARK' } } }
});Emitted when the extension locks / unlocks
window.arkconnect?.on('lockToggled', (data) => {
// Handle data: { type: 'lockToggled', data: { isLocked: boolean } }
});The error response that can be returned by the API calls
type ErrorResponse = {
status: 'failed';
domain: string;
message: string;
tabId: number;
};