Links

NEAR

Develop NEAR dApps

NEAR wallet-selector

XDEFI is a provider available in NEAR wallet-selector project. This allows dApp developer to allow XDEFI Wallet users to connect to their dApp with a single click.

window.xfi.near object

XDEFI Wallet provides a z object that dApp developers can use to interact with the XDEFI Wallet. The window.xfi.near object is available after the window.onLoad event is fired.
It is recommended to use the NEAR wallet-selector project to integrate XDEFI Wallet with your dApp. The wallet-selector project will take care of the window.xfi.near object for you.

window.xfi.near.request

Here is a sample code to request XDEFI Wallet to connect to a dApp.
window.xfi.near.request({
method: 'connect',
});
Methods
There are 4 methods available in window.xfi.near.request object.
connect
Returns a promise that resolves to a address[] object.
const addresses = await window.xfi.near.request({
method: 'connect',
});
disconnect
Disconnects the dApp from XDEFI Wallet.
await window.xfi.near.request({
method: 'disconnect',
});
signAndSendTransaction
Signs and sends a transaction to the blockchain. Returns the transaction hash.
type Transaction = {
signerId: string;
publicKey: PublicKey;
nonce: BN;
receiverId: string;
actions: Action[];
blockHash: Uint8Array;
};
​
const transaction : Transaction = {...};
​
const txHash: string = await window.xfi.near.request({
method: 'signAndSendTransaction',
params: {
transaction
},
})
signAndSendTransactions
Signs and sends multiple transactions to the blockchain. Returns the transaction hashes.
type Transaction = {
signerId: string;
publicKey: PublicKey;
nonce: BN;
receiverId: string;
actions: Action[];
blockHash: Uint8Array;
};
​
const transactions: Transaction[] = [{...}];
​
const txHashes: string[] = await window.xfi.near.request({
method: 'signAndSendTransactions',
params: {
transactions
},
})
Other function signatures
The previous functions are the most commonly used functions. However, there are other functions available in window.xfi.near object. See below the full list of functions.
connect: (network?: NETWORKS) => Promise<INearAccount[]>
disconnect: () => Promise<void>
signAndSendTransaction: (
transaction: NearTransaction
) => Promise<NearFinalExecutionOutcome>
signAndSendTransactions: (
transactions: Array<NearTransaction>
) => Promise<Array<NearFinalExecutionOutcome>>
Last modified 11mo ago
XDEFI Technologies 2024