gpt4 book ai didi

Are there any way to pay transaction cost from a hardware wallet when deploying contract using ethers.js?(在使用ethers.js部署合约时,是否有任何方法可以从硬件钱包支付交易成本?)

转载 作者:bug小助手 更新时间:2023-10-26 20:59:03 24 4
gpt4 key购买 nike



I am working on developing Dapp and facing a challenge.

我正在开发DAPP,并面临着一项挑战。


▶ Thing I want to achieve ◀

▶我想要实现的事情◀



  • I'd like to create a new wallet instance, then when deploying a contract, I want to pay transaction costs from a signer wallet which would be a hardware wallet like Trezor/Ledger.


▶ Problems that I'm facing ◀

我面临的▶问题◀



  • Since I cannot retrieve private keys from a hardware wallet, I can only create the new wallet with createRandom() method in ethers.js, which means I cannot technically connect the hardware wallet to the new wallet as a signer.


▶ Current implementation ◀

▶当前实施◀



  • Using createRandom() to instantiate a new wallet.


    const newWallet = ethers.Wallet.createRandom().connect(provider);


  • Then send some token from the hardware wallet to the new wallet

  • Deploy contract(= transaction costs would be paid by the transferred token)


▶ Question ◀

▶问题◀



  • Are there any ways to connect the hardware wallet to the new wallet instance? If that's possible, the transaction costs may be paid by the signer (= the connected hardware wallet).

  • If that's not, are there any ways to pay transaction costs from the hardware wallet?

  • Or, maybe it can be achieved if I can calculate total transaction costs BEFORE deployment, does anyone know to do so?


Since I'm still new to the blockchain space, it'd be appreciated if someone would give me some advice.

由于我还是区块链领域的新手,如果有人能给我一些建议,我将不胜感激。


更多回答

Sorry, I didn't test the case as I usually do for reactjs questions but I would seperate this process in 3 steps: 1 - Create a transaction payload for the contract deployment but don't send it. 2 - Forward this payload to the hardware wallet to be signed. 3- Once signed, broadcast the signed transaction to the network.

对不起,我没有测试案例,就像我通常对reactjs问题所做的那样,但我会将此过程分成3个步骤:1-为合同部署创建事务有效负载,但不发送它。2-将此有效负载转发到硬件钱包进行签名。3-签名后,将已签名的交易广播到网络。

@alimuratumutlu Thank you for your advice. It seems working well. I didn't know that there is such a way to deploy. Thank you again.

@alimuratumutlu感谢您的建议。它似乎工作得很好。我不知道有这样的部署方式。再次感谢您。

优秀答案推荐
更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com