您好,我最近刚刚开始从 Udemy 学习 Solidity,尽管在几乎完成课程后我还没有理解 assert 和 require 之间的区别。当不满足要求时,它们不是都会破坏功能吗?在合约内的 Gas 优化方面,两者相比是否有优势?
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)
有什么建议吗?
使用锚点
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;上面的代码?
我想测试我的合约FundMe.sol但它如何脱离FundMe.test.js会弹出一个错误
\n我的控制台
\nFundMe\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)\nRun Code Online (Sandbox Code Playgroud)\n将测试写入文件FundMe.sol 的文件
\nFundMe.test.js
\nconst { deployments, ethers, getNamedAccounts } = require("hardhat")\nconst { assert, expect, revertedWith } …Run Code Online (Sandbox Code Playgroud) 我想从链代码的Invoke()方法中调用另一个链代码.建议的方法是什么?我想我可以在/ chaincode上使用标准REST API并通过其ID(由部署操作返回)引用它,但是有"系统"GO API来实现这一点,我也可以通过名称而不是引用链代码身份证?
我正在使用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)
有没有人遇到过类似的问题或者有什么方法可以解决这个问题呢?
嗨,大家好我一直与solidity和truffle几天来开发合同.我正在测试使用由Ganache创建的网络RPC客户端来构建本地区块链环境.但有一件事我不明白.我按照以下步骤操作:
truffle deploy.我在网络上部署合同.truffle test.我测试我的合同.没关系.truffle deploy.我试着更新我的合同.说我"网络最新"但是,如果我重新启动Ganache并更新我的合同truffle deploy工作(这是我不明白的事情).
为什么?有人可以向我解释一下吗?
我希望我的智能合约在调用合约时返回7或8个唯一的随机数,范围从1到100。获得这种结果的最佳方法是什么?
blockchain ×10
solidity ×4
ethereum ×3
hyperledger ×3
apache ×1
contract ×1
ether ×1
go ×1
hardhat ×1
javascript ×1
node.js ×1
rust ×1
solana ×1
storage ×1
truffle ×1