标签: blockchain

断言和要求之间的区别

您好,我最近刚刚开始从 Udemy 学习 Solidity,尽管在几乎完成课程后我还没有理解 assert 和 require 之间的区别。当不满足要求时,它们不是都会破坏功能吗?在合约内的 Gas 优化方面,两者相比是否有优势?

blockchain ethereum solidity smartcontracts

4
推荐指数
2
解决办法
2630
查看次数

错误[E0412]:在此范围内找不到类型“ProgramResult”

use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod myepicproject {
  use super::*;
  pub fn start_stuff_off(ctx: Context<StartStuffOff>) -> ProgramResult {
    Ok(())
  }
}

#[derive(Accounts)]
pub struct StartStuffOff {}
Run Code Online (Sandbox Code Playgroud)

我有上面的源 Rust 代码和下面的错误。

error[E0412]: cannot find type `ProgramResult` in this scope
 --> programs/myepicproject/src/lib.rs:8:58
  |
8 |   pub fn start_stuff_off(ctx: Context<StartStuffOff>) -> ProgramResult {
  |                                                          ^^^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0412`.
error: could not compile `myepicproject` due to previous error
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

使用锚点

rust blockchain smartcontracts solana anchor-solana

4
推荐指数
2
解决办法
5448
查看次数

可靠性:内存与堆栈

Solidity有3种不同的内存存储:存储、内存和堆栈。网上看了很多文章,还是不明白内存和栈的区别。我的问题是:

Q1. 内存和堆栈有什么区别?

Q2。假设我在函数中定义了一个局部变量,我怎么知道这个变量是存储在内存中还是栈中呢?(只有当变量声明带有“memory”关键字时,变量才在内存中?)

感谢大家。


感谢@Yilmaz 的回复。根据你的回答,假设我们有一个这样写的函数:

function test() public {
    string memory str;
    int i;
}
Run Code Online (Sandbox Code Playgroud)

str是否i同时在“内存”和“堆栈”上?

我的第三个问题是:

Q3。为什么只有数组、结构体和映射类型需要指定内存位置?为什么 Solidity 不允许我写int memory i;上面的代码?

storage blockchain ethereum solidity smartcontracts

4
推荐指数
1
解决办法
1542
查看次数

错误:无效的 Chai 属性:revertedWith

我想测试我的合约FundMe.sol但它如何脱离FundMe.test.js会弹出一个错误

\n

我的控制台

\n
FundMe\n    constructor\nDevelopment network detected! Deploying mocks...\n      \xe2\x9c\x93 Should set the aggregator addresses correctly\n    fund\n\n      1) Should fail if you don't send enough ETH\n\n\n  1 passing (977ms)\n  1 failing\n\n  1) FundMe\n       fund\n         Should fail if you don't send enough ETH:\n     Error: Invalid Chai property: revertedWith\n      at Object.proxyGetter [as get] (node_modules/chai/lib/chai/utils/proxify.js:78:17)\n      at Context.<anonymous> (test/unit/FundMe.test.js:29:46)\n
Run Code Online (Sandbox Code Playgroud)\n

将测试写入文件FundMe.sol 的文件

\n

FundMe.test.js

\n
const { deployments, ethers, getNamedAccounts } = require("hardhat")\nconst { assert, expect, revertedWith } …
Run Code Online (Sandbox Code Playgroud)

javascript node.js blockchain hardhat

4
推荐指数
1
解决办法
2678
查看次数

如何使用不在github上的链代码?

我已经使用这个开发了一个链码,现在我知道它可行,我想在具有多个节点的网络中测试它.

我应该在哪里放置我的链码,以便我可以在Hyperledger结构网络中部署它?

我用来设置网络.

blockchain hyperledger hyperledger-fabric

3
推荐指数
1
解决办法
2126
查看次数

从链码中调用另一个链码的最佳方法是什么?

我想从链代码的Invoke()方法中调用另一个链代码.建议的方法是什么?我想我可以在/ chaincode上使用标准REST API并通过其ID(由部署操作返回)引用它,但是有"系统"GO API来实现这一点,我也可以通过名称而不是引用链代码身份证?

blockchain hyperledger

3
推荐指数
1
解决办法
1207
查看次数

Hyperledger Custom Chaincode部署错误

我正在使用Hyperledger来处理POC.我已经设置了这里提到的链代码设置.我正在关注链接中提到的选项1(使用vagrant来运行CA服务器和一个VP).在我目前的设置中,我正在运行禁用安全性.我的VP被罚款运行,并且我能够启动并注册chaincode就好了(按照提到这里但是,当我试图通过CLI使用以下命令来部署我chaincode:

peer chaincode deploy -n mycc -c '{"Function":"init", "Args": `["hi there"]}'`
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

Error: Error building chaincode: rpc error: code = 2 desc = "Error getting chaincode package bytes: Cannot generate hashcode from empty chaincode path"
Run Code Online (Sandbox Code Playgroud)

我特意提到我存储自定义链码的路径,我收到以下错误:

Error: Error building chaincode: rpc error: code = 2 desc = "Path to chaincode does not exist: /opt/gopath/src/ProductBC/ProductBC/finished/"
Run Code Online (Sandbox Code Playgroud)

有没有人遇到过类似的问题或者有什么方法可以解决这个问题呢?

go blockchain hyperledger

3
推荐指数
1
解决办法
2580
查看次数

网络最新的松露部署

嗨,大家好我一直与soliditytruffle几天来开发合同.我正在测试使用由Ganache创建的网络RPC客户端来构建本地区块链环境.但有一件事我不明白.我按照以下步骤操作:

  • truffle deploy.我在网络上部署合同.
  • truffle test.我测试我的合同.没关系.
  • truffle deploy.我试着更新我的合同.说我"网络最新"

但是,如果我重新启动Ganache并更新我的合同truffle deploy工作(这是我不明白的事情).

为什么?有人可以向我解释一下吗?

contract blockchain solidity truffle

3
推荐指数
1
解决办法
2785
查看次数

在apache或intel公司下是hyperledger锯齿?

Hyperledger锯齿由Apache或Inter公司维护?

在此输入图像描述

在页脚有英特尔公司,如果我们想将项目转移到基于Hyperledger锯齿的生产,我们是否需要向英特尔支付?

apache blockchain hyperledger-sawtooth ibm-blockchain

3
推荐指数
1
解决办法
98
查看次数

我们如何在以太坊中生成多个随机数?

我希望我的智能合约在调用合约时返回7或8个唯一的随机数,范围从1到100。获得这种结果的最佳方法是什么?

blockchain ethereum solidity smartcontracts ether

3
推荐指数
1
解决办法
286
查看次数