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

互联网营销型网站网站用什么做内网穿透比较好

互联网营销型网站,网站用什么做内网穿透比较好,网站管理员怎么登陆,松江建设网站简介#xff1a;通过 IDL 生成代码 调用 anchor 智能合约。 全网首发 使用 anchor 可以快速开发 solana 上面的智能合约 #xff0c; 在本案例中我们 先使用 anchor 创建一个只能合约#xff08; 多个函数方法#xff09;。 部署到 dev 链上。 通过 anchor 的 IDL 生成 代码… 简介通过 IDL 生成代码 调用 anchor 智能合约。 全网首发         使用 anchor 可以快速开发 solana 上面的智能合约 在本案例中我们 先使用 anchor 创建一个只能合约 多个函数方法。 部署到 dev 链上。 通过 anchor 的 IDL 生成 代码 我这边是go 框架代码这里别的语言也是可以的 然后编写代码 调用 通过 IDL 生成的代码 来 调用 anchor 智能合约的函数 1.编写 anchor 只能合约 部署上链 1.1 anchor 智能合约的编写  ◒案例中使用 rust 编写 anchor 只能合约一共四个方法用户操作 pad 账户中的一个数值 initialize  初始化函数  只能调用一次 reset 重置为一个指定的值可多次调用 increment 累加 可多次调用 subtract 累减 可多次调用 use anchor_lang::prelude::*;// This is your programs public key and it will update // automatically when you build the project. declare_id!(HKvWCsAhzhXRfj8zNhNrofjV3dDjSmm42EguMKK3X5n);#[program] pub mod anchor_counter {use super::*;//初始化pub fn initialize(ctx: ContextInitialize, init_data: u64) - Result() {msg!(initialize from: {:?}, ctx.program_id);//直接给pad 账户复制ctx.accounts.counter.count init_data;Ok(())}//重置 数据到指定 值pub fn reset(ctx: ContextUpdateCount, init_data: u64) - Result() {let counter mut ctx.accounts.counter;msg!(increment from: {:?}, ctx.program_id);msg!(previous counter: {:?}, counter.count);counter.count init_data;//counter.count - 2;msg!(after counter: {:?}, counter.count);Ok(())}//累加pub fn increment(ctx: ContextUpdateCount) - Result() {let counter mut ctx.accounts.counter;msg!(increment from: {:?}, ctx.program_id);msg!(previous counter: {:?}, counter.count);counter.count counter.count.checked_add(1).unwrap();//counter.count - 2;msg!(after counter: {:?}, counter.count);Ok(())}//累减pub fn subtract(ctx: ContextUpdateCount, count: u64) - Result() {let counter mut ctx.accounts.counter;msg!(increment from: {:?}, ctx.program_id);msg!(previous counter: {:?}, counter.count);//counter.count counter.count.checked_add(1).unwrap();counter.count - count;msg!(after counter: {:?}, counter.count);Ok(())} }#[derive(Accounts)] pub struct Initializeinfo {#[account(mut)]// user 调用者 签名者, 是否 mut有权限修改信息pub user: Signerinfo,// counter 数据账户 pda 派生#[account(init,seeds [bcounter_seed],bump,payer user,space 8 8)]pub counter: Accountinfo, Counter,// 程序账户pub system_program: Programinfo, System, }#[derive(Accounts)] pub struct UpdateCountinfo {// user 调用者 签名者pub user: Signerinfo,#[account(mut)]pub counter: Accountinfo, Counter, }#[account] pub struct Counter {count: u64, }1.2 部署智能合约。  导出 IDL 文件  2.通过 anchor 智能合约 IDL 文件生成代码 导出 anchor 智能合约的 IDL 文件我们可以 得到一个  idl.json 文件。因为我空间选取的是 go,所以我这边需要使用  anchor-go 库 来把  idl.json 配置文件 生成一个 go 脚本。  github.com/gagliardetto/anchor-go go run github.com/gagliardetto/anchor-go --srcidl.json  运行上面命令。就会在当前项目中生成一个  generated 文件夹  以ancho 智能合约 项目名为 文件夹的目录。 3.使用 IDL 生成的代码代用智能合约 这里直接值 使用生成的代码 构造合约然后调用调用完我们通过 区块链浏览器查看 发现数据已经变化了。 说明调用时成功的   package mainimport (anchor-go/generated/anchor_counterfmtgithub.com/gagliardetto/solana-gogithub.com/gagliardetto/solana-go/rpcconfirm github.com/gagliardetto/solana-go/rpc/sendAndConfirmTransactiongithub.com/gagliardetto/solana-go/rpc/wsgolang.org/x/net/context )//TIP pTo run your code, right-click the code and select bRun/b./p pAlternatively, click // the icon srcAllIcons.Actions.Execute/ icon in the gutter and select the bRun/b menu item from here./pfunc main() {// 创建 RPC 客户端rpcClient : rpc.New(rpc.DevNet_RPC)wsClient, err : ws.Connect(context.Background(), rpc.DevNet_WS)if err ! nil {panic(err)}response, err : rpcClient.GetVersion(context.TODO())if err ! nil {panic(err)}fmt.Println(version, response.SolanaCore)// 交易签名账户 密钥对fromPrivateKey, err : solana.PrivateKeyFromBase58(你 anchor 所属 钱包 私钥) // 私钥if err ! nil {panic(err)}fromPublicKey : fromPrivateKey.PublicKey()// 获取最新的区块哈希recent, err : rpcClient.GetLatestBlockhash(context.TODO(), rpc.CommitmentFinalized)if err ! nil {panic(err)}//anchor 只能合约 地址anchorID : solana.MustPublicKeyFromBase58(HKvWCsAhzhXRfj8zNhNrofjV3dDjSmm42EguMKK3X5n)anchor_counter.SetProgramID(anchorID)// 通过随机因子 获取 PDA 账号padPublicKey, _, _ : solana.FindProgramAddress([][]byte{[]byte(counter_seed)}, anchorID)//调用 anchor 智能合约的 累加方法transferInstruction : anchor_counter.NewIncrementInstruction(fromPublicKey, padPublicKey)//调用 anchor 智能合约的 重置方法//transferInstruction : anchor_counter.NewResetInstruction(2025, fromPublicKey, padPublicKey)// 创建交易tx, err : solana.NewTransaction([]solana.Instruction{transferInstruction.Build()},recent.Value.Blockhash,solana.TransactionPayer(fromPublicKey),)if err ! nil {panic(err)}fmt.Println(tx)// 签名交易_, err tx.Sign(func(key solana.PublicKey) *solana.PrivateKey {if fromPrivateKey.PublicKey().Equals(key) {return fromPrivateKey}return nil},)if err ! nil {panic(fmt.Errorf(unable to sign transaction: %w, err))}//发送并等待交易确认sig, err : confirm.SendAndConfirmTransaction(context.TODO(),rpcClient,wsClient,tx,)if err ! nil {panic(err)}fmt.Println(Transaction confirmed:, sig) }beta.solpg.io 编辑器  区块链浏览器
http://www.pierceye.com/news/955335/

