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

网站资料如何做参考文献百度怎么发广告

网站资料如何做参考文献,百度怎么发广告,南京做网站建设有哪些内容,精简版wordpress跟随HackQuest部署counter项目,使用 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: Context<Initialize>) -> 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: Context<Increment>) -> Result<()> {require_keys_eq!(ctx.accounts.authority.key(),ctx.accounts.counter.authority,ErrorCode::Unauthorized);ctx.accounts.counter.count += 1;Ok(())}
}#[derive(Accounts)]
pub struct Initialize<'info> {#[account(init,payer = authority,space = Counter::SIZE,seeds = [b"counter"],bump)]counter: Account<'info, Counter>,#[account(mut)]authority: Signer<'info>,system_program: Program<'info, System>,
}#[derive(Accounts)]
pub struct Increment<'info> {#[account(mut,seeds = [b"counter"],bump = counter.bump)]counter: Account<'info, Counter>,authority: Signer<'info>,
}#[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.hkea.cn/news/68936/

相关文章:

  • 澳门服务器做网站需要备案吗百度ai人工智能平台
  • 做化验的在哪个网站里投简历河南网站关键词优化
  • 百度网址大全网站大全网络整合营销方案ppt
  • 海阳市建设工程交易中心网站品牌推广的作用
  • 江西省住房和城乡建设网站成都网站优化seo
  • java资源网站云优化
  • 小程序源码大全网络seo关键词优化技巧
  • 服务佳的小企业网站建设ip子域名大全
  • 网页与制作唐山seo推广公司
  • 自己做的网站怎么弄到网上在线网页制作
  • 电商网站 设计方案百度的排名规则详解
  • 福建省建设厅网站余外链链接平台
  • 广告营销网站市场推广方案
  • 徐州企业做网站软文是什么文章
  • 网站代码备份如何优化seo
  • 百度网站公司信息推广怎么做天津做网站的网络公司
  • wordpress在线pdfseo百度站长工具查询
  • 太仓网站建设有限公司网站设计公司怎么样
  • 网站去哪做在线crm软件
  • 做360手机网站快速汕头seo排名收费
  • 网站建设总做总结宜兴百度推广公司
  • 做毕业网站的周记外贸建站优化
  • 南昌市住房和城乡建设局网站百度官网推广平台电话
  • 真人做视频网站百度怎么发布广告
  • 网站页面优化包括怎么给网站做优化
  • 哪个网站用帝国cms做的软文素材网
  • 网站建设需要的资料深圳精准网络营销推广
  • 客户网站建设公司网站排名提升软件
  • 网站建设与维护试卷论文怎么在百度上做广告
  • 做博客网站要什么技术百度网站网址是多少