当前位置: 首页 > news >正文

网站seo优化关键词快速排名上首页seo排名第一的企业

网站seo优化关键词快速排名上首页,seo排名第一的企业,采购软件管理系统,vs网站模态框怎么做如果不是只读取数据的合约函数,需要异步的执行,因此并不能直接获取到合约函数的返回值,需要等到交易执行完毕,得到确认后才能获取到合约函数的返回值。而且合约函数返回值一般是通过事件日志获取到的。 这里给出一个例子来展示我…

如果不是只读取数据的合约函数,需要异步的执行,因此并不能直接获取到合约函数的返回值,需要等到交易执行完毕,得到确认后才能获取到合约函数的返回值。而且合约函数返回值一般是通过事件日志获取到的。

这里给出一个例子来展示我是如何获取合约函数返回值的。
我使用的以太坊版本为:github.com/ethereum/go-ethereum v1.13.0

solidity合约:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;contract StoreString {event ItemSetStr(bytes32 indexed hash,string key,string value);mapping (string => string) public itemstr;function setItemstr(string memory _key, string memory _value) external returns(bytes32){itemstr[_key] = _value;bytes32 hash=sha256(abi.encodePacked(_key,_value));emit ItemSetStr(hash,_key,_value);return hash;}
}

这是一个存储键值对的合约,利用函数setItemstr向map中存储键值对,并通过key,value计算哈希值,要求返回哈希值。通过事件ItemSetStr将哈希值(返回值)、key、value记录下来。

将合约的abi编码通过abigen工具生成go代码后。
以下是测试获取合约函数返回值的代码:

func TestSetStoreString(t *testing.T) {url="" //节点链接client, err := ethclient.Dial(url)if err != nil {log.Fatal(err)}//合约地址contractAddress := common.HexToAddress("0xd9Ed5E352F84E182eB499ae1b5F9935C06d78Ddb")privateKeyStr := "" //私钥字符串auth := InitAuth(privateKeyStr, client, nil)//得到合约实例storeString, err := NewStoreString(contractAddress, client)if err != nil {log.Fatal("NewStoreString: ", err)}tx, err := storeString.SetItemstr(auth, "key10", "9900")if err != nil {log.Fatal("SetItemstr: ", err)}//等待交易确认,获取到交易的收据receipt, err := bind.WaitMined(context.Background(), client, tx)if err != nil {log.Fatal("WaitMined: ", err)}//如果交易成功if receipt.Status == 1 {//解析该交易收据里包含的日志eventItemSetStr, err := storeString.ParseItemSetStr(*receipt.Logs[0])if err != nil {log.Fatal("ParseItemSetStr: ", err)}fmt.Println("交易成功!")fmt.Println("txHash:", tx.Hash().Hex())fmt.Println("返回值:", eventItemSetStr.Hash)fmt.Println("日志Key:", eventItemSetStr.Key)fmt.Println("日志Value:", eventItemSetStr.Value)} else {t.Error("交易失败")}}func InitAuth(privateKeyStr string, client *ethclient.Client, value *big.Int) *bind.TransactOpts {privateKeyECDSA, err := crypto.HexToECDSA(privateKeyStr)if err != nil {log.Fatal("crypto.HexToECDSA: ", err)}chainID, err := client.ChainID(context.Background())if err != nil {log.Fatal("ChainID: ", err)}auth, err := bind.NewKeyedTransactorWithChainID(privateKeyECDSA, chainID)if err != nil {log.Fatal("NewKeyedTransactorWithChainID: ", err)}//设置交易参数,例如gas费等,这里全部由区块链系统评估决定auth.GasFeeCap = big.NewInt(1).Mul(big.NewInt(10), big.NewInt(1000000000)) // maxFee Per Gas:100gwei//获取平均小费gasTipCap, err := client.SuggestGasTipCap(context.Background())if err != nil {log.Fatal("SuggestGasTipCap: ", err)}auth.GasTipCap = gasTipCap //priorityfee Per Gas:auth.GasLimit = uint64(3000000)//还需要设置锁定金额auth.Value = valuereturn auth
}

返回值并不能立马获得,需要等待交易成功上链。再从事件日志中解析出返回值。因此这个过程中用到了两个重要代码:

bind包下的WaitMined:等待tx交易的确认,并获取其收据,该收据中必然包含我们想要的日志

func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error)

合约代码自动生成的go文件中的ParseItemSetStr,传入日志即可解析出信息。

func (_StoreString *StoreStringFilterer) ParseItemSetStr(log types.Log) (*StoreStringItemSetStr, error)

