Solidity

Solidity Event是如何实现的

我的梦境 提交于 2019-12-27 13:36:33
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一个Solidity Event的定义如下: event Deposit( address indexed _from, bytes32 indexed _id, uint _value ); 最多 3 indexed参数. 如果一个 indexed 参数的类型是大于32 bytes (比如 string 和 bytes), 就不存实际数据, 而是存数据的KECCAK256摘要(Digest). EVM Log Primitives 先来看log0 , log1 , ..., log4 EVM 指令. EVM 日志功能使用不同的术语: “topics”: 最多 4 个topics. 每个topic 32 bytes. “data”: 数据是event的Payload. 可以是任意长度的bytes. 一个Solidity event 如何映射到一个log 原语? 所有“non-indexed 参数” 被存为data. 每个“indexed 参数” 被存为一个32 bytes的topic. The log0 Primitive Log0生成一个只有data的日志项目, 没有topic. data可以任意长度的 bytes. 下面看一个例子 pragma solidity ^0.4.18; contract

解析solidity的event log

本小妞迷上赌 提交于 2019-12-27 13:19:29
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 参考文档 。 例子代码如下: pragma solidity ^0.4.25; contract Assert{ } contract TestReturn { Assert ast; event CreateAssertAll(Assert indexed _sig,uint256 indexed id); event CreateAssertOne(Assert indexed _sig,uint256 id); event Create(Assert _sig,uint256 id); function check() public returns(uint256) { ast = new Assert(); emit CreateAssertAll(ast,uint256(6)); emit CreateAssertOne(ast,uint256(6)); emit Create(ast,uint256(6)); } } 上面的代码中,有3个event。他们的index不同。生成的log数据结构不一样。 CreateAssertAll全部是index。 CreateAssertOne有一个是idnex。 Create全部都不是index。 我在ropsten上调用了这个方法。hash如下: https:

python以太坊类库web3.py概览

吃可爱长大的小学妹 提交于 2019-12-27 12:40:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> python通过web3.py库与以太坊交互共同入口是 web3 对象。web3对象提供API接口,python开发应用与以太坊进行交互如钱包创建、支付、转账等连接JSON-RPC服务器进行。 Providers提供者 Providers 使web3连接到区块链上。Web3.py库带有以下内置的 providers ,它们能够适用于大多数用例。 web3.HTTPProvider :用于连接基于http和https的JSON-RPC服务器。 web3.IPCProvider :用于连接基于ipc套接字的JSON-RPC服务器。 web3.WebsocketProvider :用于连接基于ws和wss的websocket的JSON-RPC服务器。 HTTPProvider :用于获取可以找到服务器的完整URI。对于本地开发,这类似 http://localhost:8545 。 IPCProvider :用于获取可以找到IPC套接字的文件系统路径。如果不提供任何参数,它将使用操作系统的默认路径。 WebsocketProvider :用于获取可以找到服务器的完整URI。对于本地开发,这类似 ws://127.0.0.1:8546 。 示例代码如下: >>> from web3 import Web3,

Error: new BigNumber() not a number: [object Object]

馋奶兔 提交于 2019-12-24 21:05:59
问题 Getting BigNumber Error .. tried almost everything This is the web3js function call creditPoints: function() { var self = this; alert("Credit Coins"); this.setStatus("Initiating transaction... (please wait)"); var meta; MetaCoin.deployed().then(function(instance) { meta = instance; //alert("credit Points"); alert(account); return meta.creditCoin( account, {from: account,gas: 300000}); }).then(function() { console.log("Transaction complete"); self.setStatus("Transaction complete!"); // self

Read-only Functions Iteration Cost

谁说我不能喝 提交于 2019-12-24 03:06:01
问题 I am developing smart contracts for some use-cases and currently I'm working on optimization of smart contracts. I am confused with something that I found interesting on Hitchiker's Guide. In the section 4- Iterating the contract code // returns true if proof is stored // *read-only function* function hasProof(bytes32 proof) constant returns (bool) { for (uint256 i = 0; i < proofs.length; i++) { if (proofs[i] == proof) { return true; } } return false; } For this code above, He states that

How to access Solidity mapping which has value of array type?

末鹿安然 提交于 2019-12-24 02:09:13
问题 I define a state variable of mapping type, e.g. mapping(uint256 => uint256[]). I thought to make it public so that I can access it from outside of the contract. However, the compiler reports error TypeError: Wrong argument count for function call: 1 arguments given but expected 2. . It looks like the automatic getter of the mapping doesn't return an array. For example, ContractB is the contract to be built, pragma solidity >=0.5.0 <0.6.0; contract ContractB { mapping(uint256 => uint256[])

Solidity compiler - problem with HelloWorld smart contract

我们两清 提交于 2019-12-23 05:15:37
问题 Im trying to run my first HelloWorld smart contract on the Enthereum network. This is my HelloWorld.sol contract. pragma solidity ^0.5.0; contract HelloWorld { bytes32 message; constructor (bytes32 myMessage) public { message = myMessage; } function getMessage() public returns(bytes32) { return message; } } When I try to build this using solcjs HelloWorld.sol --bin , there is just one Warning and no errors. I have installed web3 and solc using npm. When I run this on a node var solc = require

One of ethereum solidity methods is not working properly got error Returned values aren't valid, did it run Out of Gas

隐身守侯 提交于 2019-12-23 04:47:40
问题 I'm trying to deploy a solidity program to my private ethereum network. However, when i call a method it's not working properly. This is what i'vd done before the call method. $ truffle console truffle(development)> var dApp undefined truffle(development)> Hello.deployed().then(function(instance) { dApp = instance; }) undefined truffle(development)> dApp.message.call() test env is below truffle@5.0.28 solc@0.5.10 linux centOS 7 geth@1.8.23 I tried all of the solution in answer about the below

Quorum Ethereum Truffle) Error: Number can only safely store up to 53 bits

一世执手 提交于 2019-12-23 04:14:16
问题 I am actually learning smart contract programming on ethereum and I work with truffle. Right now I am making this tutorial here: https://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains Where you learn how to create a dapp with quorum. But now I have a problem. I did everything exactly as described, but when I do: truffle migrate I get this error here: $ truffle migrate ⚠️ Important ⚠️ If you're using an HDWalletProvider, it must be Web3 1.0 enabled or

Storing and Retrieving Data in Ethereum Blockchain

旧城冷巷雨未停 提交于 2019-12-23 03:06:52
问题 I am a beginner in blockchian and I want to store a personal demographics data in a ethereum blockchain via solidity.I have some basic questions regarding that: Do I have to store the data in a smart contract ? Say I store multiple personal data in the blockchain , in that case would each personal data get stored in separate blocks using the same instance of the smart contract ? Are there any open source tools through which I can view the blocks in my local ethereum block chain? 回答1: I will