New answers tagged

0

There is a short answer and an obscure answer. Short answer You can't. Events are not accessible internally, so use state variables for logic and emit events to inform external clients about changes. Obscure answer Access may be possible with assembly. I came across this pattern some time ago, and since events are much cheaper than state storage, it ...


1

This is how your contract should look like if you want to cover 0.6.x standard. However you should never fully trust any solitions here and always double check the logic you copy from here and make sure everything is working as it should be. pragma solidity ^0.6.0; /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ ...


1

nested hell Yup. This is circular: struct B { B[] as; } B contains arrays of B? The dynamic array of a struct inside a struct pushes the limits of what the compiler can handle. You would have to construct a memory instance of the struct and use the push method, which isn't present and then copy the works into storage. As a general suggestion, ...


0

But if a value is stored in an event, is there an efficient way to retrieve its value from a web3.js script (which is not running all the time and so cannot effectively subscribe to events)? There is a stateless (almost) pattern to consider. pragma solidity 0.5.16; contract BreadCrumbs { uint public prevChange; event LogChange(string arg1, ...


1

The code below compiles with ^0.5.16. There were a few updates needed. 1 - constant is no longer used. You need to use either view or pure more info here I made all view because they read the state. 2 - I needed to set the visibility for each of the functions. I made all public. More options here 3 - payIn is a function that sends money to the contract, ...


0

Here you go. I changed .send() to .transfer(), because transfer throws on failure while send is returning false on failure and you are not checking it anywhere. Had to setup visibility for all the functions and replace constant with view, because constant got deprecated in the latest versions. Next time just place your code into https://remix.ethereum.org/ ...


0

No, you can't. Only the node that receive the transaction could know it, but once the transaction is spread to the others nodes, this is hopefully lost.


2

I do not think it is possible. At least, it cannot be found in the documentation: https://solidity.readthedocs.io/en/v0.6.1/miscellaneous.html#index-4 Moreover, it would be a major paradox into a blockchain (at least a public one). One nice element is that it is very hard to know who is who in a network unless you want people to know it. If you have access ...


1

The EVM is internally consistent, deterministic and replicable, now and in the future. Its only inputs are signed transactions. These include both messages from users and transaction ordering blocks from miners. A contract cannot inspect an external source since there is no way to confirm the correctness of such a step in the future. That is, there is no ...


0

This design is inherently centralized and periodic distributions will not change that. Since the accounting is already in a mysql database it will not be a setback to continue that way. Present a function to request withdrawal on demand, and have the server send users their tokens when they ask for them. On the other hand, if a decentralized design is the ...


1

For example, should I change my solidity smart contract and for each function add returns(string,uint,uint) That won't do it. Return values are visible to other contracts but they are not visible externally. The problem I have is that it is so impossible to filter information just for a specific player You can filter events but you have to: ...


0

Please, be kind to me, I came across this post, but I am new to the Stack Exchange community ( Ive used it a few times, so I know formatting is important, but I'm just trying to be helpful.) This is a link to the event log of one of my contracts. it generates strings of meta data on chain, using two nodes, a seed phrase and a known algorithm to generate ...


1

EVM is isolated, which means there is no I/O to the outside world. However, you could program it in the way that your python code reacts on events published on-chain. This will not give you the ACID properties of a on-chain transaction, but it can be a valid solution depending on the usecase.


1

Here are my thoughts on this topic: Don't store your private key or mnemonic on your machine if it is connected to the internet. This is a great target for hackers. Over the years I have seen many different approaches. For example: Hardware Wallets Paper Wallets However a cheaper option is storing the private key as an encrypted (password protected) text ...


-2

The general advice in solidity for these kind of problem is to divide the storage of node-data from the node- topology network description. This means that any new node data should be added to a simple list (i.e. a dynamic array) and that the network of connection should be managed by a different structure. A mapping where the address is the node number in ...


1

library GraphLibrary { struct Graph { mapping (uint => mapping (uint => uint)) edges; mapping (uint => uint) sourceNodes; mapping (uint => uint) targetNodes; uint lastEdgeID; } function addEdge (Graph storage _graph, uint _sourceNodeID, uint _targetNodeID) external returns (uint) { require (_graph.edges [_sourceNodeID][...


1

You've declared function misbehaviorJudge. But you've implemented function misbeaviorJudge. So the way I see it, you are trying to invoke an unimplemented function. A couple of ways for you to avoid a similar issue next time (more precisely, convert it from a hard-to-investigate runtime problem into an easy-to-investigate compilation problem): Option #1 -...


0

It is not a good idea to have you paying for all your users. This open the door to many possible attacks to your money and your contract, as DoS attack, where someone repeatedly and fastly call your contract again and again and, this way, prevents any regular user to access the service and wastes your money in gas. This is because in Ethereum anyone who ...


0

The fact that you can do different things with similar syntax can be confusing. It's important to understand what's happening internally so you know what to use and when. The key here is the internal visibility and the storage pointer. Values versus pointers Suppose we say address a = "0x123..."; The compiler will look at that in the context of the ...


0

I understand this: I want to have mappings with addresses as keys and structs as the value. I want to store these addresses in an array and iterate through them. so far it looks like this how would I modify this? but I don't see what this has to do with it: Can you have an array of mappings? No. You can put a mapping in a struct, however, and you can ...


0

Ethereum does not charge rent for storing data, so in many cases it is more gas-efficient to keep in storage data, that is not needed anymore, rather than to delete it. Self destruct (a.k.a. suicide) opcode was supposed to address this, by deleting storage of the contracts not needed anymore, but it caused more problems than solved, so now its usage is ...


Top 50 recent answers are included