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

有了源代码怎么做网站哈尔滨网站建设兼职

有了源代码怎么做网站,哈尔滨网站建设兼职,.net做网站后台,dw制作简单网站模板下载地址跟随HackQuest部署counter项目#xff0c;使用 Solana 官方提供的 playgroud 。这个平台让我们的部署和测试过程变得更加简便高效。 合约代码 lib.rs中复制以下代码 use anchor_lang::prelude::*; use std::ops::DerefMut;declare_id!(CVQCRMyzWNr8MbNhzjbfPu9YVvr97…跟随HackQuest部署counter项目使用 Solana 官方提供的 playgroud 。这个平台让我们的部署和测试过程变得更加简便高效。 合约代码 lib.rs中复制以下代码 use anchor_lang::prelude::*; use std::ops::DerefMut;declare_id!(CVQCRMyzWNr8MbNhzjbfPu9YVvr97onF48Lc9ZwXotpW);#[program] pub mod counter {use super::*;pub fn initialize(ctx: ContextInitialize) - Result() {let counter ctx.accounts.counter.deref_mut();let bump ctx.bumps.counter;*counter Counter {authority: *ctx.accounts.authority.key,count: 0,bump,};Ok(())}pub fn increment(ctx: ContextIncrement) - Result() {require_keys_eq!(ctx.accounts.authority.key(),ctx.accounts.counter.authority,ErrorCode::Unauthorized);ctx.accounts.counter.count 1;Ok(())} }#[derive(Accounts)] pub struct Initializeinfo {#[account(init,payer authority,space Counter::SIZE,seeds [bcounter],bump)]counter: Accountinfo, Counter,#[account(mut)]authority: Signerinfo,system_program: Programinfo, System, }#[derive(Accounts)] pub struct Incrementinfo {#[account(mut,seeds [bcounter],bump counter.bump)]counter: Accountinfo, Counter,authority: Signerinfo, }#[account] pub struct Counter {pub authority: Pubkey,pub count: u64,pub bump: u8, }impl Counter {pub const SIZE: usize 8 32 8 1; }#[error_code] pub enum ErrorCode {#[msg(You are not authorized to perform this action.)]Unauthorized, }交换代码 client.ts中复制以下代码 const wallet pg.wallet; const program pg.program; const counterSeed Buffer.from(counter);const counterPubkey await web3.PublicKey.findProgramAddressSync([counterSeed],pg.PROGRAM_ID );const initializeTx await pg.program.methods.initialize().accounts({counter: counterPubkey[0],authority: pg.wallet.publicKey,systemProgram: web3.SystemProgram.programId,}).rpc();let counterAccount await program.account.counter.fetch(counterPubkey[0]); console.log(account after initializing , Number(counterAccount.count));const incrementTx await pg.program.methods.increment().accounts({counter: counterPubkey[0],authority: pg.wallet.publicKey,}).rpc();counterAccount await program.account.counter.fetch(counterPubkey[0]); console.log(account after increasing , Number(counterAccount.count));部署和发布 切换到左侧工具栏第二个按钮并点击 build点击deploy, 终端出现 “Deployment successful.” 即为部署成功。这大约会消耗2~3个sol 测试交互 切换到左侧第一个文件按钮并点击 Run 运行client.ts文件输出如图 再次执行就会开始报错 Running client… client.ts: Uncaught error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0 各种求助之后修改初始化代码输出报错日志 try {// Initialize accountconst initializeTx await pg.program.methods.initialize().accounts({counter: counterPubkey,authority: pg.wallet.publicKey,systemProgram: web3.SystemProgram.programId,}).rpc();} catch (error) {console.error(Error fetching counter account:, error);}报错日志如下 logs: [ Program CVQCRMyzWNr8MbNhzjbfPu9YVvr97onF48Lc9ZwXotpW invoke [1],Program log: Instruction: Initialize,Program 11111111111111111111111111111111 invoke [2],Allocate: account Address { address: 8sKt2NcKbN9E2SUE6E3NgfzwGi5ByBZxHQdCw27bMef1, base: None } already in use,Program 11111111111111111111111111111111 failed: custom program error: 0x0,Program CVQCRMyzWNr8MbNhzjbfPu9YVvr97onF48Lc9ZwXotpW consumed 4867 of 200000 compute units,Program CVQCRMyzWNr8MbNhzjbfPu9YVvr97onF48Lc9ZwXotpW failed: custom program error: 0x0 ],programErrorStack: { stack: [ [Object], [Object] ] } }根据日志信息关键的错误是 Allocate: account Address { address: 8sKt2NcKbN9E2SUE6E3NgfzwGi5ByBZxHQdCw27bMef1, base: None } already in use这表示你尝试分配的账户地址 8sKt2NcKbN9E2SUE6E3NgfzwGi5ByBZxHQdCw27bMef1 已经被使用因此无法进行新的初始化。这通常发生在你已经为该地址创建了账户但可能在再次执行时未考虑到这一点。 修改initializeTx代码 let counterAccount; try {counterAccount await program.account.counter.fetch(counterPubkey);console.log(Counter account already exists:, counterAccount); } catch (error) {if (error.message.includes(Account does not exist)) {console.log(Counter account does not exist, proceeding with initialization...);// Initialize accountconst initializeTx await pg.program.methods.initialize().accounts({counter: counterPubkey,authority: pg.wallet.publicKey,systemProgram: web3.SystemProgram.programId,}).rpc();} else {console.error(Error fetching counter account:, error);} }执行结果 修复后完整client.ts代码 const wallet pg.wallet; const program pg.program; const counterSeed Buffer.from(counter);const [counterPubkey, bump] web3.PublicKey.findProgramAddressSync([counterSeed],pg.PROGRAM_ID );let counterAccount; try {counterAccount await program.account.counter.fetch(counterPubkey);console.log(Counter account already exists:, counterAccount); } catch (error) {if (error.message.includes(Account does not exist)) {console.log(Counter account does not exist, proceeding with initialization...);// Initialize accountconst initializeTx await pg.program.methods.initialize().accounts({counter: counterPubkey,authority: pg.wallet.publicKey,systemProgram: web3.SystemProgram.programId,}).rpc();} else {console.error(Error fetching counter account:, error);} }const incrementTx await pg.program.methods.increment().accounts({counter: counterPubkey,authority: pg.wallet.publicKey,}).rpc();counterAccount await program.account.counter.fetch(counterPubkey); console.log(account after increasing , Number(counterAccount.count));
http://www.w-s-a.com/news/758398/

