From 33e10dcb549ff12903c9130f9c8e1859e76c66ed Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Mon, 18 Mar 2024 10:57:38 +0700 Subject: [PATCH 01/14] chore: format docs --- developers/libraries-integration.md | 1 + developers/mobile-binance.md | 2 +- developers/mobile-bitcoin-cash.md | 2 +- developers/mobile-bitcoin.md | 2 +- developers/mobile-cosmos.md | 2 +- developers/mobile-dogecoin.md | 2 +- developers/mobile-ethereum.md | 2 +- developers/mobile-litecoin.md | 2 +- developers/mobile-near.md | 2 +- developers/mobile-optimism.md | 2 +- developers/mobile-polygon.md | 2 +- developers/mobile-solana.md | 2 +- developers/mobile-terra.md | 2 +- developers/mobile-testnets.md | 2 +- developers/mobile-thorchain.md | 2 +- developers/mobile-zetachain.md | 2 +- routing/introduction.md | 1 + 17 files changed, 17 insertions(+), 15 deletions(-) diff --git a/developers/libraries-integration.md b/developers/libraries-integration.md index ba800bab6..6158696c0 100644 --- a/developers/libraries-integration.md +++ b/developers/libraries-integration.md @@ -6,6 +6,7 @@ next: text: "BlockNative" link: "./blocknative-xdefi-integration" --- + # Libraries Integration XDEFI Wallet is also integrated in a large panel of libraries to make it accessible to any developer's needs. diff --git a/developers/mobile-binance.md b/developers/mobile-binance.md index 6d16e770c..e03f51c60 100644 --- a/developers/mobile-binance.md +++ b/developers/mobile-binance.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-bitcoin-cash.md b/developers/mobile-bitcoin-cash.md index 6a08f4b24..0316f6850 100644 --- a/developers/mobile-bitcoin-cash.md +++ b/developers/mobile-bitcoin-cash.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-bitcoin.md b/developers/mobile-bitcoin.md index ebe38338e..a4da5dff1 100644 --- a/developers/mobile-bitcoin.md +++ b/developers/mobile-bitcoin.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-cosmos.md b/developers/mobile-cosmos.md index 7dac2c953..dcad509a3 100644 --- a/developers/mobile-cosmos.md +++ b/developers/mobile-cosmos.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-dogecoin.md b/developers/mobile-dogecoin.md index c2f028d44..0f70ea786 100644 --- a/developers/mobile-dogecoin.md +++ b/developers/mobile-dogecoin.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-ethereum.md b/developers/mobile-ethereum.md index 3db92c63d..9d4549fc7 100644 --- a/developers/mobile-ethereum.md +++ b/developers/mobile-ethereum.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-litecoin.md b/developers/mobile-litecoin.md index 361af321b..3c67e19ca 100644 --- a/developers/mobile-litecoin.md +++ b/developers/mobile-litecoin.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-near.md b/developers/mobile-near.md index 7ea1d23c8..8f8bb43b8 100644 --- a/developers/mobile-near.md +++ b/developers/mobile-near.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-optimism.md b/developers/mobile-optimism.md index 2f1b6696e..00eccd5a1 100644 --- a/developers/mobile-optimism.md +++ b/developers/mobile-optimism.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-polygon.md b/developers/mobile-polygon.md index 70cf6b95f..ac65491f6 100644 --- a/developers/mobile-polygon.md +++ b/developers/mobile-polygon.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-solana.md b/developers/mobile-solana.md index b783680cb..9d488076b 100644 --- a/developers/mobile-solana.md +++ b/developers/mobile-solana.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-terra.md b/developers/mobile-terra.md index 40f821bb3..1482b1284 100644 --- a/developers/mobile-terra.md +++ b/developers/mobile-terra.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-testnets.md b/developers/mobile-testnets.md index e77f70dfb..64497098b 100644 --- a/developers/mobile-testnets.md +++ b/developers/mobile-testnets.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-thorchain.md b/developers/mobile-thorchain.md index ccc6c692e..42ecdc227 100644 --- a/developers/mobile-thorchain.md +++ b/developers/mobile-thorchain.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/developers/mobile-zetachain.md b/developers/mobile-zetachain.md index 109da74b0..093f43ad0 100644 --- a/developers/mobile-zetachain.md +++ b/developers/mobile-zetachain.md @@ -2,4 +2,4 @@

No mobile wallet integration available yet! It will be updated soon. -

