Integration APIAll Javascript methods to interact with the wallet
Copy declare global {
interface Window {
xidar: {
v1: {
hasWallet: () => Promise<boolean>
isConnected: () => Promise<boolean>
connect: () => Promise<string>
disconnect: () => Promise<{code: number}>
sign: (challenge: string) => Promise<string>
submitTransaction: (payload: {}) => Promise<any>
encrypt: (message: string, fromAddress: string, toAddress: string) => Promise<string>
decrypt: (message: string, fromAddress: string) => Promise<string>
accounts: () => Promise<string[]>
balances: () => Promise<{}>
stakes: () => Promise<{}>
unstakes: () => Promise<{}>
}
}
}
}
hasWallet()
This function allows you to know if the user has the wallet installed and initialized. Returns true or false.
Copy hasWallet: () => Promise<boolean>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
//Do code...
}
isConnected()
This function allows you to know if the user's wallet is synchronized with the current domain name. Returns true or false.
Copy isConnected: () => Promise<boolean>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
//Do code...
}
}
connect()
This function allows the website to be synchronized with the user's wallet. Ask for permissions if the user has not already accepted. Returns the active address of the user or null.
Copy connect: () => Promise<string>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const activeAddress = await window.xidar.v1.connect();
if (activeAddress) {
// Do code
}
}
disconnect()
This function allows to disconnect the website from the user's wallet.
Copy disconnect: () => Promise<{code: number}>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
const disconnectResult = await window.xidar.v1.disconnect();
}
}
sign()
This function allows you to sign a message with the private key of the active address of the user's wallet. Returns the signed message.
Copy sign: (challenge: string) => Promise<string>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
const signedMessage = await window.xidar.v1.sign('Here is my message');
}
}
submitTransaction()
This function allows you to send a transaction with the user's active wallet address. Return the transaction ID.
Copy submitTransaction: (payload: {}) => Promise<any>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
const activeAddress = await window.xidar.v1.connect();
const transaction = await window.xidar.v1.submitTransaction({
"actions": [
{
"type": "TransferTokens",
"from_account": {
"address": activeAddress
},
"to_account": {
"address": "rdx1qsp3q5gpep5x2la7q87paqf8yla43krz0lageax8svsjnq9fmfswgfcyhd8pm"
},
"amount": {
"token_identifier": {
"rri": "xrd_rr1qy5wfsfh"
},
"value": "100000000000000000000"
}
}
],
"message": "Message example",
"encryptMessage": false
});
const transactionID = transaction.txID
}
}
encrypt()
This function allows you to encrypt a message with the the user's active wallet address. Returns the encrypted message.
Copy encrypt: (message: string, fromAddress: string, toAddress: string) => Promise<string>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
const activeAddress = await window.xidar.v1.connect();
const encryptedMessage = await window.xidar.v1.encrypt(
'Here is my message',
activeAddress,
"rdx1qsp3q5gpep5x2la7q87paqf8yla43krz0lageax8svsjnq9fmfswgfcyhd8pm"
);
}
}
decrypt()
This function allows you to decrypt a message with the the user's active wallet address. Returns the decrypted message.
Copy decrypt: (message: string, fromAddress: string) => Promise<string>
Copy
const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
const decryptedMessage = await window.xidar.v1.decrypt(
'01ff022c6b5987523d48d3ac9e329114cac862fa8b9c442806b0b4431dcce8055d75c183f2d1e3298325f5089f1b2a9bbfa7ca7efeb860049941db4f5dca332b35a7a6de5664a1b131ffc5af80a6915eb7',
"rdx1qsp3q5gpep5x2la7q87paqf8yla43krz0lageax8svsjnq9fmfswgfcyhd8pm"
);
}
}
accounts()
This function allows you to retrieve the list of all the addresses of the user's wallet. Return an array of addresses.
Copy accounts: () => Promise<string[]>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
const addresses = await window.xidar.v1.accounts();
}
}
balances()
This function allows you to retrieve balances of the user's active wallet address. Returns an array of tokens informations.
Copy balances: () => Promise<{}>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
const balances = await window.xidar.v1.balances();
}
}
stakes()
This function allows you to retrieve staking positions of the user's active wallet address. Returns an array of staking positions.
Copy stakes: () => Promise<{}>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
const stakes = await window.xidar.v1.stakes();
}
}
unstakes()
This function allows you to retrieve unstaking positions of the user's active wallet address. Returns an array of unstaking positions.
Copy unstakes: () => Promise<{}>
Copy const hasWallet = await window.xidar.v1.hasWallet();
if (hasWallet) {
const isConnected = await window.xidar.v1.isConnected();
if (isConnected) {
const unstakes = await window.xidar.v1.unstakes();
}
}