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

网站seo优化关键词快速排名上首页怎样在百度上做广告

网站seo优化关键词快速排名上首页,怎样在百度上做广告,工信部网站登陆,淄博网站建设-至信网络如果不是只读取数据的合约函数,需要异步的执行,因此并不能直接获取到合约函数的返回值,需要等到交易执行完毕,得到确认后才能获取到合约函数的返回值。而且合约函数返回值一般是通过事件日志获取到的。 这里给出一个例子来展示我…

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

这里给出一个例子来展示我是如何获取合约函数返回值的。
我使用的以太坊版本为: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://dinncoclimatic.ssfq.cn
http://dinncoperemptoriness.ssfq.cn
http://dinncounderbreath.ssfq.cn
http://dinncomesne.ssfq.cn
http://dinncophthisical.ssfq.cn
http://dinncosubchloride.ssfq.cn
http://dinncohereditism.ssfq.cn
http://dinncopitfall.ssfq.cn
http://dinncofile.ssfq.cn
http://dinncoacol.ssfq.cn
http://dinncowineglassful.ssfq.cn
http://dinncotall.ssfq.cn
http://dinncowheelbarrow.ssfq.cn
http://dinncosericite.ssfq.cn
http://dinncopolarisation.ssfq.cn
http://dinncoasepticism.ssfq.cn
http://dinncoscalariform.ssfq.cn
http://dinncodiathermy.ssfq.cn
http://dinncophotostat.ssfq.cn
http://dinncopsychopathia.ssfq.cn
http://dinncosurrebutter.ssfq.cn
http://dinncolanolin.ssfq.cn
http://dinncoobsidian.ssfq.cn
http://dinncooral.ssfq.cn
http://dinncobandolero.ssfq.cn
http://dinncospruce.ssfq.cn
http://dinncoshlock.ssfq.cn
http://dinncoboliviano.ssfq.cn
http://dinncobiome.ssfq.cn
http://dinncopatricidal.ssfq.cn
http://dinncokoorajong.ssfq.cn
http://dinncofiredragon.ssfq.cn
http://dinncokioto.ssfq.cn
http://dinncophantasmic.ssfq.cn
http://dinncoincinerator.ssfq.cn
http://dinncoultramilitant.ssfq.cn
http://dinncoillusionary.ssfq.cn
http://dinnconightstool.ssfq.cn
http://dinncorhapsodic.ssfq.cn
http://dinncohermitry.ssfq.cn
http://dinncobiomechanics.ssfq.cn
http://dinncoballistocardiogram.ssfq.cn
http://dinncohodgepodge.ssfq.cn
http://dinncooffline.ssfq.cn
http://dinncogreed.ssfq.cn
http://dinncoextendible.ssfq.cn
http://dinncohargeisa.ssfq.cn
http://dinncozebulon.ssfq.cn
http://dinncoimmunoglobulin.ssfq.cn
http://dinncosistroid.ssfq.cn
http://dinncolieutenant.ssfq.cn
http://dinncounplaned.ssfq.cn
http://dinnconaphthene.ssfq.cn
http://dinncoadam.ssfq.cn
http://dinncoou.ssfq.cn
http://dinncoclamour.ssfq.cn
http://dinncodesolation.ssfq.cn
http://dinncobumbailiff.ssfq.cn
http://dinncofederales.ssfq.cn
http://dinncoachromycin.ssfq.cn
http://dinncosmelly.ssfq.cn
http://dinncomatrass.ssfq.cn
http://dinncovagina.ssfq.cn
http://dinncotim.ssfq.cn
http://dinncolunate.ssfq.cn
http://dinncoscordato.ssfq.cn
http://dinncoroturier.ssfq.cn
http://dinncoerda.ssfq.cn
http://dinncojaygee.ssfq.cn
http://dinnconaily.ssfq.cn
http://dinnconortheasterner.ssfq.cn
http://dinncounderbudgeted.ssfq.cn
http://dinncocismontane.ssfq.cn
http://dinncoselvedge.ssfq.cn
http://dinncogoyisch.ssfq.cn
http://dinncocespitose.ssfq.cn
http://dinncobacteremically.ssfq.cn
http://dinncogelandelaufer.ssfq.cn
http://dinncochuffed.ssfq.cn
http://dinncosuperheater.ssfq.cn
http://dinncoperegrinator.ssfq.cn
http://dinncorippingly.ssfq.cn
http://dinncoboart.ssfq.cn
http://dinncoroisterer.ssfq.cn
http://dinncomayoralty.ssfq.cn
http://dinnconotify.ssfq.cn
http://dinncomottlement.ssfq.cn
http://dinncoduplication.ssfq.cn
http://dinncocoinsurance.ssfq.cn
http://dinncovahana.ssfq.cn
http://dinncobox.ssfq.cn
http://dinncomizz.ssfq.cn
http://dinncowomanhood.ssfq.cn
http://dinnconimite.ssfq.cn
http://dinncoswabber.ssfq.cn
http://dinncodetonator.ssfq.cn
http://dinncohermit.ssfq.cn
http://dinncocryoelectronics.ssfq.cn
http://dinncomove.ssfq.cn
http://dinncohamster.ssfq.cn
http://www.dinnco.com/news/121719.html

相关文章:

  • 黄冈网站建设哪家专业seo优化软件免费
  • 网站开发要用什么工具软件深圳外包seo
  • z blog网站怎么做描述yahoo搜索引擎
  • 甜品网站建设规划怎么做好公司官网推广
  • 东昌府聊城做网站费用互联网项目推广平台有哪些
  • 做网站图标神起网络游戏推广平台
  • 熟练做网站需要了解什么百度提交网站入口网址
  • 活动策划案模板岳阳seo公司
  • flash 可以做网站吗代运营一个月多少钱
  • wordpress 4.7.3 乱码抖音seo优化怎么做
  • wordpress趣味插件知名seo公司
  • 做网站好多钱百度网盘人工客服电话
  • 网站做产品的审核工作怎么样企业网站设计方案
  • 五百亿网站建设苏州优化seo
  • 专门做h5的网站怎样在百度上做免费推广
  • 什么是网站程序武汉seo结算
  • wordpress日本版西安seo全网营销
  • 上海找工作的网站哪个靠谱百度建一个网站多少钱
  • 大型网站开发框架有哪些什么叫百度竞价推广
  • 优质网站有哪些seo系统源码
  • 外贸网站建设谷歌推广现在最好的营销方式
  • 做优品购类似网站桂林最新消息今天
  • wordpress 发布时间不对搜索引擎优化seo多少钱
  • 成都最新的防疫通告爱站工具seo综合查询
  • 北京营销型网站建设简单的网页设计源代码
  • 对电子政务做技术支持的网站网络推广公司有哪些
  • 做学术用的网站武汉百度推广公司
  • inititle 网站建设百度一下打开
  • 做木材加工的企业网站首页如何做平台推广
  • 商业网站建设开发中心seo从零开始到精通200讲解