相关文章:

  • 广州住房和城乡建设部网站首页福建建站公司
  • 福州网站制作有限公司可玩儿小程序代理
  • 佛山市企业网站建设平台注册公司多少钱起步
  • 网站开发好的语言网站维护上海
  • 民宿网站建设网站如何添加统计代码
  • 哪里培训做网站wordpress plugin development
  • 网站开发费用摊销时间html5视频教程
  • 连连跨境电商网站开发山西省住房建设厅网站首页
  • 潍坊seo网站推广北京南站地铁线路图
  • 投资网站排行军事最新新闻播报
  • 梅州建设网站丰台网页设计公司
  • 短期网站建设培训学校网页建站价格
  • 偏门网站建设做的网站被挂马
  • 三五互联网站自己做一个网站需要什么
  • wordpress博客网站深圳建工集团
  • 罗永浩做的网站房产网站设计方案
  • 创建个人网站多少钱模板速成网站
  • 晋江做网站的公司哪家好企业网站报价
  • 百度权重查询网站旅游公司的网站怎么做
  • 品牌网站建设小蝌蚪2a西安中交建设集团网站
  • 潍坊网页网站制作优畅 wordpress
  • 搜狗收录网站网站制作费用预算表
  • dede网站安全长沙营销型
  • 那些做电影视频网站的赚钱吗邯郸网站建设方案
  • 在线做app的网站wordpress 产品分类
  • seo网站建设规划网站模板视频教程
  • 沈阳网站制作策划wordpress 文章页调用
  • 网站开发和网络工程师方法网站目录
  • 用dw做网站的好处网页美工培训中心
  • 中文域名注册 .网站网站英文地图怎么做