\ No newline at end of file + diff --git a/routing/introduction.md b/routing/introduction.md index f8ffd7316..5f13ac0be 100644 --- a/routing/introduction.md +++ b/routing/introduction.md @@ -6,6 +6,7 @@ next: text: "Endpoints" link: "./endpoints" --- + # Routing API _Comprehensive description of the routing service and its endpoints_ From d9100bf84573f81763b59e32b8473dde7180c9ff Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Mon, 18 Mar 2024 10:58:29 +0700 Subject: [PATCH 02/14] docs: add content for Blockchains Integration/ETH --- developers/ethereum.md | 332 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) diff --git a/developers/ethereum.md b/developers/ethereum.md index 20c86d452..e8d5e57b1 100644 --- a/developers/ethereum.md +++ b/developers/ethereum.md @@ -1 +1,333 @@ # Ethereum (ETH) + +Welcome to the xDeFi Wallet Ethereum integration guide. This guide will help you to integrate your Ethereum-based DApp with xDeFi Wallet. + +### Detect XDeFi Wallet with Ethereum + +To detect whether your browser is running XDeFi Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?.isXDeFi) || + window.xdefi +) { + console.log("XDeFi Wallet detected"); + // Your code here +} +``` + +Notice: + +- `window.ethereum` is a standard Ethereum provider object, and `window.ethereum.isXDeFi` is a property added by XDeFi Wallet. If `window.ethereum` is not available, you can also check `window.xdefi` which is a global object added by XDeFi Wallet. +- The XDeFi Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +### Connect/Disconnect to XDeFi Wallet + +To connect to XDeFi Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDeFi Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDeFi Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try{ + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +#### List of Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +**Event List** +| Events | Trigger | +| --- | --- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +**Methods supported** + +| Methods | Description | +| --- | --- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | From 28e957bede0292b827614e1027befd12cc6f176e Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Mon, 18 Mar 2024 14:54:50 +0700 Subject: [PATCH 03/14] chore: update Readme x docs --- README.md | 5 +++-- developers/ethereum.md | 12 +++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c323d5562..be005b600 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,14 @@ making a pull request. ## Directory Structure +- /.vitepress: Configuration files for the VitePress site. - /about: A category for learning more about XDEFI Technologies and $XDEFI token. +- /campaigns: A category for Campaigns Service API - /developers: A category with tutorials and guides for deploying dApps and connect with XDEFI Wallet. - /routing: Technical reference materials for integrating our Routing aggregator API. - -- /community: A category for the XDEFI community. - /public: Images, diagrams, and other media files used in the documentation. +- /components: Custom components used in the documentation. ## Feedback & Suggestions diff --git a/developers/ethereum.md b/developers/ethereum.md index e8d5e57b1..b3cbde0a4 100644 --- a/developers/ethereum.md +++ b/developers/ethereum.md @@ -305,8 +305,6 @@ window.ethereum.on("data", data => { ### Events -#### List of Events - Currently we only support some action events from Wallet ```javascript @@ -316,7 +314,7 @@ window.ethereum.on('close', () => window.location.reload()); window.ethereum.on('accountsChanged', () => window.location.reload()); ``` -**Event List** +#### Events supported | Events | Trigger | | --- | --- | | `accountsChanged` | Receive when active account changed in Wallet | @@ -325,9 +323,9 @@ window.ethereum.on('accountsChanged', () => window.location.reload()); | `close` | Alias for disconnect event | | `disconnect` | Receive when disconnecting from Wallet | -**Methods supported** +#### Methods supported -| Methods | Description | -| --- | --- | -| `on(event, callback)` | Add event listener | +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | | `off(event, callback)` | Remove event listener | From 4715329af79f90d97e8463ba6780a93e40caae15 Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Mon, 18 Mar 2024 17:17:32 +0700 Subject: [PATCH 04/14] chore: fix a typo --- developers/ethereum.md | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/developers/ethereum.md b/developers/ethereum.md index b3cbde0a4..b3bf92a5f 100644 --- a/developers/ethereum.md +++ b/developers/ethereum.md @@ -1,29 +1,29 @@ # Ethereum (ETH) -Welcome to the xDeFi Wallet Ethereum integration guide. This guide will help you to integrate your Ethereum-based DApp with xDeFi Wallet. +Welcome to the XDEFI Wallet Ethereum integration guide. This guide will help you to integrate your Ethereum-based DApp with XDEFI Wallet. -### Detect XDeFi Wallet with Ethereum +### Detect XDEFI Wallet with Ethereum -To detect whether your browser is running XDeFi Wallet, you can use the following code: +To detect whether your browser is running XDEFI Wallet, you can use the following code: ```javascript if ( - (typeof window.ethereum !== "undefined" && window.ethereum?.isXDeFi) || + (typeof window.ethereum !== "undefined" && window.ethereum?.isXDEFI) || window.xdefi ) { - console.log("XDeFi Wallet detected"); + console.log("XDEFI Wallet detected"); // Your code here } ``` Notice: -- `window.ethereum` is a standard Ethereum provider object, and `window.ethereum.isXDeFi` is a property added by XDeFi Wallet. If `window.ethereum` is not available, you can also check `window.xdefi` which is a global object added by XDeFi Wallet. -- The XDeFi Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` +- `window.ethereum` is a standard Ethereum provider object, and `window.ethereum.isXDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xdefi` which is a global object added by XDEFI Wallet. +- The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` -### Connect/Disconnect to XDeFi Wallet +### Connect/Disconnect to XDEFI Wallet -To connect to XDeFi Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: ```javascript // Connect & get accounts @@ -38,7 +38,7 @@ window.ethereum.request({method: 'wallet_getPermissions'}); window.ethereum.request({method: 'wallet_requestPermissions'}); ``` -To disconnect from XDeFi Wallet, please use: +To disconnect from XDEFI Wallet, please use: ```javascript window.ethereum.disconnect(); @@ -46,7 +46,7 @@ window.ethereum.disconnect(); ### Experience functions -When your account is connected to XDeFi Wallet, let's start experiencing more functions. +When your account is connected to XDEFI Wallet, let's start experiencing more functions. #### Get the current account @@ -315,13 +315,14 @@ window.ethereum.on('accountsChanged', () => window.location.reload()); ``` #### Events supported -| Events | Trigger | -| --- | --- | + +| Events | Trigger | +| ----------------- | --------------------------------------------- | | `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | #### Methods supported From 77aaeb913104b5b7410ea244829348444e97d57b Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Tue, 19 Mar 2024 16:13:57 +0700 Subject: [PATCH 05/14] docs: update docs for EVMs --- components/DetectWallet.jsx | 43 +++++++++++++++++++++++++++++++++++++ developers/ethereum.md | 28 +++++++++++++++++++----- 2 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 components/DetectWallet.jsx diff --git a/components/DetectWallet.jsx b/components/DetectWallet.jsx new file mode 100644 index 000000000..bee4abc00 --- /dev/null +++ b/components/DetectWallet.jsx @@ -0,0 +1,43 @@ +import React from "react"; + +const DetectWallet = ({network}) => { + const detectWallet = async () => { + if ( + (typeof window.ethereum !== "undefined" && window.ethereum._XDEFI) || + window.xfi + ) { + switch (network) { + case "ethereum": + await window.ethereum + .request({ method: "eth_accounts" }) + .then((result) => { + alert("XDEFI Wallet detected!\nAddress: " + result[0]); + return; + }) + .catch((err) => { + alert("Error connecting wallet:", err); + return; + }); + break; + default: + alert("Network not supported!"); + return; + } + } else { + alert("XDEFI Wallet not detected!"); + } + }; + + return ( +
+ +
+ ); +}; + +export default DetectWallet; diff --git a/developers/ethereum.md b/developers/ethereum.md index b3bf92a5f..d286bf06e 100644 --- a/developers/ethereum.md +++ b/developers/ethereum.md @@ -8,18 +8,19 @@ To detect whether your browser is running XDEFI Wallet, you can use the followin ```javascript if ( - (typeof window.ethereum !== "undefined" && window.ethereum?.isXDEFI) || - window.xdefi + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi ) { console.log("XDEFI Wallet detected"); // Your code here } ``` -Notice: +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. -- `window.ethereum` is a standard Ethereum provider object, and `window.ethereum.isXDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xdefi` which is a global object added by XDEFI Wallet. -- The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
### Connect/Disconnect to XDEFI Wallet @@ -330,3 +331,20 @@ window.ethereum.on('accountsChanged', () => window.location.reload()); | ---------------------- | --------------------- | | `on(event, callback)` | Add event listener | | `off(event, callback)` | Remove event listener | + + From a5ccaaf2654184c298f47bd71c6dacc962ed1429 Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Tue, 19 Mar 2024 22:45:38 +0700 Subject: [PATCH 06/14] docs: chore update --- components/DetectWallet.jsx | 68 +++++++++++++++++++++---------------- developers/ethereum.md | 4 +-- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/components/DetectWallet.jsx b/components/DetectWallet.jsx index bee4abc00..ea996447f 100644 --- a/components/DetectWallet.jsx +++ b/components/DetectWallet.jsx @@ -1,42 +1,50 @@ -import React from "react"; +import React, { useState } from "react"; + +const DetectWallet = ({ chainId }) => { + const [address, setAddress] = useState(undefined); -const DetectWallet = ({network}) => { const detectWallet = async () => { - if ( - (typeof window.ethereum !== "undefined" && window.ethereum._XDEFI) || - window.xfi - ) { - switch (network) { - case "ethereum": - await window.ethereum - .request({ method: "eth_accounts" }) - .then((result) => { - alert("XDEFI Wallet detected!\nAddress: " + result[0]); - return; - }) - .catch((err) => { - alert("Error connecting wallet:", err); - return; - }); - break; - default: - alert("Network not supported!"); - return; + if (window.xfi) { + if (!window.xfi[chainId]) { + alert("XDEFI Wallet not connected to the correct network!"); + return; + } + if (chainId === "ethereum") { + await window.ethereum + .request({ method: "eth_requestAccounts" }) + .then((accounts) => setAddress(accounts[0])); + return; } + await window.xfi[chainId].request( + { method: "request_accounts", params: [] }, + (error, accounts) => setAddress(accounts[0]), + ); } else { alert("XDEFI Wallet not detected!"); } }; return ( -
- -
+ <> +
+ +
+ {address && ( +
+
+ + Address + +
+
{address}
+
+ )} + ); }; diff --git a/developers/ethereum.md b/developers/ethereum.md index d286bf06e..179a69158 100644 --- a/developers/ethereum.md +++ b/developers/ethereum.md @@ -203,7 +203,7 @@ Return `Promise` with the result Return `Promise` with the result, and an error otherwise ```javascript -try{ +try { await window.await ethereum.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: '0xf00' }], @@ -344,7 +344,7 @@ const refConnectWallet = ref() onMounted(() => { const rootDetectWallet = createRoot(refDetectWallet.value) rootDetectWallet.render(createElement(DetectWallet, { - network: 'ethereum', + chainId: 'ethereum', }, null)) }) From 78fe24dddbdcd06e92c343e2059c8e83679b72bc Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Wed, 20 Mar 2024 11:04:26 +0700 Subject: [PATCH 07/14] docs: add content for Blockchains Integration --- .vitepress/config.ts | 48 ---- developers/akash.md | 1 - developers/arbitrum.md | 351 ++++++++++++++++++++++++++ developers/aurora.md | 351 ++++++++++++++++++++++++++ developers/avalanche.md | 351 ++++++++++++++++++++++++++ developers/axelar.md | 1 - developers/bitcoin-cash.md | 133 ++++++++++ developers/bitcoin.md | 133 ++++++++++ developers/blockchains-integration.md | 11 - developers/bnb-beacon-chain.md | 133 ++++++++++ developers/bnb-smart-chain.md | 351 ++++++++++++++++++++++++++ developers/canto.md | 351 ++++++++++++++++++++++++++ developers/cosmos.md | 133 ++++++++++ developers/crescent.md | 1 - developers/cronos.md | 351 ++++++++++++++++++++++++++ developers/dogecoin.md | 133 ++++++++++ developers/fantom.md | 351 ++++++++++++++++++++++++++ developers/gnosis.md | 351 ++++++++++++++++++++++++++ developers/juno.md | 1 - developers/kava.md | 1 - developers/klaytn.md | 351 ++++++++++++++++++++++++++ developers/kujira.md | 1 - developers/litecoin.md | 133 ++++++++++ developers/mars.md | 1 - developers/maya.md | 133 ++++++++++ developers/near.md | 133 ++++++++++ developers/optimism.md | 351 ++++++++++++++++++++++++++ developers/osmosis.md | 0 developers/polygon.md | 351 ++++++++++++++++++++++++++ developers/sei.md | 1 - developers/solana.md | 133 ++++++++++ developers/stargaze.md | 1 - developers/stride.md | 1 - developers/terra.md | 133 ++++++++++ developers/thorchain.md | 133 ++++++++++ developers/tron.md | 1 - 36 files changed, 5324 insertions(+), 70 deletions(-) delete mode 100644 developers/akash.md delete mode 100644 developers/axelar.md delete mode 100644 developers/crescent.md delete mode 100644 developers/juno.md delete mode 100644 developers/kava.md delete mode 100644 developers/kujira.md delete mode 100644 developers/mars.md delete mode 100644 developers/osmosis.md delete mode 100644 developers/sei.md delete mode 100644 developers/stargaze.md delete mode 100644 developers/stride.md delete mode 100644 developers/tron.md diff --git a/.vitepress/config.ts b/.vitepress/config.ts index 6ba82cc4b..dab103191 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -540,10 +540,6 @@ function sidebarHome() { text: "Introduction", link: "/developers/blockchains-integration", }, - { - text: "Akash (AKT)", - link: "/developers/akash", - }, { text: "Arbitrum (AETH)", link: "/developers/arbitrum", @@ -556,10 +552,6 @@ function sidebarHome() { text: "Avalanche (AVAX)", link: "/developers/avalanche", }, - { - text: "Axelar (AXL)", - link: "/developers/axelar", - }, { text: "Bitcoin (BTC)", link: "/developers/bitcoin", @@ -584,10 +576,6 @@ function sidebarHome() { text: "Cosmos (ATOM)", link: "/developers/cosmos", }, - { - text: "Crescent (CRE)", - link: "/developers/crescent", - }, { text: "Cronos (CRO)", link: "/developers/cronos", @@ -608,30 +596,14 @@ function sidebarHome() { text: "Gnosis (xDAI)", link: "/developers/gnosis", }, - { - text: "Juno (JUNO)", - link: "/developers/juno", - }, - { - text: "Kava (KAVA)", - link: "/developers/kava", - }, { text: "Klaytn (KLAY)", link: "/developers/klaytn", }, - { - text: "Kujira (KUJI)", - link: "/developers/kujira", - }, { text: "Litecoin (LTC)", link: "/developers/litecoin", }, - { - text: "Mars (MARS)", - link: "/developers/mars", - }, { text: "Maya Protocol (MAYA)", link: "/developers/maya", @@ -644,30 +616,14 @@ function sidebarHome() { text: "Optimism (ETH)", link: "/developers/optimism", }, - { - text: "Osmosis (OSMO)", - link: "/developers/osmosis", - }, { text: "Polygon (MATIC)", link: "/developers/polygon", }, - { - text: "Sei Testnet (SEI)", - link: "/developers/sei", - }, { text: "Solana (SOL)", link: "/developers/solana", }, - { - text: "Stargaze (STARS)", - link: "/developers/stargaze", - }, - { - text: "Stride (STRD)", - link: "/developers/stride", - }, { text: "Terra (LUNA)", link: "/developers/terra", @@ -676,10 +632,6 @@ function sidebarHome() { text: "THORChain (RUNE)", link: "/developers/thorchain", }, - { - text: "Tron (TRX)", - link: "/developers/tron", - }, ], }, ], diff --git a/developers/akash.md b/developers/akash.md deleted file mode 100644 index 1f7fd6458..000000000 --- a/developers/akash.md +++ /dev/null @@ -1 +0,0 @@ -# Akash (AKT) diff --git a/developers/arbitrum.md b/developers/arbitrum.md index 41683ce72..0c389e6a1 100644 --- a/developers/arbitrum.md +++ b/developers/arbitrum.md @@ -1 +1,352 @@ # Arbitrum (AETH) + +Arbitrum is a layer 2 scaling solution for Ethereum. It is a sidechain that uses a technology called rollups to process transactions off-chain and then batch them into a single transaction that is submitted to the Ethereum mainnet. This allows for faster and cheaper transactions. + +This document based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/aurora.md b/developers/aurora.md index bba2c0f98..ab1be8298 100644 --- a/developers/aurora.md +++ b/developers/aurora.md @@ -1 +1,352 @@ # Aurora (AURORA) + +Aurora is a multi-chain platform that unites Ethereum and the Aurora Network, a layer 2 blockchain that is compatible with Ethereum. Aurora is designed to provide a seamless experience for developers and users, with the goal of making it easy to build and use decentralized applications (dApps) on the Aurora Network. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/avalanche.md b/developers/avalanche.md index 9f4482b46..012f3a4ec 100644 --- a/developers/avalanche.md +++ b/developers/avalanche.md @@ -1 +1,352 @@ # Avalanche (AVAX) + +Avalanche is an open-source platform for launching decentralized applications and enterprise blockchain deployments in one interoperable, highly scalable ecosystem. Avalanche is the first decentralized platform that confirms transactions in under one second, supports the entirety of the Ethereum development toolkit, and enables millions of independent validators to participate as full block producers. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/axelar.md b/developers/axelar.md deleted file mode 100644 index 40a29b590..000000000 --- a/developers/axelar.md +++ /dev/null @@ -1 +0,0 @@ -# Axelar (AXL) diff --git a/developers/bitcoin-cash.md b/developers/bitcoin-cash.md index aec4299af..2a2a9cb8b 100644 --- a/developers/bitcoin-cash.md +++ b/developers/bitcoin-cash.md @@ -1 +1,134 @@ # Bitcoin Cash (BCH) + +Welcome to the XDEFI Wallet Bitcoin Cash integration guide. + +### Detect XDEFI Wallet with Bitcoin Cash + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.bitcoincash.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.bitcoincash.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.bitcoincash.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.bitcoincash.on('event_name', callback); +​//Example +window.xfi.bitcoincash.on('close', () => window.location.reload()); +window.xfi.bitcoincash.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/bitcoin.md b/developers/bitcoin.md index 6dc35f397..143c36eae 100644 --- a/developers/bitcoin.md +++ b/developers/bitcoin.md @@ -1 +1,134 @@ # Bitcoin (BTC) + +Welcome to the XDEFI Wallet Bitcoin integration guide. + +### Detect XDEFI Wallet with Bitcoin + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.bitcoin.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.bitcoin.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.bitcoin.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.bitcoin.on('event_name', callback); +​//Example +window.xfi.bitcoin.on('close', () => window.location.reload()); +window.xfi.bitcoin.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/blockchains-integration.md b/developers/blockchains-integration.md index 8caf952ef..a50c39edc 100644 --- a/developers/blockchains-integration.md +++ b/developers/blockchains-integration.md @@ -11,41 +11,30 @@ next: ### Native blockchains support -- [Akash (AKT)](./akash) - [Arbitrum (AETH)](./arbitrum) - [Aurora (AURORA)](./aurora) - [Avalanche (AVAX)](./avalanche) -- [Axelar (AXL)](./axelar) - [Bitcoin (BTC)](./bitcoin) - [Bitcoin Cash (BCH)](./bitcoin-cash) - [BNB Beacon Chain (BNB)](./bnb-beacon-chain) - [BNB Smart Chain (BNB)](./bnb-smart-chain) - [Canto (CANTO)](./canto) - [Cosmos (ATOM)](./cosmos) -- [Crescent (CRE)](./crescent) - [Cronos (CRO)](./cronos) - [Dogecoin (DOGE)](./dogecoin) - [Ethereum (ETH)](./ethereum) - [Fantom (FTM)](./fantom) - [Gnosis (xDAI)](./gnosis) -- [Juno (JUNO)](./juno) - [Kava (KAVA)](./kava) - [Klaytn (KLAY)](./klaytn) -- [Kujira (KUJI)](./kujira) - [Litecoin (LTC)](./litecoin) -- [Mars (MARS)](./mars) - [Maya Protocol (MAYA)](./maya) - [Near Protocol (NEAR)](./near) - [Optimism (ETH)](./optimism) -- [Osmosis (OSMO)](./osmosis) - [Polygon (MATIC)](./polygon) -- [Sei Testnet (SEI)](./sei) - [Solana (SOL)](./solana) -- [Stargaze (STARS)](./stargaze) -- [Stride (STRD)](./stride) - [Terra (LUNA)](./terra) - [THORChain (RUNE)](./thorchain) -- [Tron (TRX)](./tron) ### Custom blockchains support diff --git a/developers/bnb-beacon-chain.md b/developers/bnb-beacon-chain.md index 260937a40..345cf597d 100644 --- a/developers/bnb-beacon-chain.md +++ b/developers/bnb-beacon-chain.md @@ -1 +1,134 @@ # BNB Beacon Chain (BNB) + +Welcome to the XDEFI Wallet BNB Beacon Chain integration guide. + +### Detect XDEFI Wallet with BNB Beacon Chain + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.binance.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.binance.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.binance.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.binance.on('event_name', callback); +​//Example +window.xfi.binance.on('close', () => window.location.reload()); +window.xfi.binance.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/bnb-smart-chain.md b/developers/bnb-smart-chain.md index 98b40328f..8f6b5d784 100644 --- a/developers/bnb-smart-chain.md +++ b/developers/bnb-smart-chain.md @@ -1 +1,352 @@ # BNB Smart Chain (BNB) + +BNB Smart Chain is a blockchain platform that allows developers to build and deploy decentralized applications. It is a fast and low-cost blockchain that runs in parallel with Binance Chain. BNB Smart Chain is compatible with the Ethereum Virtual Machine (EVM), which means it supports the Ethereum toolchain and Solidity smart contracts. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/canto.md b/developers/canto.md index 529c27792..ec3bedec1 100644 --- a/developers/canto.md +++ b/developers/canto.md @@ -1 +1,352 @@ # Canto (CANTO) + +Canto is a multi-chain wallet that allows users to manage their digital assets and interact with decentralized applications (dApps) on various blockchains. Canto is a non-custodial wallet, meaning that users have full control over their assets and private keys. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/cosmos.md b/developers/cosmos.md index a68bc067e..e83f0df5e 100644 --- a/developers/cosmos.md +++ b/developers/cosmos.md @@ -1 +1,134 @@ # Cosmos (ATOM) + +Welcome to the XDEFI Wallet Cosmos integration guide. + +### Detect XDEFI Wallet with Cosmos + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.cosmos.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.cosmos.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.cosmos.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.cosmos.on('event_name', callback); +​//Example +window.xfi.cosmos.on('close', () => window.location.reload()); +window.xfi.cosmos.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/crescent.md b/developers/crescent.md deleted file mode 100644 index 7dd39c543..000000000 --- a/developers/crescent.md +++ /dev/null @@ -1 +0,0 @@ -# Crescent (CRE) diff --git a/developers/cronos.md b/developers/cronos.md index 16facfae8..70a4c6d42 100644 --- a/developers/cronos.md +++ b/developers/cronos.md @@ -1 +1,352 @@ # Cronos (CRO) + +Cronos is a blockchain network that is powered by the EVM (Ethereum Virtual Machine) and is fully compatible with the Ethereum ecosystem. It is designed to be a decentralized, secure, and scalable platform that can support a wide range of decentralized applications, including DeFi, NFTs, and more. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/dogecoin.md b/developers/dogecoin.md index 298620ebd..34ee5b353 100644 --- a/developers/dogecoin.md +++ b/developers/dogecoin.md @@ -1 +1,134 @@ # Dogecoin (DOGE) + +Welcome to the XDEFI Wallet Dogecoin integration guide. + +### Detect XDEFI Wallet with Dogecoin + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.dogecoin.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.dogecoin.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.dogecoin.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.dogecoin.on('event_name', callback); +​//Example +window.xfi.dogecoin.on('close', () => window.location.reload()); +window.xfi.dogecoin.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/fantom.md b/developers/fantom.md index 0030b54c5..0195c3b2f 100644 --- a/developers/fantom.md +++ b/developers/fantom.md @@ -1 +1,352 @@ # Fantom (FTM) + +Fantom is a high-performance, scalable, and secure smart-contract platform. It is designed to overcome the limitations of previous generation blockchain platforms. Fantom is permissionless, decentralized, and open-source. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/gnosis.md b/developers/gnosis.md index 31183fe3f..7de283bc2 100644 --- a/developers/gnosis.md +++ b/developers/gnosis.md @@ -1 +1,352 @@ # Gnosis (xDAI) + +Gnosis is a decentralized prediction market platform built on Ethereum. It allows users to create, trade, and hold prediction shares of events. Gnosis is a decentralized platform for prediction markets, and xDAI is a sidechain of Ethereum. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/juno.md b/developers/juno.md deleted file mode 100644 index ef1b0b3e3..000000000 --- a/developers/juno.md +++ /dev/null @@ -1 +0,0 @@ -# Juno (JUNO) diff --git a/developers/kava.md b/developers/kava.md deleted file mode 100644 index 156bf5395..000000000 --- a/developers/kava.md +++ /dev/null @@ -1 +0,0 @@ -# Kava (KAVA) diff --git a/developers/klaytn.md b/developers/klaytn.md index e144b4b40..e8d9c6fd6 100644 --- a/developers/klaytn.md +++ b/developers/klaytn.md @@ -1 +1,352 @@ # Klaytn (KLAY) + +Klaytn is a public blockchain platform of the Klaytn Foundation, a group of companies and organizations including Kakao, a South Korean internet company. Klaytn is a service-centric blockchain platform providing an easy development environment and friendly user experience. It is a platform that allows users to experience blockchain technology in their daily lives. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/kujira.md b/developers/kujira.md deleted file mode 100644 index 6bc9e7eea..000000000 --- a/developers/kujira.md +++ /dev/null @@ -1 +0,0 @@ -# Kujira (KUJI) diff --git a/developers/litecoin.md b/developers/litecoin.md index fb55b2b17..bbbdc32d9 100644 --- a/developers/litecoin.md +++ b/developers/litecoin.md @@ -1 +1,134 @@ # Litecoin (LTC) + +Welcome to the XDEFI Wallet Litecoin integration guide. + +### Detect XDEFI Wallet with Litecoin + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.litecoin.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.litecoin.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.litecoin.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.litecoin.on('event_name', callback); +​//Example +window.xfi.litecoin.on('close', () => window.location.reload()); +window.xfi.litecoin.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/mars.md b/developers/mars.md deleted file mode 100644 index 26b6f52ca..000000000 --- a/developers/mars.md +++ /dev/null @@ -1 +0,0 @@ -# Mars (MARS) diff --git a/developers/maya.md b/developers/maya.md index d4537e1a0..f109b775a 100644 --- a/developers/maya.md +++ b/developers/maya.md @@ -1 +1,134 @@ # Maya Protocol (MAYA) + +Welcome to the XDEFI Wallet Maya Protocol integration guide. + +### Detect XDEFI Wallet with Maya Protocol + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.mayachain.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.mayachain.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.mayachain.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.mayachain.on('event_name', callback); +​//Example +window.xfi.mayachain.on('close', () => window.location.reload()); +window.xfi.mayachain.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/near.md b/developers/near.md index 863430a26..7c43ff3fe 100644 --- a/developers/near.md +++ b/developers/near.md @@ -1 +1,134 @@ # Near Protocol (NEAR) + +Welcome to the XDEFI Wallet NEAR integration guide. + +### Detect XDEFI Wallet with NEAR + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.near.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.near.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.near.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.near.on('event_name', callback); +​//Example +window.xfi.near.on('close', () => window.location.reload()); +window.xfi.near.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/optimism.md b/developers/optimism.md index e7674dfd4..13e78fbbb 100644 --- a/developers/optimism.md +++ b/developers/optimism.md @@ -1 +1,352 @@ # Optimism (ETH) + +Optimism is a layer 2 scaling solution for Ethereum, which is designed to enable fast, secure, and low-cost transactions. It is built on the Optimistic Ethereum (OΞ) protocol, which is an Ethereum Virtual Machine (EVM) compatible layer 2 scaling solution. Optimism is designed to be a general-purpose scaling solution, which means that it can be used to scale any Ethereum application, including DeFi, NFTs, and more. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/osmosis.md b/developers/osmosis.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/developers/polygon.md b/developers/polygon.md index 67214ed62..0a90bf4b1 100644 --- a/developers/polygon.md +++ b/developers/polygon.md @@ -1 +1,352 @@ # Polygon (MATIC) + +Polygon is a protocol and a framework for building and connecting Ethereum-compatible blockchain networks. Aggregating scalable solutions on Ethereum supporting a multi-chain Ethereum ecosystem. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/sei.md b/developers/sei.md deleted file mode 100644 index 8979fe7ad..000000000 --- a/developers/sei.md +++ /dev/null @@ -1 +0,0 @@ -# Sei Testnet (SEI) diff --git a/developers/solana.md b/developers/solana.md index f2faf0a59..d569006b1 100644 --- a/developers/solana.md +++ b/developers/solana.md @@ -1 +1,134 @@ # Solana (SOL) + +Welcome to the XDEFI Wallet Solana integration guide. + +### Detect XDEFI Wallet with Solana + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.solana.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.solana.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.solana.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.solana.on('event_name', callback); +​//Example +window.xfi.solana.on('close', () => window.location.reload()); +window.xfi.solana.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/stargaze.md b/developers/stargaze.md deleted file mode 100644 index 89a0d5ec2..000000000 --- a/developers/stargaze.md +++ /dev/null @@ -1 +0,0 @@ -# Stargaze (STARS) diff --git a/developers/stride.md b/developers/stride.md deleted file mode 100644 index 75ef9ae8f..000000000 --- a/developers/stride.md +++ /dev/null @@ -1 +0,0 @@ -# Stride (STRD) diff --git a/developers/terra.md b/developers/terra.md index 6dd175175..a8d22d6e1 100644 --- a/developers/terra.md +++ b/developers/terra.md @@ -1 +1,134 @@ # Terra (LUNA) + +Welcome to the XDEFI Wallet Terra integration guide. + +### Detect XDEFI Wallet with Terra + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.terra.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.terra.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.terra.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.terra.on('event_name', callback); +​//Example +window.xfi.terra.on('close', () => window.location.reload()); +window.xfi.terra.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/thorchain.md b/developers/thorchain.md index fa003a0c4..238a0a3f8 100644 --- a/developers/thorchain.md +++ b/developers/thorchain.md @@ -1 +1,134 @@ # THORChain (RUNE) + +Welcome to the XDEFI Wallet THORChain integration guide. + +### Detect XDEFI Wallet with THORChain + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +
+ +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi.thorchain.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi.thorchain.request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi.thorchain.request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi.thorchain.on('event_name', callback); +​//Example +window.xfi.thorchain.on('close', () => window.location.reload()); +window.xfi.thorchain.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/tron.md b/developers/tron.md deleted file mode 100644 index a102c7b82..000000000 --- a/developers/tron.md +++ /dev/null @@ -1 +0,0 @@ -# Tron (TRX) From 03450bfce767d240a84e5e0e7bccbef3525091c4 Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Wed, 20 Mar 2024 14:29:36 +0700 Subject: [PATCH 08/14] docs: update --- .vitepress/config.ts | 90 +---- developers/arbitrum.md | 352 ------------------ developers/aurora.md | 352 ------------------ developers/avalanche.md | 352 ------------------ developers/bitcoin-cash.md | 134 ------- developers/blockchains-integration.md | 57 ++- developers/bnb-beacon-chain.md | 134 ------- developers/bnb-smart-chain.md | 352 ------------------ developers/canto.md | 352 ------------------ developers/cosmos.md | 134 ------- developers/cronos.md | 352 ------------------ developers/dogecoin.md | 134 ------- developers/ethereum.md | 2 +- developers/fantom.md | 352 ------------------ developers/gnosis.md | 352 ------------------ developers/introduction.md | 28 +- developers/klaytn.md | 352 ------------------ developers/litecoin.md | 134 ------- developers/maya.md | 134 ------- developers/near.md | 134 ------- developers/optimism.md | 352 ------------------ .../{bitcoin.md => other-blockchains.md} | 38 +- developers/polygon.md | 352 ------------------ developers/solana.md | 134 ------- developers/terra.md | 134 ------- developers/thorchain.md | 134 ------- 26 files changed, 67 insertions(+), 5360 deletions(-) delete mode 100644 developers/arbitrum.md delete mode 100644 developers/aurora.md delete mode 100644 developers/avalanche.md delete mode 100644 developers/bitcoin-cash.md delete mode 100644 developers/bnb-beacon-chain.md delete mode 100644 developers/bnb-smart-chain.md delete mode 100644 developers/canto.md delete mode 100644 developers/cosmos.md delete mode 100644 developers/cronos.md delete mode 100644 developers/dogecoin.md delete mode 100644 developers/fantom.md delete mode 100644 developers/gnosis.md delete mode 100644 developers/klaytn.md delete mode 100644 developers/litecoin.md delete mode 100644 developers/maya.md delete mode 100644 developers/near.md delete mode 100644 developers/optimism.md rename developers/{bitcoin.md => other-blockchains.md} (70%) delete mode 100644 developers/polygon.md delete mode 100644 developers/solana.md delete mode 100644 developers/terra.md delete mode 100644 developers/thorchain.md diff --git a/.vitepress/config.ts b/.vitepress/config.ts index dab103191..70a022d6f 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -541,96 +541,12 @@ function sidebarHome() { link: "/developers/blockchains-integration", }, { - text: "Arbitrum (AETH)", - link: "/developers/arbitrum", - }, - { - text: "Aurora (AURORA)", - link: "/developers/aurora", - }, - { - text: "Avalanche (AVAX)", - link: "/developers/avalanche", - }, - { - text: "Bitcoin (BTC)", - link: "/developers/bitcoin", - }, - { - text: "Bitcoin Cash (BCH)", - link: "/developers/bitcoin-cash", - }, - { - text: "BNB Beacon Chain (BNB)", - link: "/developers/bnb-beacon-chain", - }, - { - text: "BNB Smart Chain (BNB)", - link: "/developers/bnb-smart-chain", - }, - { - text: "Canto (CANTO)", - link: "/developers/canto", - }, - { - text: "Cosmos (ATOM)", - link: "/developers/cosmos", - }, - { - text: "Cronos (CRO)", - link: "/developers/cronos", - }, - { - text: "Dogecoin (DOGE)", - link: "/developers/dogecoin", - }, - { - text: "Ethereum (ETH)", + text: "Ethereum (EVM's)", link: "/developers/ethereum", }, { - text: "Fantom (FTM)", - link: "/developers/fantom", - }, - { - text: "Gnosis (xDAI)", - link: "/developers/gnosis", - }, - { - text: "Klaytn (KLAY)", - link: "/developers/klaytn", - }, - { - text: "Litecoin (LTC)", - link: "/developers/litecoin", - }, - { - text: "Maya Protocol (MAYA)", - link: "/developers/maya", - }, - { - text: "Near Protocol (NEAR)", - link: "/developers/near", - }, - { - text: "Optimism (ETH)", - link: "/developers/optimism", - }, - { - text: "Polygon (MATIC)", - link: "/developers/polygon", - }, - { - text: "Solana (SOL)", - link: "/developers/solana", - }, - { - text: "Terra (LUNA)", - link: "/developers/terra", - }, - { - text: "THORChain (RUNE)", - link: "/developers/thorchain", + text: "Other Blockchains", + link: "/developers/other-blockchains", }, ], }, diff --git a/developers/arbitrum.md b/developers/arbitrum.md deleted file mode 100644 index 0c389e6a1..000000000 --- a/developers/arbitrum.md +++ /dev/null @@ -1,352 +0,0 @@ -# Arbitrum (AETH) - -Arbitrum is a layer 2 scaling solution for Ethereum. It is a sidechain that uses a technology called rollups to process transactions off-chain and then batch them into a single transaction that is submitted to the Ethereum mainnet. This allows for faster and cheaper transactions. - -This document based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/aurora.md b/developers/aurora.md deleted file mode 100644 index ab1be8298..000000000 --- a/developers/aurora.md +++ /dev/null @@ -1,352 +0,0 @@ -# Aurora (AURORA) - -Aurora is a multi-chain platform that unites Ethereum and the Aurora Network, a layer 2 blockchain that is compatible with Ethereum. Aurora is designed to provide a seamless experience for developers and users, with the goal of making it easy to build and use decentralized applications (dApps) on the Aurora Network. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/avalanche.md b/developers/avalanche.md deleted file mode 100644 index 012f3a4ec..000000000 --- a/developers/avalanche.md +++ /dev/null @@ -1,352 +0,0 @@ -# Avalanche (AVAX) - -Avalanche is an open-source platform for launching decentralized applications and enterprise blockchain deployments in one interoperable, highly scalable ecosystem. Avalanche is the first decentralized platform that confirms transactions in under one second, supports the entirety of the Ethereum development toolkit, and enables millions of independent validators to participate as full block producers. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/bitcoin-cash.md b/developers/bitcoin-cash.md deleted file mode 100644 index 2a2a9cb8b..000000000 --- a/developers/bitcoin-cash.md +++ /dev/null @@ -1,134 +0,0 @@ -# Bitcoin Cash (BCH) - -Welcome to the XDEFI Wallet Bitcoin Cash integration guide. - -### Detect XDEFI Wallet with Bitcoin Cash - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.bitcoincash.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.bitcoincash.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.bitcoincash.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.bitcoincash.on('event_name', callback); -​//Example -window.xfi.bitcoincash.on('close', () => window.location.reload()); -window.xfi.bitcoincash.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/blockchains-integration.md b/developers/blockchains-integration.md index a50c39edc..90ccbb2f4 100644 --- a/developers/blockchains-integration.md +++ b/developers/blockchains-integration.md @@ -9,36 +9,29 @@ next: # Blockchains Integration -### Native blockchains support +XDEFI is the largest multichain wallet that provides hundreds of blockchains accessibility. -- [Arbitrum (AETH)](./arbitrum) -- [Aurora (AURORA)](./aurora) -- [Avalanche (AVAX)](./avalanche) -- [Bitcoin (BTC)](./bitcoin) -- [Bitcoin Cash (BCH)](./bitcoin-cash) -- [BNB Beacon Chain (BNB)](./bnb-beacon-chain) -- [BNB Smart Chain (BNB)](./bnb-smart-chain) -- [Canto (CANTO)](./canto) -- [Cosmos (ATOM)](./cosmos) -- [Cronos (CRO)](./cronos) -- [Dogecoin (DOGE)](./dogecoin) -- [Ethereum (ETH)](./ethereum) -- [Fantom (FTM)](./fantom) -- [Gnosis (xDAI)](./gnosis) -- [Kava (KAVA)](./kava) -- [Klaytn (KLAY)](./klaytn) -- [Litecoin (LTC)](./litecoin) -- [Maya Protocol (MAYA)](./maya) -- [Near Protocol (NEAR)](./near) -- [Optimism (ETH)](./optimism) -- [Polygon (MATIC)](./polygon) -- [Solana (SOL)](./solana) -- [Terra (LUNA)](./terra) -- [THORChain (RUNE)](./thorchain) - -### Custom blockchains support - -- **EVM's** (Mainnet & Testnet) -- **Cosmos chains** (Mainnet & Testnet) - -For both of them, interacting with a dApp will automatically ask you to add the new network while connecting to it. Otherwise, you can add and manage custom networks manually by going into the "Settings" tab and click on the "Network setting" line. +- [EVMs (Ethereum ecosystem) and the Ethereum](./ethereum) + - Ethereum(ETH) + - Arbitrum(AETH) + - Aurora(AURORA) + - Avalanche(AVAX) + - Binance Smart Chain(BSC) + - Canto Network(CANTO) + - Cronos(CRO) + - Fantom(FTM) + - Gnosis(xDAI) + - Optimism(OPTIMISM) + - Polygon(MATIC) +- [Other Blockchains](./other-blockchains) + - BNB Beacon Chain (BNB) + - Bitcoin(BTC) + - Bitcoin Cash(BCH) + - Cosmos(ATOM) + - Dogecoin(DOGE) + - Litecoin(LTC) + - Maya Protocol(MAYA) + - NEAR Protocol(NEAR) + - Solana(SOL) + - Terra(LUNA) + - THORChain(RUNE) diff --git a/developers/bnb-beacon-chain.md b/developers/bnb-beacon-chain.md deleted file mode 100644 index 345cf597d..000000000 --- a/developers/bnb-beacon-chain.md +++ /dev/null @@ -1,134 +0,0 @@ -# BNB Beacon Chain (BNB) - -Welcome to the XDEFI Wallet BNB Beacon Chain integration guide. - -### Detect XDEFI Wallet with BNB Beacon Chain - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.binance.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.binance.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.binance.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.binance.on('event_name', callback); -​//Example -window.xfi.binance.on('close', () => window.location.reload()); -window.xfi.binance.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/bnb-smart-chain.md b/developers/bnb-smart-chain.md deleted file mode 100644 index 8f6b5d784..000000000 --- a/developers/bnb-smart-chain.md +++ /dev/null @@ -1,352 +0,0 @@ -# BNB Smart Chain (BNB) - -BNB Smart Chain is a blockchain platform that allows developers to build and deploy decentralized applications. It is a fast and low-cost blockchain that runs in parallel with Binance Chain. BNB Smart Chain is compatible with the Ethereum Virtual Machine (EVM), which means it supports the Ethereum toolchain and Solidity smart contracts. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/canto.md b/developers/canto.md deleted file mode 100644 index ec3bedec1..000000000 --- a/developers/canto.md +++ /dev/null @@ -1,352 +0,0 @@ -# Canto (CANTO) - -Canto is a multi-chain wallet that allows users to manage their digital assets and interact with decentralized applications (dApps) on various blockchains. Canto is a non-custodial wallet, meaning that users have full control over their assets and private keys. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/cosmos.md b/developers/cosmos.md deleted file mode 100644 index e83f0df5e..000000000 --- a/developers/cosmos.md +++ /dev/null @@ -1,134 +0,0 @@ -# Cosmos (ATOM) - -Welcome to the XDEFI Wallet Cosmos integration guide. - -### Detect XDEFI Wallet with Cosmos - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.cosmos.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.cosmos.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.cosmos.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.cosmos.on('event_name', callback); -​//Example -window.xfi.cosmos.on('close', () => window.location.reload()); -window.xfi.cosmos.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/cronos.md b/developers/cronos.md deleted file mode 100644 index 70a4c6d42..000000000 --- a/developers/cronos.md +++ /dev/null @@ -1,352 +0,0 @@ -# Cronos (CRO) - -Cronos is a blockchain network that is powered by the EVM (Ethereum Virtual Machine) and is fully compatible with the Ethereum ecosystem. It is designed to be a decentralized, secure, and scalable platform that can support a wide range of decentralized applications, including DeFi, NFTs, and more. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/dogecoin.md b/developers/dogecoin.md deleted file mode 100644 index 34ee5b353..000000000 --- a/developers/dogecoin.md +++ /dev/null @@ -1,134 +0,0 @@ -# Dogecoin (DOGE) - -Welcome to the XDEFI Wallet Dogecoin integration guide. - -### Detect XDEFI Wallet with Dogecoin - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.dogecoin.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.dogecoin.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.dogecoin.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.dogecoin.on('event_name', callback); -​//Example -window.xfi.dogecoin.on('close', () => window.location.reload()); -window.xfi.dogecoin.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/ethereum.md b/developers/ethereum.md index 179a69158..40e558dac 100644 --- a/developers/ethereum.md +++ b/developers/ethereum.md @@ -1,4 +1,4 @@ -# Ethereum (ETH) +# Ethereum (EVM's) Welcome to the XDEFI Wallet Ethereum integration guide. This guide will help you to integrate your Ethereum-based DApp with XDEFI Wallet. diff --git a/developers/fantom.md b/developers/fantom.md deleted file mode 100644 index 0195c3b2f..000000000 --- a/developers/fantom.md +++ /dev/null @@ -1,352 +0,0 @@ -# Fantom (FTM) - -Fantom is a high-performance, scalable, and secure smart-contract platform. It is designed to overcome the limitations of previous generation blockchain platforms. Fantom is permissionless, decentralized, and open-source. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/gnosis.md b/developers/gnosis.md deleted file mode 100644 index 7de283bc2..000000000 --- a/developers/gnosis.md +++ /dev/null @@ -1,352 +0,0 @@ -# Gnosis (xDAI) - -Gnosis is a decentralized prediction market platform built on Ethereum. It allows users to create, trade, and hold prediction shares of events. Gnosis is a decentralized platform for prediction markets, and xDAI is a sidechain of Ethereum. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/introduction.md b/developers/introduction.md index 0ce7e5fce..a69305a4e 100644 --- a/developers/introduction.md +++ b/developers/introduction.md @@ -27,23 +27,17 @@ XDEFI is the largest multichain wallet that provide hundreds of blockchains acce You can access a single ecosystem integration with his set of tutorial from here: -- [Arbitrum](./arbitrum) -- [Avalanche](./avalanche) -- [Binance](./binance) -- [Bitcoin](./bitcoin) -- [Bitcoin Cash](./bitcoin-cash) -- [Cosmos](./cosmos) -- [Dogecoin](./dogecoin) -- [Ethereum](./ethereum) -- [Litcoin](./litecoin) -- [Near](./near) -- [Optimism](./optimism) -- [Polygon](./polygon) -- [Solana](./solana) -- [Terra](./terra) -- [Testnets](./testnets) -- [Thorchain](./thorchcain) -- [Zetachain](./zetachain) +- BNB Smart Chain +- Bitcoin +- Bitcoin Cash +- Cosmos +- Dogecoin +- Litecoin +- Maya Protocol +- NEAR Protocol +- Solana +- Terra +- THORChain ## Libraries integration diff --git a/developers/klaytn.md b/developers/klaytn.md deleted file mode 100644 index e8d9c6fd6..000000000 --- a/developers/klaytn.md +++ /dev/null @@ -1,352 +0,0 @@ -# Klaytn (KLAY) - -Klaytn is a public blockchain platform of the Klaytn Foundation, a group of companies and organizations including Kakao, a South Korean internet company. Klaytn is a service-centric blockchain platform providing an easy development environment and friendly user experience. It is a platform that allows users to experience blockchain technology in their daily lives. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/litecoin.md b/developers/litecoin.md deleted file mode 100644 index bbbdc32d9..000000000 --- a/developers/litecoin.md +++ /dev/null @@ -1,134 +0,0 @@ -# Litecoin (LTC) - -Welcome to the XDEFI Wallet Litecoin integration guide. - -### Detect XDEFI Wallet with Litecoin - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.litecoin.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.litecoin.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.litecoin.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.litecoin.on('event_name', callback); -​//Example -window.xfi.litecoin.on('close', () => window.location.reload()); -window.xfi.litecoin.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/maya.md b/developers/maya.md deleted file mode 100644 index f109b775a..000000000 --- a/developers/maya.md +++ /dev/null @@ -1,134 +0,0 @@ -# Maya Protocol (MAYA) - -Welcome to the XDEFI Wallet Maya Protocol integration guide. - -### Detect XDEFI Wallet with Maya Protocol - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.mayachain.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.mayachain.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.mayachain.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.mayachain.on('event_name', callback); -​//Example -window.xfi.mayachain.on('close', () => window.location.reload()); -window.xfi.mayachain.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/near.md b/developers/near.md deleted file mode 100644 index 7c43ff3fe..000000000 --- a/developers/near.md +++ /dev/null @@ -1,134 +0,0 @@ -# Near Protocol (NEAR) - -Welcome to the XDEFI Wallet NEAR integration guide. - -### Detect XDEFI Wallet with NEAR - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.near.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.near.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.near.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.near.on('event_name', callback); -​//Example -window.xfi.near.on('close', () => window.location.reload()); -window.xfi.near.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/optimism.md b/developers/optimism.md deleted file mode 100644 index 13e78fbbb..000000000 --- a/developers/optimism.md +++ /dev/null @@ -1,352 +0,0 @@ -# Optimism (ETH) - -Optimism is a layer 2 scaling solution for Ethereum, which is designed to enable fast, secure, and low-cost transactions. It is built on the Optimistic Ethereum (OΞ) protocol, which is an Ethereum Virtual Machine (EVM) compatible layer 2 scaling solution. Optimism is designed to be a general-purpose scaling solution, which means that it can be used to scale any Ethereum application, including DeFi, NFTs, and more. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/bitcoin.md b/developers/other-blockchains.md similarity index 70% rename from developers/bitcoin.md rename to developers/other-blockchains.md index 143c36eae..bcafac1e0 100644 --- a/developers/bitcoin.md +++ b/developers/other-blockchains.md @@ -1,8 +1,22 @@ -# Bitcoin (BTC) - -Welcome to the XDEFI Wallet Bitcoin integration guide. - -### Detect XDEFI Wallet with Bitcoin +# Other Blockchains + +Native blockchains supported + +| Blockchain | Chain ID | xfi[chainId] | +| ---------------- | ------------- | ------------------------ | +| BNB Beacon Chain | `binance` | `window.xfi.binance` | +| Bitcoin | `bitcoin` | `window.xfi.bitcoin` | +| Bitcoin Cash | `bitcoincash` | `window.xfi.bitcoincash` | +| Cosmos | `cosmos` | `window.xfi.cosmos` | +| Dogecoin | `dogecoin` | `window.xfi.dogecoin` | +| Litecoin | `litecoin` | `window.xfi.litecoin` | +| Maya Protocol | `mayachain` | `window.xfi.mayachain` | +| NEAR Protocol | `near` | `window.xfi.near` | +| Solana | `solana` | `window.xfi.solana` | +| Terra | `terra` | `window.xfi.terra` | +| THORChain | `thorchain` | `window.xfi.thorchain` | + +### Detect XDEFI Wallet To detect whether your browser is running XDEFI Wallet, you can use the following code: @@ -15,6 +29,8 @@ if (window.xfi) { Notice: `window.xfi` which is a global object added by XDEFI Wallet. +Below is an example of how to detect XDEFI Wallet with Bitcoin (BTC): `window.xfi.bitcoin` +
### Connect to XDEFI Wallet @@ -23,7 +39,7 @@ To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] accou ```javascript // Connect & get accounts -window.xfi.bitcoin.request( +window.xfi[chainId].request( { method: "request_accounts", params: [] }, (error, accounts) => { if (error) { @@ -43,7 +59,7 @@ When your account is connected to XDEFI Wallet, let's start experiencing more fu #### Get the current account ```javascript -window.xfi.bitcoin.request( +window.xfi[chainId].request( { method: "request_accounts", params: [] }, (error, accounts) => { if (error) { @@ -63,7 +79,7 @@ Above code will return `Promise` #### Transfer ```javascript -window.xfi.bitcoin.request( +window.xfi[chainId].request( { method: "transfer", params: [ @@ -93,10 +109,10 @@ Return `Promise` with the transaction hash Currently we only support some action events from Wallet ```javascript -window.xfi.bitcoin.on('event_name', callback); +window.xfi[chainId].on('event_name', callback); ​//Example -window.xfi.bitcoin.on('close', () => window.location.reload()); -window.xfi.bitcoin.on('accountsChanged', () => window.location.reload()); +window.xfi[chainId].on('close', () => window.location.reload()); +window.xfi[chainId].on('accountsChanged', () => window.location.reload()); ``` #### Events supported diff --git a/developers/polygon.md b/developers/polygon.md deleted file mode 100644 index 0a90bf4b1..000000000 --- a/developers/polygon.md +++ /dev/null @@ -1,352 +0,0 @@ -# Polygon (MATIC) - -Polygon is a protocol and a framework for building and connecting Ethereum-compatible blockchain networks. Aggregating scalable solutions on Ethereum supporting a multi-chain Ethereum ecosystem. - -This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key - -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/solana.md b/developers/solana.md deleted file mode 100644 index d569006b1..000000000 --- a/developers/solana.md +++ /dev/null @@ -1,134 +0,0 @@ -# Solana (SOL) - -Welcome to the XDEFI Wallet Solana integration guide. - -### Detect XDEFI Wallet with Solana - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.solana.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.solana.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.solana.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.solana.on('event_name', callback); -​//Example -window.xfi.solana.on('close', () => window.location.reload()); -window.xfi.solana.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/terra.md b/developers/terra.md deleted file mode 100644 index a8d22d6e1..000000000 --- a/developers/terra.md +++ /dev/null @@ -1,134 +0,0 @@ -# Terra (LUNA) - -Welcome to the XDEFI Wallet Terra integration guide. - -### Detect XDEFI Wallet with Terra - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.terra.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.terra.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.terra.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.terra.on('event_name', callback); -​//Example -window.xfi.terra.on('close', () => window.location.reload()); -window.xfi.terra.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - diff --git a/developers/thorchain.md b/developers/thorchain.md deleted file mode 100644 index 238a0a3f8..000000000 --- a/developers/thorchain.md +++ /dev/null @@ -1,134 +0,0 @@ -# THORChain (RUNE) - -Welcome to the XDEFI Wallet THORChain integration guide. - -### Detect XDEFI Wallet with THORChain - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if (window.xfi) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.xfi` which is a global object added by XDEFI Wallet. - -
- -### Connect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.xfi.thorchain.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } else { - console.log("Account connected:", accounts[0]); - } - }, -); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.xfi.thorchain.request( - { method: "request_accounts", params: [] }, - (error, accounts) => { - if (error) { - console.error(error); - return; - } - console.log("Accounts:", accounts); - // Do something with the accounts - }, -); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.xfi.thorchain.request( - { - method: "transfer", - params: [ - { - asset: "string", - from: "string", - recipient: "string", - amount: "string", - memo: "string", - }, - ], - }, - (error, result) => { - if (error) { - console.error(error); - return; - } - console.log("Transaction hash:", result); - }, -); -``` - -Return `Promise` with the transaction hash - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.xfi.thorchain.on('event_name', callback); -​//Example -window.xfi.thorchain.on('close', () => window.location.reload()); -window.xfi.thorchain.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - From f89a19b51c2c9f2a714b0a3c8dcb7e965e702119 Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Wed, 20 Mar 2024 14:39:35 +0700 Subject: [PATCH 09/14] chore: update typo --- developers/blockchains-integration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/developers/blockchains-integration.md b/developers/blockchains-integration.md index 90ccbb2f4..c1f1ce48c 100644 --- a/developers/blockchains-integration.md +++ b/developers/blockchains-integration.md @@ -11,7 +11,7 @@ next: XDEFI is the largest multichain wallet that provides hundreds of blockchains accessibility. -- [EVMs (Ethereum ecosystem) and the Ethereum](./ethereum) +- [EVM's and Ethereum](./ethereum) - Ethereum(ETH) - Arbitrum(AETH) - Aurora(AURORA) From 42ee9962e1332b554f9c594d3952876ab8556af2 Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Wed, 20 Mar 2024 14:40:10 +0700 Subject: [PATCH 10/14] chore: update typo --- developers/blockchains-integration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/developers/blockchains-integration.md b/developers/blockchains-integration.md index c1f1ce48c..01fc7c09a 100644 --- a/developers/blockchains-integration.md +++ b/developers/blockchains-integration.md @@ -11,7 +11,7 @@ next: XDEFI is the largest multichain wallet that provides hundreds of blockchains accessibility. -- [EVM's and Ethereum](./ethereum) +- [Ethereum and EVM's](./ethereum) - Ethereum(ETH) - Arbitrum(AETH) - Aurora(AURORA) From d14500e5863e7dda69526a39295459a90a9b9c5c Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Wed, 20 Mar 2024 16:57:23 +0700 Subject: [PATCH 11/14] docs: update --- .vitepress/config.ts | 93 ++++++- developers/_evm.md | 346 +++++++++++++++++++++++++ developers/_xfi.md | 113 ++++++++ developers/arbitrum.md | 7 + developers/aurora.md | 7 + developers/avalanche.md | 7 + developers/bitcoin-cash.md | 26 ++ developers/bitcoin.md | 26 ++ developers/blockchains-integration.md | 52 ++-- developers/bnb-beacon-chain.md | 26 ++ developers/bnb-smart-chain.md | 7 + developers/canto.md | 7 + developers/cosmos.md | 26 ++ developers/cronos.md | 7 + developers/dogecoin.md | 26 ++ developers/ethereum.md | 355 +------------------------- developers/fantom.md | 7 + developers/gnosis.md | 7 + developers/litecoin.md | 26 ++ developers/maya.md | 26 ++ developers/near.md | 26 ++ developers/optimism.md | 7 + developers/polygon.md | 7 + developers/solana.md | 26 ++ developers/terra.md | 26 ++ developers/thorchain.md | 26 ++ 26 files changed, 939 insertions(+), 376 deletions(-) create mode 100644 developers/_evm.md create mode 100644 developers/_xfi.md create mode 100644 developers/arbitrum.md create mode 100644 developers/aurora.md create mode 100644 developers/avalanche.md create mode 100644 developers/bitcoin-cash.md create mode 100644 developers/bitcoin.md create mode 100644 developers/bnb-beacon-chain.md create mode 100644 developers/bnb-smart-chain.md create mode 100644 developers/canto.md create mode 100644 developers/cosmos.md create mode 100644 developers/cronos.md create mode 100644 developers/dogecoin.md create mode 100644 developers/fantom.md create mode 100644 developers/gnosis.md create mode 100644 developers/litecoin.md create mode 100644 developers/maya.md create mode 100644 developers/near.md create mode 100644 developers/optimism.md create mode 100644 developers/polygon.md create mode 100644 developers/solana.md create mode 100644 developers/terra.md create mode 100644 developers/thorchain.md diff --git a/.vitepress/config.ts b/.vitepress/config.ts index 70a022d6f..0901dbe90 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -541,12 +541,99 @@ function sidebarHome() { link: "/developers/blockchains-integration", }, { - text: "Ethereum (EVM's)", + text: "EVM's", link: "/developers/ethereum", + collapsed: true, + items: [ + { + text: "Ethereum(ETH)", + link: "/developers/ethereum", + }, + { + text: "Arbitrum(AETH)", + link: "/developers/arbitrum", + }, + { + text: "Aurora (AURORA)", + link: "/developers/aurora", + }, + { + text: "Avalanche (AVAX)", + link: "/developers/avalanche", + }, + { + text: "BNB Smart Chain (BNB)", + link: "/developers/bnb-smart-chain", + }, + { + text: "Canto (CANTO)", + link: "/developers/canto", + }, + { + text: "Cronos (CRO)", + link: "/developers/cronos", + }, + { + text: "Fantom (FTM)", + link: "/developers/fantom", + }, + { + text: "Gnosis (xDAI)", + link: "/developers/gnosis", + }, + { + text: "Optimism (ETH)", + link: "/developers/optimism", + }, + { + text: "Polygon (MATIC)", + link: "/developers/polygon", + }, + ], + }, + { + text: "Bitcoin (BTC)", + link: "/developers/bitcoin", + }, + { + text: "Bitcoin Cash (BCH)", + link: "/developers/bitcoin-cash", + }, + { + text: "BNB Beacon Chain (BNB)", + link: "/developers/bnb-beacon-chain", + }, + { + text: "Cosmos (ATOM)", + link: "/developers/cosmos", + }, + { + text: "Dogecoin (DOGE)", + link: "/developers/dogecoin", + }, + { + text: "Litecoin (LTC)", + link: "/developers/litecoin", + }, + { + text: "Maya Protocol (MAYA)", + link: "/developers/maya", + }, + { + text: "NEAR (NEAR)", + link: "/developers/near", + }, + { + text: "Solana (SOL)", + link: "/developers/solana", + }, + { + text: "Terra (LUNA)", + link: "/developers/terra", }, { - text: "Other Blockchains", - link: "/developers/other-blockchains", + text: "Thorchain (RUNE)", + link: "/developers/thorchain", }, ], }, diff --git a/developers/_evm.md b/developers/_evm.md new file mode 100644 index 000000000..73e795943 --- /dev/null +++ b/developers/_evm.md @@ -0,0 +1,346 @@ +### Detect XDEFI Wallet with Ethereum + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if ( + (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || + window.xfi +) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. + +The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` + +
+ +### Connect/Disconnect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.ethereum.request({method: 'eth_accounts'}); +// Alias for connection +window.ethereum.request({method: 'eth_requestAccounts'});​ +// Check if dapp connected +window.ethereum.isConnected(); +// Check if the caller's current permissions +window.ethereum.request({method: 'wallet_getPermissions'}); +// Check if request the given permissions +window.ethereum.request({method: 'wallet_requestPermissions'}); +``` + +To disconnect from XDEFI Wallet, please use: + +```javascript +window.ethereum.disconnect(); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { + if (accounts.length > 0) { + console.log("Current account:", accounts[0]); + // Do something with the account + } else { + console.log("No account connected"); + // Do something else + } +}); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +#### Check wallet whether it is connected(exists) or not + +```javascript +window.ethereum + .request({ method: "has_wallet", params: ["ethereum"] }) + .then(() => { + // Wallet is connected + }) + .catch((e) => { + // Wallet not found (not exist) + }); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` + +#### Sign Transaction + +```javascript +// Example Sign Transactionconst +const signature = window.ethereum.request({ + method: 'eth_signTransaction', + params: [ + "from": "string", + "to": "string", + "gas": "string", + "gasPrice": "string", + "value": "string", + "data": "string", + "nonce": "string" + ] +}); +``` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.ethereum.request({ + method: "eth_sendTransaction", + params: [ + { + from: "string", + to: "string", + gas: "string", + gasPrice: "string", + value: "string", + data: "string", + nonce: "string", + }, + ], +}); +``` + +Return `Promise` with the transaction hash + +#### Decrypt Message + +```javascript +window.ethereum + .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) + .then((decryptedMessage) => + console.log("The decrypted message is:", decryptedMessage), + ) + .catch((error) => console.log(error.message)); +``` + +Above code will return `Promise` with the decrypted message + +#### Get Encryption Public Key + +Return `Promise` with the public key + +```javascript +let encryptionPublicKey; +window.ethereum + .request({ + method: "eth_getEncryptionPublicKey", + params: [accounts[0]], // You must have access to the specified account + }) + .then((result) => { + encryptionPublicKey = result; + }) + .catch((error) => { + if (error.code === 4001) { + // EIP-1193 userRejectedRequest error + console.log("Can't encrypt anything without the key."); + } else { + console.error(error); + } + }); +``` + +#### Encrypt Message + +```javascript +const ethUtil = require('ethereumjs-util'); +const encryptedMessage = ethUtil.bufferToHex( + Buffer.from( + JSON.stringify( + sigUtil.encrypt( + { + publicKey: encryptionPublicKey, + data: 'Hello, World!, + version: 'x25519-xsalsa20-poly1305', + } + ) + ), + 'utf8' + ) +); +``` + +#### Add Ethereum Chain + +```javascript +window.ethereum.request +interface AddEthereumChainParameter { + chainId: string; // A 0x-prefix hex string + chainName: string; + nativeCurrency: { + name: string; + symbol: string; // 2-6 characters long + decimals: 18; + }; + rpcUrls: string[]; + blockExplorerUrls?: string[]; + iconUrls?: string[]; // Currently ignored +} +``` + +Return `Promise` with the result + +#### Switch Ethereum Chain + +Return `Promise` with the result, and an error otherwise + +```javascript +try { + await window.await ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: '0xf00' }], + }); +} catch (switchError) { + if (switchError.code === 4902) { + try { + await ethereum.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: '0xf00', + chainName: '...', + rpcUrls: ['https://...'] /* ... */, + }, + ], + }); + } catch (addError) { + // handle "add" error + } + } + // handle other "switch" errors +} +``` + +#### Watch Asset + +Return true if the token was added, false otherwise + +```javascript +window.ethereum + .request({ + method: "wallet_watchAsset", + params: { + type: "ERC20", + options: { + address: "0x1234567890123456789012345678901234567890", + symbol: "FOO", + decimals: 18, + image: "https://example.com/token-image.png", + }, + }, + }) + .then((success) => { + if (success) { + console.log("FOO successfully added to wallet!"); + } else { + throw new Error("Something went wrong."); + } + }) + .catch(console.error); +``` + +#### RPC Request + +Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) + +```javascript +window.ethereum.request({method: '', params: [args1,....]}) +``` + +### Subscription + +Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. + +#### Methods + +```javascript +// For Subscribe +window.ethereum + .request({ + method: "eth_subscribe", + params: ["", ""], + }) + .then((subscriptionId) => { + console.log("Subscription ID:", subscriptionId); + // Do something with the subscription ID + }); + +// For Unsubscribe +window.ethereum.request({ + method: "eth_unsubscribe", + params: [""], +}); +``` + +#### Example + +```javascript +// Subscribe for event +const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { + address: "0x1234567890123456789012345678901234567890", + topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] +}) +// You can listen for incoming notifications by +window.ethereum.on("data", data => { + // Do the rest of your work with data +}) +``` + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.ethereum.on('event_name', callback); +​//Example +window.ethereum.on('close', () => window.location.reload()); +window.ethereum.on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/_xfi.md b/developers/_xfi.md new file mode 100644 index 000000000..a20d6ac0e --- /dev/null +++ b/developers/_xfi.md @@ -0,0 +1,113 @@ +### Detect XDEFI Wallet + +To detect whether your browser is running XDEFI Wallet, you can use the following code: + +```javascript +if (window.xfi) { + console.log("XDEFI Wallet detected"); + // Your code here +} +``` + +Notice: `window.xfi` which is a global object added by XDEFI Wallet. + +### Connect to XDEFI Wallet + +To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: + +```javascript +// Connect & get accounts +window.xfi[chainId].request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } else { + console.log("Account connected:", accounts[0]); + } + }, +); +``` + +### Experience functions + +When your account is connected to XDEFI Wallet, let's start experiencing more functions. + +#### Get the current account + +```javascript +window.xfi[chainId].request( + { method: "request_accounts", params: [] }, + (error, accounts) => { + if (error) { + console.error(error); + return; + } + console.log("Accounts:", accounts); + // Do something with the accounts + }, +); +``` + +Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` + +Above code will return `Promise` + +#### Transfer + +```javascript +window.xfi[chainId].request( + { + method: "transfer", + params: [ + { + asset: "string", + from: "string", + recipient: "string", + amount: "string", + memo: "string", + }, + ], + }, + (error, result) => { + if (error) { + console.error(error); + return; + } + console.log("Transaction hash:", result); + }, +); +``` + +Return `Promise` with the transaction hash + +### Events + +Currently we only support some action events from Wallet + +```javascript +window.xfi[chainId].on('event_name', callback); +​//Example +window.xfi[chainId].on('close', () => window.location.reload()); +window.xfi[chainId].on('accountsChanged', () => window.location.reload()); +``` + +#### Events supported + +| Events | Trigger | +| ----------------- | --------------------------------------------- | +| `accountsChanged` | Receive when active account changed in Wallet | +| `networkChanged` | Receive when active network changed in Wallet | +| `chainChanged` | Receive when active chain changed in Wallet | +| `close` | Alias for disconnect event | +| `disconnect` | Receive when disconnecting from Wallet | + +#### Methods supported + +| Methods | Description | +| ---------------------- | --------------------- | +| `on(event, callback)` | Add event listener | +| `off(event, callback)` | Remove event listener | + + diff --git a/developers/arbitrum.md b/developers/arbitrum.md new file mode 100644 index 000000000..df1f3576a --- /dev/null +++ b/developers/arbitrum.md @@ -0,0 +1,7 @@ +# Arbitrum (AETH) + +Arbitrum is a layer 2 scaling solution for Ethereum. It is a sidechain that uses a technology called rollups to process transactions off-chain and then batch them into a single transaction that is submitted to the Ethereum mainnet. This allows for faster and cheaper transactions. + +This document based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/aurora.md b/developers/aurora.md new file mode 100644 index 000000000..5ea1699e6 --- /dev/null +++ b/developers/aurora.md @@ -0,0 +1,7 @@ +# Aurora (AURORA) + +Aurora is a multi-chain platform that unites Ethereum and the Aurora Network, a layer 2 blockchain that is compatible with Ethereum. Aurora is designed to provide a seamless experience for developers and users, with the goal of making it easy to build and use decentralized applications (dApps) on the Aurora Network. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/avalanche.md b/developers/avalanche.md new file mode 100644 index 000000000..2dfc60f5b --- /dev/null +++ b/developers/avalanche.md @@ -0,0 +1,7 @@ +# Avalanche (AVAX) + +Avalanche is an open-source platform for launching decentralized applications and enterprise blockchain deployments in one interoperable, highly scalable ecosystem. Avalanche is the first decentralized platform that confirms transactions in under one second, supports the entirety of the Ethereum development toolkit, and enables millions of independent validators to participate as full block producers. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/bitcoin-cash.md b/developers/bitcoin-cash.md new file mode 100644 index 000000000..d8372aa68 --- /dev/null +++ b/developers/bitcoin-cash.md @@ -0,0 +1,26 @@ +# Bitcoin Cash (BCH) + + + +And `bitcoincash` is the `chainId` for Bitcoin Cash. + +
+ + + + diff --git a/developers/bitcoin.md b/developers/bitcoin.md new file mode 100644 index 000000000..fc8b8ea2f --- /dev/null +++ b/developers/bitcoin.md @@ -0,0 +1,26 @@ +# Bitcoin (BTC) + + + +And `bitcoin` is the `chainId` for Bitcoin. + +
+ + + + diff --git a/developers/blockchains-integration.md b/developers/blockchains-integration.md index 01fc7c09a..8164e6caf 100644 --- a/developers/blockchains-integration.md +++ b/developers/blockchains-integration.md @@ -3,35 +3,35 @@ prev: text: "Mobile Wallet Integration" link: "./mobile-wallet" next: - text: "Akash (AKT)" - link: "./akash" + text: "Ethereum (ETH)" + link: "./ethereum" --- # Blockchains Integration XDEFI is the largest multichain wallet that provides hundreds of blockchains accessibility. -- [Ethereum and EVM's](./ethereum) - - Ethereum(ETH) - - Arbitrum(AETH) - - Aurora(AURORA) - - Avalanche(AVAX) - - Binance Smart Chain(BSC) - - Canto Network(CANTO) - - Cronos(CRO) - - Fantom(FTM) - - Gnosis(xDAI) - - Optimism(OPTIMISM) - - Polygon(MATIC) -- [Other Blockchains](./other-blockchains) - - BNB Beacon Chain (BNB) - - Bitcoin(BTC) - - Bitcoin Cash(BCH) - - Cosmos(ATOM) - - Dogecoin(DOGE) - - Litecoin(LTC) - - Maya Protocol(MAYA) - - NEAR Protocol(NEAR) - - Solana(SOL) - - Terra(LUNA) - - THORChain(RUNE) +- EVM's + - [Ethereum (ETH)](./ethereum) + - [Arbitrum (AETH)](./arbitrum) + - [Aurora (AURORA)](./aurora) + - [Avalanche (AVAX)](./avalanche) + - [Binance Smart Chain (BSC)](./bnb-smart-chain) + - [Canto Network (CANTO)](./canto) + - [Cronos (CRO)](./cronos) + - [Fantom (FTM)](./fantom) + - [Gnosis (xDAI)](./gnosis) + - [Optimism (OPTIMISM)](./optimism) + - [Polygon (MATIC)](./polygon) +- Other Blockchains + - [BNB Beacon Chain (BNB)](./bnb-beacon-chain) + - [Bitcoin (BTC)](./bitcoin) + - [Bitcoin Cash (BCH)](./bitcoin-cash) + - [Cosmos (ATOM)](./cosmos) + - [Dogecoin (DOGE)](./dogecoin) + - [Litecoin (LTC)](./litecoin) + - [Maya Protocol (MAYA)](./maya) + - [NEAR Protocol (NEAR)](./near) + - [Solana (SOL)](./solana) + - [Terra (LUNA)](./terra) + - [THORChain (RUNE)](./thorchain) diff --git a/developers/bnb-beacon-chain.md b/developers/bnb-beacon-chain.md new file mode 100644 index 000000000..e937eea69 --- /dev/null +++ b/developers/bnb-beacon-chain.md @@ -0,0 +1,26 @@ +# BNB Beacon Chain (BNB) + + + +And `binance` is the `chainId` for BNB Beacon Chain. + +
+ + + + diff --git a/developers/bnb-smart-chain.md b/developers/bnb-smart-chain.md new file mode 100644 index 000000000..05eefe4cf --- /dev/null +++ b/developers/bnb-smart-chain.md @@ -0,0 +1,7 @@ +# BNB Smart Chain (BNB) + +BNB Smart Chain is a blockchain platform that allows developers to build and deploy decentralized applications. It is a fast and low-cost blockchain that runs in parallel with Binance Chain. BNB Smart Chain is compatible with the Ethereum Virtual Machine (EVM), which means it supports the Ethereum toolchain and Solidity smart contracts. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/canto.md b/developers/canto.md new file mode 100644 index 000000000..64ce6af74 --- /dev/null +++ b/developers/canto.md @@ -0,0 +1,7 @@ +# Canto (CANTO) + +Canto is a multi-chain wallet that allows users to manage their digital assets and interact with decentralized applications (dApps) on various blockchains. Canto is a non-custodial wallet, meaning that users have full control over their assets and private keys. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/cosmos.md b/developers/cosmos.md new file mode 100644 index 000000000..54f637be2 --- /dev/null +++ b/developers/cosmos.md @@ -0,0 +1,26 @@ +# Cosmos (ATOM) + + + +And `cosmos` is the `chainId` for Cosmos. + +
+ + + + diff --git a/developers/cronos.md b/developers/cronos.md new file mode 100644 index 000000000..b360fa8a3 --- /dev/null +++ b/developers/cronos.md @@ -0,0 +1,7 @@ +# Cronos (CRO) + +Cronos is a blockchain network that is powered by the EVM (Ethereum Virtual Machine) and is fully compatible with the Ethereum ecosystem. It is designed to be a decentralized, secure, and scalable platform that can support a wide range of decentralized applications, including DeFi, NFTs, and more. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/dogecoin.md b/developers/dogecoin.md new file mode 100644 index 000000000..a9b4df6ee --- /dev/null +++ b/developers/dogecoin.md @@ -0,0 +1,26 @@ +# Dogecoin (DOGE) + + + +And `dogecoin` is the `chainId` for Dogecoin. + +
+ + + + diff --git a/developers/ethereum.md b/developers/ethereum.md index 40e558dac..02e44c6a8 100644 --- a/developers/ethereum.md +++ b/developers/ethereum.md @@ -1,350 +1,11 @@ -# Ethereum (EVM's) +--- +next: + text: "Arbitrum (AETH)" + link: "./arbitrum" +--- -Welcome to the XDEFI Wallet Ethereum integration guide. This guide will help you to integrate your Ethereum-based DApp with XDEFI Wallet. - -### Detect XDEFI Wallet with Ethereum - -To detect whether your browser is running XDEFI Wallet, you can use the following code: - -```javascript -if ( - (typeof window.ethereum !== "undefined" && window.ethereum?._XDEFI) || - window.xfi -) { - console.log("XDEFI Wallet detected"); - // Your code here -} -``` - -Notice: `window.ethereum` is a standard Ethereum provider object, and `window.ethereum._XDEFI` is a property added by XDEFI Wallet. If `window.ethereum` is not available, you can also check `window.xfi` which is a global object added by XDEFI Wallet. - -The XDEFI Wallet on Ethereum JavaScript provider API is specified by [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) and [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963). Support `window.ethereum` only and removal `window.web3` - -
- -### Connect/Disconnect to XDEFI Wallet - -To connect to XDEFI Wallet (access the user's [blockchain - like Ethereum] account(s)), you can use the following code: - -```javascript -// Connect & get accounts -window.ethereum.request({method: 'eth_accounts'}); -// Alias for connection -window.ethereum.request({method: 'eth_requestAccounts'});​ -// Check if dapp connected -window.ethereum.isConnected(); -// Check if the caller's current permissions -window.ethereum.request({method: 'wallet_getPermissions'}); -// Check if request the given permissions -window.ethereum.request({method: 'wallet_requestPermissions'}); -``` - -To disconnect from XDEFI Wallet, please use: - -```javascript -window.ethereum.disconnect(); -``` - -### Experience functions - -When your account is connected to XDEFI Wallet, let's start experiencing more functions. - -#### Get the current account - -```javascript -window.ethereum.request({ method: "eth_accounts" }).then((accounts) => { - if (accounts.length > 0) { - console.log("Current account:", accounts[0]); - // Do something with the account - } else { - console.log("No account connected"); - // Do something else - } -}); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `[]` instead of `throw Error` - -#### Check wallet whether it is connected(exists) or not - -```javascript -window.ethereum - .request({ method: "has_wallet", params: ["ethereum"] }) - .then(() => { - // Wallet is connected - }) - .catch((e) => { - // Wallet not found (not exist) - }); -``` - -Above code will return `Promise` with the current account address. If wallet can not be found, return `false` instead of `throw Error` - -#### Sign Transaction - -```javascript -// Example Sign Transactionconst -const signature = window.ethereum.request({ - method: 'eth_signTransaction', - params: [ - "from": "string", - "to": "string", - "gas": "string", - "gasPrice": "string", - "value": "string", - "data": "string", - "nonce": "string" - ] -}); -``` - -Above code will return `Promise` - -#### Transfer - -```javascript -window.ethereum.request({ - method: "eth_sendTransaction", - params: [ - { - from: "string", - to: "string", - gas: "string", - gasPrice: "string", - value: "string", - data: "string", - nonce: "string", - }, - ], -}); -``` - -Return `Promise` with the transaction hash - -#### Decrypt Message - -```javascript -window.ethereum - .request({ method: "eth_decrypt", params: [encryptedMessage, accounts[0]] }) - .then((decryptedMessage) => - console.log("The decrypted message is:", decryptedMessage), - ) - .catch((error) => console.log(error.message)); -``` - -Above code will return `Promise` with the decrypted message - -#### Get Encryption Public Key - -Return `Promise` with the public key +# Ethereum (ETH) -```javascript -let encryptionPublicKey; -window.ethereum - .request({ - method: "eth_getEncryptionPublicKey", - params: [accounts[0]], // You must have access to the specified account - }) - .then((result) => { - encryptionPublicKey = result; - }) - .catch((error) => { - if (error.code === 4001) { - // EIP-1193 userRejectedRequest error - console.log("Can't encrypt anything without the key."); - } else { - console.error(error); - } - }); -``` - -#### Encrypt Message - -```javascript -const ethUtil = require('ethereumjs-util'); -const encryptedMessage = ethUtil.bufferToHex( - Buffer.from( - JSON.stringify( - sigUtil.encrypt( - { - publicKey: encryptionPublicKey, - data: 'Hello, World!, - version: 'x25519-xsalsa20-poly1305', - } - ) - ), - 'utf8' - ) -); -``` - -#### Add Ethereum Chain - -```javascript -window.ethereum.request -interface AddEthereumChainParameter { - chainId: string; // A 0x-prefix hex string - chainName: string; - nativeCurrency: { - name: string; - symbol: string; // 2-6 characters long - decimals: 18; - }; - rpcUrls: string[]; - blockExplorerUrls?: string[]; - iconUrls?: string[]; // Currently ignored -} -``` - -Return `Promise` with the result - -#### Switch Ethereum Chain - -Return `Promise` with the result, and an error otherwise - -```javascript -try { - await window.await ethereum.request({ - method: 'wallet_switchEthereumChain', - params: [{ chainId: '0xf00' }], - }); -} catch (switchError) { - if (switchError.code === 4902) { - try { - await ethereum.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: '0xf00', - chainName: '...', - rpcUrls: ['https://...'] /* ... */, - }, - ], - }); - } catch (addError) { - // handle "add" error - } - } - // handle other "switch" errors -} -``` - -#### Watch Asset - -Return true if the token was added, false otherwise - -```javascript -window.ethereum - .request({ - method: "wallet_watchAsset", - params: { - type: "ERC20", - options: { - address: "0x1234567890123456789012345678901234567890", - symbol: "FOO", - decimals: 18, - image: "https://example.com/token-image.png", - }, - }, - }) - .then((success) => { - if (success) { - console.log("FOO successfully added to wallet!"); - } else { - throw new Error("Something went wrong."); - } - }) - .catch(console.error); -``` - -#### RPC Request - -Return `Promise` Currently only support HTTP(s) method Reference: [RPC Method](http://google.com) - -```javascript -window.ethereum.request({method: '', params: [args1,....]}) -``` - -### Subscription - -Support subscribe using JSON-RPC notifications. This allows clients to wait for events instead of polling for them. All results will be released at `data` event. - -#### Methods - -```javascript -// For Subscribe -window.ethereum - .request({ - method: "eth_subscribe", - params: ["", ""], - }) - .then((subscriptionId) => { - console.log("Subscription ID:", subscriptionId); - // Do something with the subscription ID - }); - -// For Unsubscribe -window.ethereum.request({ - method: "eth_unsubscribe", - params: [""], -}); -``` - -#### Example - -```javascript -// Subscribe for event -const subscriptionID = window.ethereum.request({method: 'eth_subscribe', params: ["logs", { - address: "0x1234567890123456789012345678901234567890", - topics: ["0x1234567890123456789012345678901234567890123456789012345678901234"] -}) -// You can listen for incoming notifications by -window.ethereum.on("data", data => { - // Do the rest of your work with data -}) -``` - -### Events - -Currently we only support some action events from Wallet - -```javascript -window.ethereum.on('event_name', callback); -​//Example -window.ethereum.on('close', () => window.location.reload()); -window.ethereum.on('accountsChanged', () => window.location.reload()); -``` - -#### Events supported - -| Events | Trigger | -| ----------------- | --------------------------------------------- | -| `accountsChanged` | Receive when active account changed in Wallet | -| `networkChanged` | Receive when active network changed in Wallet | -| `chainChanged` | Receive when active chain changed in Wallet | -| `close` | Alias for disconnect event | -| `disconnect` | Receive when disconnecting from Wallet | - -#### Methods supported - -| Methods | Description | -| ---------------------- | --------------------- | -| `on(event, callback)` | Add event listener | -| `off(event, callback)` | Remove event listener | - - + diff --git a/developers/fantom.md b/developers/fantom.md new file mode 100644 index 000000000..0106144be --- /dev/null +++ b/developers/fantom.md @@ -0,0 +1,7 @@ +# Fantom (FTM) + +Fantom is a high-performance, scalable, and secure smart-contract platform. It is designed to overcome the limitations of previous generation blockchain platforms. Fantom is permissionless, decentralized, and open-source. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/gnosis.md b/developers/gnosis.md new file mode 100644 index 000000000..ba91dab72 --- /dev/null +++ b/developers/gnosis.md @@ -0,0 +1,7 @@ +# Gnosis (xDAI) + +Gnosis is a decentralized prediction market platform built on Ethereum. It allows users to create, trade, and hold prediction shares of events. Gnosis is a decentralized platform for prediction markets, and xDAI is a sidechain of Ethereum. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/litecoin.md b/developers/litecoin.md new file mode 100644 index 000000000..8ee4371b9 --- /dev/null +++ b/developers/litecoin.md @@ -0,0 +1,26 @@ +# Litecoin (LTC) + + + +And `litecoin` is the `chainId` for Litecoin. + +
+ + + + diff --git a/developers/maya.md b/developers/maya.md new file mode 100644 index 000000000..9b440be67 --- /dev/null +++ b/developers/maya.md @@ -0,0 +1,26 @@ +# Maya Protocol (MAYA) + + + +And `mayachain` is the `chainId` for Maya Protocol. + +
+ + + + diff --git a/developers/near.md b/developers/near.md new file mode 100644 index 000000000..d9ee0c5ce --- /dev/null +++ b/developers/near.md @@ -0,0 +1,26 @@ +# NEAR (NEAR) + + + +And `near` is the `chainId` for NEAR Protocol. + +
+ + + + diff --git a/developers/optimism.md b/developers/optimism.md new file mode 100644 index 000000000..7b2f9d88a --- /dev/null +++ b/developers/optimism.md @@ -0,0 +1,7 @@ +# Optimism (ETH) + +Optimism is a layer 2 scaling solution for Ethereum, which is designed to enable fast, secure, and low-cost transactions. It is built on the Optimistic Ethereum (OΞ) protocol, which is an Ethereum Virtual Machine (EVM) compatible layer 2 scaling solution. Optimism is designed to be a general-purpose scaling solution, which means that it can be used to scale any Ethereum application, including DeFi, NFTs, and more. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/polygon.md b/developers/polygon.md new file mode 100644 index 000000000..5cf275174 --- /dev/null +++ b/developers/polygon.md @@ -0,0 +1,7 @@ +# Polygon (MATIC) + +Polygon is a protocol and a framework for building and connecting Ethereum-compatible blockchain networks. Aggregating scalable solutions on Ethereum supporting a multi-chain Ethereum ecosystem. + +This document is based on the EVMs (Ethereum Virtual Machine) and the Ethereum network. + + diff --git a/developers/solana.md b/developers/solana.md new file mode 100644 index 000000000..f341c6270 --- /dev/null +++ b/developers/solana.md @@ -0,0 +1,26 @@ +# Solana (SOL) + + + +And `solana` is the `chainId` for Solana. + +
+ + + + diff --git a/developers/terra.md b/developers/terra.md new file mode 100644 index 000000000..9af61e02a --- /dev/null +++ b/developers/terra.md @@ -0,0 +1,26 @@ +# Terra (LUNA) + + + +And `terra` is the `chainId` for Terra. + +
+ + + + diff --git a/developers/thorchain.md b/developers/thorchain.md new file mode 100644 index 000000000..d143ea485 --- /dev/null +++ b/developers/thorchain.md @@ -0,0 +1,26 @@ +# Thorchain (RUNE) + + + +And `thorchain` is the `chainId` for Thorchain. + +
+ + + + From 1cc93f57b106edf0a9d83038577fa3787b5f6403 Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Wed, 20 Mar 2024 17:03:21 +0700 Subject: [PATCH 12/14] chore: update --- developers/_xfi.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/developers/_xfi.md b/developers/_xfi.md index a20d6ac0e..9bec7b1f5 100644 --- a/developers/_xfi.md +++ b/developers/_xfi.md @@ -109,5 +109,3 @@ window.xfi[chainId].on('accountsChanged', () => window.location.reload()); | ---------------------- | --------------------- | | `on(event, callback)` | Add event listener | | `off(event, callback)` | Remove event listener | - - From 60b59e92ca946d8895f2d330c06af674d7853c57 Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Wed, 20 Mar 2024 17:18:37 +0700 Subject: [PATCH 13/14] docs: update for Cosmos --- developers/cosmos.md | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/developers/cosmos.md b/developers/cosmos.md index 54f637be2..fde58e524 100644 --- a/developers/cosmos.md +++ b/developers/cosmos.md @@ -1,26 +1,3 @@ # Cosmos (ATOM) - - -And `cosmos` is the `chainId` for Cosmos. - -
- - - - +Comming soon... From f1521348d28b368ec9aacb6f4d5ee8d4fe53fca9 Mon Sep 17 00:00:00 2001 From: "Justin (HoangVD2)" Date: Wed, 20 Mar 2024 17:31:50 +0700 Subject: [PATCH 14/14] chore: fix typo --- developers/bitcoin-cash.md | 4 +--- developers/bitcoin.md | 4 +--- developers/bnb-beacon-chain.md | 4 +--- developers/dogecoin.md | 4 +--- developers/litecoin.md | 4 +--- developers/maya.md | 4 +--- developers/near.md | 4 +--- developers/solana.md | 4 +--- developers/terra.md | 4 +--- developers/thorchain.md | 4 +--- 10 files changed, 10 insertions(+), 30 deletions(-) diff --git a/developers/bitcoin-cash.md b/developers/bitcoin-cash.md index d8372aa68..c1dbb8f0f 100644 --- a/developers/bitcoin-cash.md +++ b/developers/bitcoin-cash.md @@ -1,8 +1,6 @@ # Bitcoin Cash (BCH) - - -And `bitcoincash` is the `chainId` for Bitcoin Cash. + And `bitcoincash` is the `chainId` for Bitcoin Cash.
diff --git a/developers/bitcoin.md b/developers/bitcoin.md index fc8b8ea2f..c3f1decd7 100644 --- a/developers/bitcoin.md +++ b/developers/bitcoin.md @@ -1,8 +1,6 @@ # Bitcoin (BTC) - - -And `bitcoin` is the `chainId` for Bitcoin. + And `bitcoin` is the `chainId` for Bitcoin.
diff --git a/developers/bnb-beacon-chain.md b/developers/bnb-beacon-chain.md index e937eea69..a855c63db 100644 --- a/developers/bnb-beacon-chain.md +++ b/developers/bnb-beacon-chain.md @@ -1,8 +1,6 @@ # BNB Beacon Chain (BNB) - - -And `binance` is the `chainId` for BNB Beacon Chain. + And `binance` is the `chainId` for BNB Beacon Chain.
diff --git a/developers/dogecoin.md b/developers/dogecoin.md index a9b4df6ee..ee71f4159 100644 --- a/developers/dogecoin.md +++ b/developers/dogecoin.md @@ -1,8 +1,6 @@ # Dogecoin (DOGE) - - -And `dogecoin` is the `chainId` for Dogecoin. + And `dogecoin` is the `chainId` for Dogecoin.
diff --git a/developers/litecoin.md b/developers/litecoin.md index 8ee4371b9..fe58dfda1 100644 --- a/developers/litecoin.md +++ b/developers/litecoin.md @@ -1,8 +1,6 @@ # Litecoin (LTC) - - -And `litecoin` is the `chainId` for Litecoin. + And `litecoin` is the `chainId` for Litecoin.
diff --git a/developers/maya.md b/developers/maya.md index 9b440be67..abb0d96e2 100644 --- a/developers/maya.md +++ b/developers/maya.md @@ -1,8 +1,6 @@ # Maya Protocol (MAYA) - - -And `mayachain` is the `chainId` for Maya Protocol. + And `mayachain` is the `chainId` for Maya Protocol.
diff --git a/developers/near.md b/developers/near.md index d9ee0c5ce..2cad34b62 100644 --- a/developers/near.md +++ b/developers/near.md @@ -1,8 +1,6 @@ # NEAR (NEAR) - - -And `near` is the `chainId` for NEAR Protocol. + And `near` is the `chainId` for NEAR Protocol.
diff --git a/developers/solana.md b/developers/solana.md index f341c6270..a9b9c6ec3 100644 --- a/developers/solana.md +++ b/developers/solana.md @@ -1,8 +1,6 @@ # Solana (SOL) - - -And `solana` is the `chainId` for Solana. + And `solana` is the `chainId` for Solana.
diff --git a/developers/terra.md b/developers/terra.md index 9af61e02a..60755d29a 100644 --- a/developers/terra.md +++ b/developers/terra.md @@ -1,8 +1,6 @@ # Terra (LUNA) - - -And `terra` is the `chainId` for Terra. + And `terra` is the `chainId` for Terra.
diff --git a/developers/thorchain.md b/developers/thorchain.md index d143ea485..c30846dbf 100644 --- a/developers/thorchain.md +++ b/developers/thorchain.md @@ -1,8 +1,6 @@ # Thorchain (RUNE) - - -And `thorchain` is the `chainId` for Thorchain. + And `thorchain` is the `chainId` for Thorchain.