# Provider API

### connect (connect to wallet)

```javascript
const pubKey = await NaboxWalllet.solana.connect();

// 返回一个solana PublicKey对象
```

### signTransaction (sign solana transaction, do not broadcast)

```javascript
const provider = NaboxWallet.solana;
const network = "";
const connection = new Connection(network);
const transaction = new Transaction();
const res = await provider.signTransaction(transaction);

// 返回值示例
{
    tx: 'Signed transaction'
}
```

### signAndSendTransaction (sign solana transaction and broadcast)

```javascript
const provider = window.NaboxWallet.solana;
const network = "<NETWORK_URL>";
const connection = new Connection(network);
const transaction = new Transaction();
const res = await provider.signAndSendTransaction(transaction);

// 返回值示例
{
    signature: 'Transaction signature after broadcast',
    publicKey: 'The account address used for the current signature'
}
```

### signAllTransactions (Batch Signature Transactions)

```javascript
const provider = NaboxWallet.solana;
const network = "";
const connection = new Connection(network);
const transaction1 = new Transaction();
const transaction2 = new Transaction();
const res = await provider.signTransaction([transaction1, transaction2]);

// 返回值示例
{
   tx: 'Signed transaction array'
}
```

### signMessage(Message Signature)

```javascript
const message = `message`;
const encodedMessage = new TextEncoder().encode(message);
const signedMessage = await NaboxWallet.solana.signMessage(encodedMessage, "utf8");
```

### on(Monitoring Events)

```javascript
// Monitor whether it is connected
NaboxWallet.solana.on("connect", () => console.log("connected!"));

// Listening for disconnections
NaboxWallet.solana.on("disconnect", () => console.log("disconnected!"));

// Monitor account changes
NaboxWallet.solana.on("accountChanged", (publicKey) => console.log("publicKey"));
```
