我有一个合约的功能,它会在每次通话时发出事件.
我想在每个测试中发出一个正在传递的事件,这里有一些测试:
it("should emit Error event when sending 5 ether", function(done){
var insurance = CarInsurance.deployed();
insurance.send({from: accounts[0], value: web3.toWei(5, 'ether')}).then(done).catch(done);
});
it("should emit Error event when sending 5 ether", function(done){
var insurance = CarInsurance.deployed();
insurance.send({from: accounts[0], value: web3.toWei(5, 'ether')}).then(function(txHash){
assert.notEqual(txHash, null);
}).then(done).catch(done);
});
it("should emit Error event when sending 5 ether", function(done){
var insurance = CarInsurance.deployed();
insurance.send({from: accounts[0], value: web3.toWei(5, 'ether')}).then(function(done){
done();
}).catch(done);
});
Run Code Online (Sandbox Code Playgroud)
结果是:
1) should emit Error event when sending 5 ether
Events emitted during test:
---------------------------
Error(error: …Run Code Online (Sandbox Code Playgroud) 我通过npm以下方式安装了松露:
sudo npm install -g truffle
但是当我在控制台上运行松露列表时它就给了我
bash:truffle:命令未找到
这在其他语言中可能很简单,但我不知道如何在 Solidity 中做到这一点。
我有一个bytes32这样的0x05416460deb76d57af601be17e777b93592d8d4d4a4096c57876a91c84f4a712。
我不想将字节转换为字符串,而是只想将整个内容表示为字符串,例如“0x05416460deb76d57af601be17e777b93592d8d4d4a4096c57876a91c84f4a712”。
在 Solidity 中如何做到这一点?
更新:
为什么我需要这样做:基本上我连接到一个预言机,它在链外执行一些工作,最后将文件上传到 IPFS。我需要从预言机将内容标识符添加到我的合约中。预言机只能bytes32作为响应发送,因此我将其转换为多重哈希,并仅将来自预言机的digestas发送bytes32到合约。
到目前为止一切顺利,我可以在合约中重新创建多重哈希。问题是,在此之后我创建了一个ERC721(NFT)令牌,并且我必须在元数据中存储一些对 IPFS 文件的引用,该元数据只能是格式的string。这就是我现在被困住的地方。
错误:Truffle 当前使用 solc 0.5.16,但您的一个或多个合约指定 \xe2\x80\x9cpragma Solidity ^0.8.0\xe2\x80\x9d
\n这是错误的照片 - https://gyazo.com/2f5ea2f50cc1d4ef5eea2f21d0e04fe7
\n我的所有合约都使用 ^0.8.0 编译指示。我的 truffle-config 也使用与您在此处看到的相同的版本 -https://gyazo.com/1ec8b28ca48902c091004f8659cf678d
\n请帮忙。非常感谢。
\n如何在没有源代码的情况下使用 Remix 与以太坊上已部署的合约(不是我的合约)进行交互,但我有 ABI。
我想要这样做的原因是因为某些合同有超过 20 个 .sol 文件,我不想手动复制并粘贴到 Remix 中。
尝试使用以太坊来解决区块链问题,在尝试与已部署的合同进行交互时,我遇到了问题.我想要实现的是调用一种方法来显示添加到使用Geth本地部署的私有区块链的信息.
我无法通过我的智能合约调用任何功能,我一直在想我是否做错了什么......有人能告诉我如何从这个合同中简单地调用其中一个方法吗?让我们说出显示现有的代理商,或者用户所属的代理商名称.
我的合同:agency.sol
pragma solidity ^0.4.18;
// We have to specify what version of compiler this code will compile with
contract Agency {
event NewAgency(uint agencyId, string name, uint dna);
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
//agency structure
struct Agency {
string name;
uint dna;
}
Agency[] public agencies;
mapping (uint => address) public agencyToOwner;
mapping (address => uint) ownerAgencyCount;
function _createAgency(string _name, uint _dna) private {
uint id = agencies.push(Agency(_name, _dna)) - 1;
agencyToOwner[id] …Run Code Online (Sandbox Code Playgroud) 该代码产生相同的输出。
pragma solidity ^0.5.0;
contract mycontract
{
function add(uint c, uint d) public pure returns(uint)
{ uint e=c+d;
return e;
}
function add(uint j, uint k) public view returns(uint)
{ uint f=j+k;
return f;
}
}
Run Code Online (Sandbox Code Playgroud) functional-programming blockchain ethereum solidity smartcontracts
我正在使用以太坊制作一个项目。
在这个项目中,我正在制定一个名为“A”的合同。
当我向“A”发送消息时,我希望“A”发出网络请求。
Solidity 是否可以使用 http 请求(方法 GET/POST )?
我已经花了几个小时试图了解执行价格。
我理解中间价格的概念,因为它是两对之间的准备金比率。
根据 Uniswap sdk文档,执行价格是发送/接收资产的比率。我很难理解计算是如何完成的。此外,Uniswap 的货币对交换似乎是基于执行价格而不是中间价格。为什么在交易时使用执行价格而不是中间价格?
我正在 Solidity 中学习以太坊开发,并尝试运行一个简单的 HelloWorld 程序,但遇到了以下错误:
函数中返回参数的数据位置必须是“内存”或“calldata”,但没有给出。
我的代码:
pragma solidity ^0.8.5;
contract HelloWorld {
string private helloMessage = "Hello world";
function getHelloMessage() public view returns (string){
return helloMessage;
}
}
Run Code Online (Sandbox Code Playgroud)