简体   繁体   English

未捕获(承诺中)错误:发送交易需要签名者

[英]Uncaught (in promise) Error: sending a transaction requires a signer

Hey I am getting this error嘿我收到这个错误

                                      `Uncaught (in promise) Error: sending a transaction requires a signer (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=contracts/5.2.0)
at Logger.makeError (ethers-5.2.umd.min.js:1:59669)
at Logger.throwError (ethers-5.2.umd.min.js:1:59874)
at Contract.<anonymous> (ethers-5.2.umd.min.js:1:312289)
at step (ethers-5.2.umd.min.js:1:305047)
at Object.next (ethers-5.2.umd.min.js:1:304307)
at ethers-5.2.umd.min.js:1:303953
at new Promise (<anonymous>)
at __awaiter (ethers-5.2.umd.min.js:1:303591)
at Contract.<anonymous> (ethers-5.2.umd.min.js:1:312138)
at vote (index.html:338:34)`

On this code在这段代码上

function vote(){ provider = new ethers.providers.Web3Provider(window.ethereum); signer = provider.getSigner(0); const contract = new ethers.Contract("0xF1bFB2277C269DC90D8726DDf60A680aeffA2AbF", abi, provider); console.log("workin"); var propval = document.getElementById("select").value; var castvote = contract.vote(propval); castvote.then(function(){ document.getElementById("mp").innerHTML = transaction; }) }

Anyone pls help me in fixing this任何人请帮我解决这个问题

In ethers.js, providers allow you to query data from the blockchain.在 ethers.js 中,提供者允许您从区块链中查询数据。 They represent the way you connect to the blockchain.它们代表了您连接到区块链的方式。 With them you can only call view methods on contracts and get data from those contract.使用它们,您只能调用合约的视图方法并从这些合约中获取数据。

Signers are providers but with access to an ethereum account.签名者是提供者,但可以访问以太坊帐户。 Therefore, they can sign transaction that modify the state of the blockchain (Transaction where you store or change information on the blockchain).因此,他们可以签署修改区块链 state 的交易(您在区块链上存储或更改信息的交易)。

When you instantiate your contract you pass a provider and not a signer.当你实例化你的合约时,你传递的是提供者而不是签名者。 So, on this contract, you should only be able to call view methods.所以,在这个合约上,你应该只能调用视图方法。 Because the vote method modify the state on the blockchain, you get the error that you get.因为投票方法修改了区块链上的 state,所以你得到了你得到的错误。

To resolve this the only change you need to do is to pass the signer instead of your provider in your contract instanciation:要解决此问题,您需要做的唯一更改是在合同实例中传递签名者而不是提供者:

const contract = new ethers.Contract("0xF1bFB2277C269DC90D8726DDf60A680aeffA2AbF", abi, signer);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试在 web3 中调用 send function 并返回错误 =&gt; Uncaught (in promise) 错误:返回错误:未知帐户 - Trying to call send function in web3 and it returns an error => Uncaught (in promise) Error: Returned error: unknown account 创建发送交易的地址 - Creating address for sending transaction 未捕获(承诺)错误:既没有在给定选项中也没有在默认选项中指定“发件人”地址 - Uncaught (in promise) Error: No "from" address specified in neither the given options, nor the default options 发送大量事务期间内存池溢出 - Overflowing mempool during sending a lot of transaction 在 Xcode 中发送交易时出现“configurationError” - Got an "configurationError" when sending a transaction in Xcode 提交交易时出错 - Error when submitting transaction 发送私人事务期间仲裁节点崩溃 - Quorum node crashes during sending a private transaction 发送交易时如何准确地将ETH转换为WEI? - How do I accurately convert ETH to WEI when sending transaction? 在 solana 中调用 transaction.from() 后,有没有办法获取金额(我们在交易中发送的令牌数) - Is there any way to get amount(number of token we are sending in transaction) after calling transaction.from() in solana “错误:找不到任何要执行的交易功能” - “Error: Could not find any functions to execute for transaction”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM