我发现很难看出这两者之间的区别,它们各自的用例是什么?
发布于 2023-01-26 05:15:12
嗨,这里是Chainstack的开发者代言人。
基本上,provider.sendTransaction接受一个已签名tx的十六进制字符串作为它的参数。signer.sendTransaction接受一个事务对象作为参数。
除非您已经具有已解码的tx字符串,否则在使用signer.signTransaction发送事务之前,需要使用provider.sendTransaction。
实际上,在ether.js的源代码中,后面就是这样做的。
async sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse>
{
this._checkProvider("sendTransaction");
const tx = await this.populateTransaction(transaction);
const signedTx = await this.signTransaction(tx);
return await this.provider.sendTransaction(signedTx);
}希望这有帮助,快乐的编码!
发布于 2023-01-27 10:47:19
签名者是来自ethersjs的一个概念(查看他们的文档)。基本上,它是一个提供者(另一个ethersjs的概念,也许更透明,它只是对到ETH网络的连接(通过RPC)的抽象)+一个私钥(实际上,它通常是Metamask)。通常,如果签名者是元问题,signer.sendTransaction会提示用户弹出一个元问题,要求他们签署并广播事务。
Provider.sendTransaction期望一个已经签名的事务作为输入,并简单地广播它。
https://ethereum.stackexchange.com/questions/143687
复制相似问题