锚点:如何要求Nodejs后端在不使用血清的Multisig的情况下从前端共同签名交易?

发布于 2025-02-12 02:59:00 字数 347 浏览 0 评论 0原文

理想情况下,我希望我的nodejs后端(可以确保按键)与Frontend应用程序共同签名交易(假设用户将使用他 /她的Solana Wallet签署交易)。后端的Pubkey也将作为锚定计划的签名帐户包括在内。

我看不到Anchor这样做的任何教程,希望这是有道理的。我当时认为前端将称为后端API传递序列化参数,后端将在该参数上签名,并将用其公共密钥将签名返回前端。

我不知道:

  • 用于签名交易的正确锚 /索拉纳Web3是什么,
  • 我该如何将(后端的)返回签名添加到

我最初不想使用Multisig使用此方法的交易中,因为它只会胜过事情。在提交交易之前只需要从后端进行一些确认即可。

Ideally, I want my Nodejs backend (which secures a keypair) to co-sign a transaction coming from the frontend app (assuming the user will sign the transaction using his / her Solana wallet). The pubkey of the backend will be also included as a signer account to the anchor program.

I can't see any tutorial from Anchor doing this, hopefully it makes sense. I was thinking that the frontend will call a backend API passing down the serialize parameters, on which the backend will sign, and will return a signature to the frontend with its public key.

I have no idea on:

  • What's the correct Anchor / Solana web3 to use to sign the transaction
  • How can I add the returning signature (of the backend) to the transaction

I initially don't want to use Multisig with this approach as it will just overcomplicate things. Just need some confirmation from the backend before submitting the transaction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一直在等你来 2025-02-19 02:59:00

您可能想做这样的事情(后端):

// create the transaction, with user's public key as the feePayer

// Sign the transaction as the backend
// We must partial sign because the transaction still requires the user signature
transaction.partialSign(backendKeypair)

// Serialize the transaction and convert to base64 to return it
const serializedTransaction = transaction.serialize({
  // We will need the buyer to sign this transaction after it's returned to them
 requireAllSignatures: false
})
const base64 = serializedTransaction.toString('base64')

// return base64 to the frontend

然后从前端开始:

// make sure you're passing user's public key in this request
const response = await fetch(`/your-api/`, {
  method: 'POST',
  ...
})

// assuming your API returns JSON
const json = await response.json()

// Deserialize the transaction from the response
const transaction = Transaction.from(Buffer.from(json.transaction, 'base64'));
    
// have the user sign transaction using their connected wallet 

You probably want to do something like this (backend):

// create the transaction, with user's public key as the feePayer

// Sign the transaction as the backend
// We must partial sign because the transaction still requires the user signature
transaction.partialSign(backendKeypair)

// Serialize the transaction and convert to base64 to return it
const serializedTransaction = transaction.serialize({
  // We will need the buyer to sign this transaction after it's returned to them
 requireAllSignatures: false
})
const base64 = serializedTransaction.toString('base64')

// return base64 to the frontend

Then from the frontend:

// make sure you're passing user's public key in this request
const response = await fetch(`/your-api/`, {
  method: 'POST',
  ...
})

// assuming your API returns JSON
const json = await response.json()

// Deserialize the transaction from the response
const transaction = Transaction.from(Buffer.from(json.transaction, 'base64'));
    
// have the user sign transaction using their connected wallet 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文