# SignAndSendTransaction（签名并发送交易）

一旦连接成功，应用就可以请求用户授权代为发送交易。

要发送交易，应用需执行以下步骤：

1. 创建一个未签名交易；
2. 由用户的 Backpack 钱包签名并提交至网络；
3. 可选地使用 Solana JSON RPC 连接等待网络确认。

{% hint style="info" %}
有关 Solana 交易的更多信息，请参考 [solana-web3.js 文档](https://solana-labs.github.io/solana-web3.js/) 以及 [Solana Cookbook](https://solanacookbook.com/core-concepts/transactions.html#transactions)。
{% endhint %}

## **基础 URL**

```
https://backpack.app/ul/v1/signAndSendTransaction
```

## **查询字符串参数**

* `dapp_encryption_public_key`（必填）：用于现有[connect](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/provider-fang-fa/connect-lian-jie.md)（连接）会话的原始加密公钥。
* `nonce`（必填）：用于加密请求的 base58 编码随机数。
* `redirect_link`（必填）：操作完成后，Backpack 应将用户[Specifying Redirects](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/specifying-redirects-zhi-ding-zhong-ding-xiang.md)（重定向）至该 URI。需进行 URL 编码。
* `payload`（必填）：加密的 JSON 字符串，包含以下字段：

```json
{
  "transaction": "...", // 序列化的交易，base58 编码
  "sendOptions": "...", // 可选的 Solana web3.js sendOptions 对象
  "session": "...",     // 来自 connect 方法的 token
}
```

* `transaction`（必填）：Backpack 将签名并提交的[transaction](https://solana-labs.github.io/solana-web3.js/classes/Transaction.html)（交易）已经被序列化，并以 base58 编码表示。
* `sendOptions`（可选）：一个可选对象，用于指定 Backpack 应如何提交交易的选项。此对象在[ Solana 的 web3.js ](https://solana-labs.github.io/solana-web3.js/modules.html#SendOptions)中定义。
* `session`（必填）：通过 [Connect](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/provider-fang-fa/connect-lian-jie.md) 方法接收到的会话凭证。有关详细信息，请参阅 [Handling Sessions](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/handling-sessions-hui-hua-chu-li.md)。

## **返回值**

### Approve（同意）

* `nonce`：用于加密响应的 base58 编码随机数。
* `data`：加密的 JSON 字符串。参考[Encryption](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/encryption-jia-mi-ji-zhi.md)了解如何通过共享密钥解密。加密内容以 base58 编码。

```json
// 解密后的 `data` 参数内容
{  
    "signature": "..." // 交易签名
}
```

* `signature`：交易中的首个签名，可作为[transaction ID](https://docs.solana.com/terminology#transaction-id)。

### Reject（拒绝）

**`errorCode`**&#x548C; **`errorMessage`** 作为查询参数。请参阅 [Errors ](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/limitations-xian-zhi.md#errors-cuo-wu-chu-li)了解所有可能的错误代码列表。

```json
{
  "errorCode": "...",
  "errorMessage": "..."
}
```


---

# Agent Instructions: 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:

```
GET https://support.backpack.exchange/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/provider-fang-fa/signandsendtransaction-qian-ming-bing-fa-song-jiao-yi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