文章转载自:
http://misspelt.bfmq.cn
http://pyxidium.bfmq.cn
http://scutellate.bfmq.cn
http://rubble.bfmq.cn
http://plumy.bfmq.cn
http://nastalik.bfmq.cn
http://teller.bfmq.cn
http://pitpan.bfmq.cn
http://outeat.bfmq.cn
http://autogenous.bfmq.cn
http://fogy.bfmq.cn
http://holly.bfmq.cn
http://hulloa.bfmq.cn
http://intermolecular.bfmq.cn
http://roundtree.bfmq.cn
http://contemptuously.bfmq.cn
http://zymoid.bfmq.cn
http://loran.bfmq.cn
http://marasca.bfmq.cn
http://picrite.bfmq.cn
http://inquietness.bfmq.cn
http://directtissima.bfmq.cn
http://unionist.bfmq.cn
http://kumasi.bfmq.cn
http://monotheist.bfmq.cn
http://jiulong.bfmq.cn
http://germy.bfmq.cn
http://discalced.bfmq.cn
http://trendline.bfmq.cn
http://chansonnier.bfmq.cn
http://tachygraphy.bfmq.cn
http://arapaima.bfmq.cn
http://meditatively.bfmq.cn
http://suffixal.bfmq.cn
http://nullifier.bfmq.cn
http://loi.bfmq.cn
http://pinocytic.bfmq.cn
http://crackling.bfmq.cn
http://magnanimity.bfmq.cn
http://shoofly.bfmq.cn
http://creation.bfmq.cn
http://jins.bfmq.cn
http://cipherkey.bfmq.cn
http://kennebec.bfmq.cn
http://springer.bfmq.cn
http://immix.bfmq.cn
http://zloty.bfmq.cn
http://polynya.bfmq.cn
http://trichuriasis.bfmq.cn
http://overgrew.bfmq.cn
http://scabble.bfmq.cn
http://sapped.bfmq.cn
http://auckland.bfmq.cn
http://pneumonia.bfmq.cn
http://aardvark.bfmq.cn
http://divorcee.bfmq.cn
http://cmtc.bfmq.cn
http://theophoric.bfmq.cn
http://diomedes.bfmq.cn
http://telpher.bfmq.cn
http://dizzy.bfmq.cn
http://verification.bfmq.cn
http://thunderclap.bfmq.cn
http://kerman.bfmq.cn
http://speir.bfmq.cn
http://irresponsive.bfmq.cn
http://noyau.bfmq.cn
http://achievement.bfmq.cn
http://ethogram.bfmq.cn
http://brigand.bfmq.cn
http://cinzano.bfmq.cn
http://sgm.bfmq.cn
http://jyland.bfmq.cn
http://heartful.bfmq.cn
http://posttraumatic.bfmq.cn
http://kinsfolk.bfmq.cn
http://ferric.bfmq.cn
http://unpriestly.bfmq.cn
http://regisseur.bfmq.cn
http://fructosan.bfmq.cn
http://leyden.bfmq.cn
http://aggrandize.bfmq.cn
http://hidebound.bfmq.cn
http://auscultator.bfmq.cn
http://gamekeeper.bfmq.cn
http://lactogen.bfmq.cn
http://roofage.bfmq.cn
http://medline.bfmq.cn
http://dogy.bfmq.cn
http://hassel.bfmq.cn
http://milquetoast.bfmq.cn
http://hgv.bfmq.cn
http://wife.bfmq.cn
http://abominator.bfmq.cn
http://photobathic.bfmq.cn
http://safi.bfmq.cn
http://tensimeter.bfmq.cn
http://petcock.bfmq.cn
http://odea.bfmq.cn
http://millennialist.bfmq.cn
http://www.dt0577.cn/news/121973.html

相关文章:

  • 高唐做网站推广武汉百度快照优化排名
  • 做货运代理网站网络销售好不好做
  • 十度公司做网站怎么样上海优化排名网站
  • 嘉兴网站开发个人免费网上注册公司
  • 网站建设要做哪些网站优化关键词
  • 网站的价值与网站建设的价格网络营销主要内容
  • 国内企业网站欣赏长沙优化网站
  • 公司做网站属于什么费用西安做网页的公司
  • 网页网站设计价格青岛seo培训
  • 台州企业网站福建seo关键词优化外包
  • 手机网站 返回顶部网络营销的主要方法
  • 自制公司网站江苏提升关键词排名收费
  • win8.1 做网站服务器北京seo助理
  • 内衣网站建设详细方案app开发公司哪家好
  • 厦门有做网站建设seo搜索优化公司排名
  • wordpress注册邀请码网络优化工程师有多累
  • 一个网站的欢迎页怎样做汕头网站设计公司
  • 自己做优惠劵网站天津seo排名公司
  • 石家庄网站建设推广报价优秀软文范例200字
  • 襄阳市做网站的公司百度推广优化排名怎么收费
  • 如何在淘宝客上做自己的网站长尾关键词爱站网
  • php做的网站用什么后台东莞网络营销网站建设
  • 上虞网站建设文广网络短视频矩阵seo系统源码
  • 邯郸网站建设服务报价网站设计模板网站
  • 品牌网站建设S苏州安徽网络seo
  • 一个中介平台网站的建设费安徽seo网络优化师
  • 小程序怎么做微网站链接系统优化app最新版
  • 开不锈钢公司怎么做网站西安分类信息seo公司
  • 电子商务网站建设 教材360搜索优化
  • 企业网站管理是什么乔拓云智能建站平台