相关文章:

  • 济南做网站哪家好财政网站平台建设不足
  • php网站建设招聘网站开发与设计论文
  • 上海 网站建设平台 补贴网站开发招标文件范本
  • 延安网站建设公司电话手机上那个网站做农产品推广比较好
  • 增城哪家网站建设好如何做网站实名认证
  • 常州地区做网站个人购物网站需要备案吗
  • 网站建设公司 跨界鱼科技专业做服务器的网站都有哪些
  • 欧洲网站服务器网站建设费用计入什么科目
  • 网站的色调苏州策划网站模板建站公司
  • 怎么看网站用的什么后台公路建设项目可行性研究报告编制办法哪个网站查最新版
  • 可以看的网站的浏览器有哪些专业APP客户端做网站
  • 如何做网站推广自己的产品推荐个网站好吗
  • 网站经营范围wordpress注入点
  • 学校网站开发协议夫妻网络网站建设
  • 福州网站seo推广优化微信商家小程序怎么弄
  • 免费网站推广工具在游戏网站做中介合法
  • 网站建设前的规划网站建设公司六安
  • 公司注册网站开发的行业表述南宁在百度上建网站
  • 创建企业网站国内网站用django做的
  • 云主机网站的空间在哪制作微网站的平台
  • 长沙做网站 青创互联wordpress4.4.1
  • 宜昌哪里有专业做网站的网站开发做什么的
  • 3小说网站开发东莞网站公司哪家好
  • 做网站安全联盟解ps网站设计概述
  • 聊城公司做网站wordpress连接域名
  • 宣传网站建设的意义台州行app官网下载
  • 温州 网站优化网站开发公司前置审批
  • 网站开发具体的工作内容网站下载app免费
  • seo网站建设时文章频率昆山网站建设ikelv
  • 中天建设中瑞物资网站优化建立生育支持政策体系