首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >provider.sendTransaction与signer.sendTransaction的区别?

provider.sendTransaction与signer.sendTransaction的区别?
EN

Ethereum用户
提问于 2023-01-26 04:18:21
回答 2查看 267关注 0票数 1

我发现很难看出这两者之间的区别,它们各自的用例是什么?

EN

回答 2

Ethereum用户

发布于 2023-01-26 05:15:12

嗨,这里是Chainstack的开发者代言人。

基本上,provider.sendTransaction接受一个已签名tx的十六进制字符串作为它的参数。signer.sendTransaction接受一个事务对象作为参数。

除非您已经具有已解码的tx字符串,否则在使用signer.signTransaction发送事务之前,需要使用provider.sendTransaction

实际上,在ether.js的源代码中,后面就是这样做的。

代码语言:javascript
复制
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);
}

希望这有帮助,快乐的编码!

票数 3
EN

Ethereum用户

发布于 2023-01-27 10:47:19

签名者是来自ethersjs的一个概念(查看他们的文档)。基本上,它是一个提供者(另一个ethersjs的概念,也许更透明,它只是对到ETH网络的连接(通过RPC)的抽象)+一个私钥(实际上,它通常是Metamask)。通常,如果签名者是元问题,signer.sendTransaction会提示用户弹出一个元问题,要求他们签署并广播事务。

Provider.sendTransaction期望一个已经签名的事务作为输入,并简单地广播它。

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/143687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档