> For the complete documentation index, see [llms.txt](https://docs.endless.link/endless/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.endless.link/endless/endless-wallet/wallet-adapter/functions.md).

# Functions

## 1. Connect to Endless Wallet

Call the connect method in SKD to obtain the current address of the wallet.

```javascript
import { UserResponseStatus } from '@endlesslab/endless-web3-sdk';

const connectRes = await jssdk.connect();

if (connectRes.status === UserResponseStatus.APPROVED) {
  // connected, you can get the wallet address
  // The wallet address is Base58 string
  console.log('wallet address: ', connectRes.args.account);
}else{
  // connect failed
}
```

## 2. GetAccount method

The getAccount method needs to be called after the wallet initialization is completed.

Call the getAccount method to obtain the current user wallet address of the endless wallet.

```javascript
import { EndLessSDKEvent } from '@endlesslab/endless-web3-sdk';

jssdk.on(EndLessSDKEvent.INIT, async () => {
  const getAccountRes = await jssdk.getAccount();
  if (getAccountRes.status === UserResponseStatus.APPROVED) {
    // The wallet address is Base58 string
    console.log('wallet address: ', connectRes.args.account);
  }else{
    // The user is not connected to the dapp or the current wallet has not been created.
  }
});
```

## 3. Disconnect method

Call the disconnect method in SKD to disconnect the dapp from the wallet.

```javascript
const disconnectRes = await jssdk.disconnect();
if (disconnectRes.status === UserResponseStatus.APPROVED) {
  // disconnected
}else{
  // disconnect failed
}
```

## 4. Signature message method

Call the signMessage method in SKD to sign the message and return the signed result.

```javascript
const signMessageRes = await jssdk.signMessage({ message: signMessage });

if (signMessageRes.status === UserResponseStatus.APPROVED) {
  // signed successfully
  console.log(signMessageRes.args.signature.toString());
}else{
  // sign failed
}
```

## 5. Sending a Transaction method

Call the signMessage method in SKD, Sign the message and send it to the Endless blockchain. After success, return the transaction hash.

The following code example demonstrates how to use the API to sign transactions and send them to the endless blockchain.

```javascript
import { EndlessSignAndSubmitTransactionInput } from '@endlesslab/endless-web3-sdk';

const transferData: EndlessSignAndSubmitTransactionInput = {
  payload: {
    function: '0x1::endless_account::transfer',
    functionArguments: [
      AccountAddress.fromBs58String(toAccountAddress),
      BigInt(transferAmount),
    ],
  },
};

const transactionRes = await jssdk.signAndSubmitTransaction(transferData);
if (transactionRes.status === UserResponseStatus.APPROVED) {
  console.log('transactionRes =====>', transactionRes);
}
```

## 6. Signature transaction method

The following code example demonstrates how to use the API to sign transactions.

```javascript
import { Endless, Network, EndlessConfig } from '@endlesslab/endless-ts-sdk';
import { 
  EndlessSignAndSubmitTransactionInput,
  EndlessWalletTransactionType
} from '@endlesslab/endless-web3-sdk';

const config = new EndlessConfig({
  network: Network.TESTNET
})
const endless = new Endless(config)

const transferData: EndlessSignAndSubmitTransactionInput = {
  payload: {
    function: '0x1::endless_account::transfer',
    functionArguments: [
      AccountAddress.fromBs58String(toAccountAddress),
      BigInt(transferAmount),
    ],
  },
};

const txn = await endless.transaction.build.simple({
  sender: accountAddress,
  data: transferData.payload
});

// EndlessWalletTransactionType.SIMPLE | EndlessWalletTransactionType.MULTI_AGENT
const transactionRes = await jssdk.signTransaction(txn, EndlessWalletTransactionType.SIMPLE);
if (transactionRes.status === UserResponseStatus.APPROVED) {
  console.log('transactionRes =====>', transactionRes);
}
```

## 7. Open view method

The following code example demonstrates how to use the API to open the Endless Wallet window.

```javascript
import { EndLessSDKEvent } from '@endlesslab/endless-web3-sdk';

jssdk.on(EndLessSDKEvent.INIT, async () => {
  await jssdk.open();
});
```

## 8. Add event listening method

This method is used to add an endless wallet event listening method.

```javascript
import { EndLessSDKEvent } from '@endlesslab/endless-web3-sdk';
jssdk.on(EndLessSDKEvent.INIT, async () => {
  console.log('init success');
});
```

## 9. Uninstall event listening method

This method is used to uninstall the Endless Wallet event listening method.

```javascript
import { EndLessSDKEvent } from '@endlesslab/endless-web3-sdk';
jssdk.off(EndLessSDKEvent.INIT, async () => {
  console.log('init success');
});
```

## 10. Transaction of sending EDS coins with script payload

```javascript
import { Endless, Network, EndlessConfig } from '@endlesslab/endless-ts-sdk';
import { 
  EndlessSignAndSubmitTransactionInput,
  EndlessWalletTransactionType
} from '@endlesslab/endless-web3-sdk';

const config = new EndlessConfig({
  network: Network.TESTNET
})
const endless = new Endless(config)

// byte code of the script of calling `endless_account::transfer_coins(...)`
const transferData: EndlessSignAndSubmitTransactionInput = {
  payload: {
    bytecode: 'a11ceb0b0600000007010004020406030a0604100205120e07202d084d2000000001010207010001000300010108000204060c05040b00010900000109000f656e646c6573735f6163636f756e74066f626a656374064f626a6563740e7472616e736665725f636f696e73000000000000000000000000000000000000000000000000000000000000000101080001060b000b010b020b03380002',
    functionArguments: [
      AccountAddress.fromBs58String(toAccountAddress),
      new U128(parseFloat(transferAmount) * 100000000),
      AccountAddress.fromBs58String('ENDLESSsssssssssssssssssssssssssssssssssssss'),
    ],
    typeArguments: ['0x1::fungible_asset::Metadata'],
  }
};

const txn = await endless.transaction.build.simple({
  sender: fromAccountAddress,
  data: transferData.payload
});

// EndlessWalletTransactionType.SIMPLE | EndlessWalletTransactionType.MULTI_AGENT
const transactionRes = await jssdk.signTransaction(txn, EndlessWalletTransactionType.SIMPLE);
if (transactionRes.status === UserResponseStatus.APPROVED) {
  console.log('transactionRes =====>', transactionRes);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.endless.link/endless/endless-wallet/wallet-adapter/functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
