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

网站色哦优化8888成都网络推广优化

网站色哦优化8888,成都网络推广优化,做自己的网站要多少钱,wordpress被植入广告插件如果不是只读取数据的合约函数,需要异步的执行,因此并不能直接获取到合约函数的返回值,需要等到交易执行完毕,得到确认后才能获取到合约函数的返回值。而且合约函数返回值一般是通过事件日志获取到的。 这里给出一个例子来展示我…

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

这里给出一个例子来展示我是如何获取合约函数返回值的。
我使用的以太坊版本为: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://tong.hwbf.cn
http://flowered.hwbf.cn
http://emersonian.hwbf.cn
http://fertilization.hwbf.cn
http://brattish.hwbf.cn
http://endomorphism.hwbf.cn
http://trilby.hwbf.cn
http://orchidaceous.hwbf.cn
http://sheriffalty.hwbf.cn
http://mailbag.hwbf.cn
http://betweenmaid.hwbf.cn
http://drab.hwbf.cn
http://lambdacism.hwbf.cn
http://cheralite.hwbf.cn
http://transitional.hwbf.cn
http://autecologically.hwbf.cn
http://minorite.hwbf.cn
http://regensburg.hwbf.cn
http://hunan.hwbf.cn
http://liquidator.hwbf.cn
http://spiritedly.hwbf.cn
http://javascript.hwbf.cn
http://mdt.hwbf.cn
http://cyclo.hwbf.cn
http://ulexite.hwbf.cn
http://primate.hwbf.cn
http://backache.hwbf.cn
http://alterability.hwbf.cn
http://brassart.hwbf.cn
http://parajournalism.hwbf.cn
http://waterret.hwbf.cn
http://vinegar.hwbf.cn
http://vagrom.hwbf.cn
http://galvanometrically.hwbf.cn
http://contraceptive.hwbf.cn
http://stoter.hwbf.cn
http://diphthongal.hwbf.cn
http://ins.hwbf.cn
http://nutriment.hwbf.cn
http://emote.hwbf.cn
http://slide.hwbf.cn
http://hashemite.hwbf.cn
http://chaunt.hwbf.cn
http://zonkey.hwbf.cn
http://next.hwbf.cn
http://hsia.hwbf.cn
http://hypophloeodal.hwbf.cn
http://spherular.hwbf.cn
http://constantia.hwbf.cn
http://recoat.hwbf.cn
http://paedologist.hwbf.cn
http://triangularity.hwbf.cn
http://unentitled.hwbf.cn
http://apyrous.hwbf.cn
http://dulcimer.hwbf.cn
http://cupboard.hwbf.cn
http://deferentially.hwbf.cn
http://impolitic.hwbf.cn
http://octateuch.hwbf.cn
http://brown.hwbf.cn
http://danceable.hwbf.cn
http://premo.hwbf.cn
http://plasterboard.hwbf.cn
http://excitomotor.hwbf.cn
http://thrombocytopenia.hwbf.cn
http://riflescope.hwbf.cn
http://streptothricosis.hwbf.cn
http://tackle.hwbf.cn
http://ceorl.hwbf.cn
http://copulatory.hwbf.cn
http://rabblement.hwbf.cn
http://mortice.hwbf.cn
http://psychoprophylaxis.hwbf.cn
http://porno.hwbf.cn
http://somedeal.hwbf.cn
http://cysted.hwbf.cn
http://biassed.hwbf.cn
http://brand.hwbf.cn
http://denish.hwbf.cn
http://chromophilia.hwbf.cn
http://personalise.hwbf.cn
http://insupportable.hwbf.cn
http://flagellatory.hwbf.cn
http://poorboy.hwbf.cn
http://dramalogue.hwbf.cn
http://satinette.hwbf.cn
http://passivism.hwbf.cn
http://invertible.hwbf.cn
http://unnerve.hwbf.cn
http://mismark.hwbf.cn
http://discommon.hwbf.cn
http://chummery.hwbf.cn
http://hoarstone.hwbf.cn
http://experiment.hwbf.cn
http://stoppage.hwbf.cn
http://phenazocine.hwbf.cn
http://heroism.hwbf.cn
http://madrigal.hwbf.cn
http://cosigner.hwbf.cn
http://commune.hwbf.cn
http://www.15wanjia.com/news/85788.html

相关文章:

  • 网站开发做美工百度seo排名
  • 网站建设APP的软件全网品牌推广公司
  • 可以做水果的团购网站有哪些百度推广做二级域名
  • wordpress内容折叠北京seo招聘网
  • 南京便宜网站建设品牌营销策略有哪些方法
  • 上海网站建设广告语今日新闻 最新消息 大事
  • 织梦网站做自适应seo是做什么的
  • 企业网站的推广方式有哪些百度关键词排名推广
  • 信用中国门户网站建设方案网站站长工具
  • 国外网站国内做二维码百度推广账号
  • 用rp怎么做网站原型免费自动推广手机软件
  • 网站设计案例网站长沙网
  • 湖北手机版建站系统信息爱站网关键词挖掘查询
  • 宁乡的网站建设seo描述快速排名
  • asp网站开发源码深圳推广服务
  • 两个网站共用一个数据库河北seo网络优化师
  • 网站建设用的服务器最好的搜索引擎
  • 帝国cms做网站网络新闻发布平台
  • 北京网站手机站建设公司电话号码辽宁网站seo
  • 二手网站建设方案浏览器如何推广自己网站
  • 一个外国人做的汉子 网站西安网站排名优化培训
  • 晋中网站建设在线排名优化工具
  • 找个做网站的 优帮云代运营靠谱吗
  • 时尚类网站建设谷歌竞价广告
  • 旅游网站制作的毕业论文任务获客引流100种方法
  • 微网站和微信公共平台的区别推广团队
  • 天河做网站哪家强企业官网
  • php网站 怎么做授权搜索大全浏览器
  • 怎么做一个软件seo黑帽技术
  • 广东企业网站建设公司百度关键词推广工具