Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

New answers tagged

0

The question is not clear enough, but if I understood you right. You need to perform an action when all goldNodes replied and until then you wait. I am sharing a sample code, where allGoldNodesReplied is false and it's said to true when all nodes reply. For that, your contract must know all goldNodes and their count and maybe some more info to prevent one ...


1

The short answer is No. What you are trying to do doesn't map to how this platform works. Normal assumptions about temporal time don't apply. Normal intuitions about execution time don't apply. The blockTime is the only, admittedly tenuous, connection to temporal time available. I'll break that down a little more. Nodes process all transactions, but ...


0

There are different approaches at Upgradeable smart contracts One of the simplest is for the frontend contracts to refer to the backend contracts, not as hardcoded addresses, but using ENS (https://ens.domains). The ENS entries are updated when new backend contracts are needed. Note that a significant benefit of smart contracts is their trustlessness, and ...


3

The pattern you are using is valid for certain table-like sets, but you should be aware of the limitations. It is ill-advised to do anything with a contract that loops - Getting Loopy with Solidity. You can, however, make it possible for a client to loop. It should be understood that "client" is an off-chain entity, in this context, because if it wasn't ...


3

Trust me. Everytime (everytime!) you are thinking to loop trough a dataset whose dimensions you cannot predict at the “start of the time“ in a blockchain based system, you are using blockchain for the wrong thing and/or your algorithm must be changed by rethinking it. Your model should be something where if a new “user” is added, the simply operation to add ...


0

You just have to trust the contract. The idea is that contract's code is public (byte code, I mean), so everybody may analyse it and decide, whether to trust it. The reality is that byte code is unreadable, so people anslyse source code instead, and then ensure, that compiling that source code produce exactly the same byte code as published on chain (here ...


0

Thanks for that quick response. I would like to clear my question. Suppose for this transaction: https://etherscan.io/tx/0x89221691a67b15427c97f1fd0cd65966ff617728cd897be27d88a04ee0bc1e2d Ether is being transferred via Contract. All I get to know from the contract's event list is that the event Transacted was emitted. I want to be sure about the authenticity ...


0

I'm a bit unsure whether you really mean Ether transfers or (ERC20) token transfers. Ether transfers don't emit any events (unless some contract happens to emit upon receiving Ethers). If you transfer Ether between EOA (Externally Owned Account) without contracts there will certainly be no events emitted. So let me provide an answer for both cases, just in ...


0

Just create a function like this: address payable public owner; modifier onlyOwner { require(msg.sender == owner); _; } constructor() public { owner = msg.sender; } function kill() public onlyOwner { selfdestruct(owner); } The kill function uses the selfdestruct function to "destroy" the contract making it unusable and effectively killing it....


0

In short This is not a reentrance attack. The actual vulnerability is the contract's mechanism allows cheap trail-and-error, until there a "hit". (Interestingly, "hit" is also the name of attacker's contract method) Attack Mechanism The attacker deployed a contract that calls random to see if a Win will happen. If yes, loop and call send 100 times. If ...


2

I haven't studied this in-depth but I see a clear problem outside of the mutex. This is not random. function random() private view returns(uint){ uint source = block.difficulty + now; bytes memory source_b = toBytes(source); return uint(keccak256(source_b)) % 100; } It is also not hard to guess. You are trying to make ...


2

I input the string "Cow", to a function in the smart contract. Next, I should be able to create a parent token which represents the string, and each child token should have a numerical ID within the range 1-50. A contract factory could serve as both an ERC721 deployer and a registry (inventory) of the deployed tokens. ERC721, itself takes care of ...


0

Short answer: If you want to transfer ether based on some condition, define your criteria and you can use one of the following methods inside a payable function: address.send(weiToSend) address.transfer(weiToSend) address.call.value(weiToSend)( ) You can read more about the above methods here and here. If you are new to smart contracts, there are a number ...


0

eth-crypto provides cryptographic JavaScript functions, such as encrypting data with the public key and decrypting it with the private key.


0

The short answer is you would make your own access control. RBAC is a specific approach. A suggestion would be to use the even simpler Ownable.sol (OpenZeppelin) example as a template, for ideas. The basic idea is to define your guards. modifier afterMidnight { // require(something, "patience. party hasn't started"); _; } function living() public ...


0

Mappings don't start having problems until 10 million values. Mappings are the one key strong asset solidity actually has.


0

As you can't hide information in the blockchain you have to use other means. If you are familiar with how the mining process works we can use the same logic here. The whole point of the mining (mathematically speaking) is that the actual mining is hard but verifying the results is trivial. So once a miner successfully mines a block he publishes the nonce ...


0

I want to parse the receipt.logs, but it fail when I use this code @Rob Hitchens. const abi = _.find(item => (item.name == "LoginEvent" || item.name == "CreateUser") && item.type == "event"); const eventJsonInterface = _.find( contract._jsonInterface, o => (o.name === 'LoginEvent' || ...


1

The short answer is you don't. You get what's in the log from the log. Other contracts can get the result, but you can't sign a transaction that changes the state and also get the result. Have a look here: https://blog.b9lab.com/calls-vs-transactions-in-ethereum-smart-contracts-62d6b17d0bc2 Hope it helps.


2

So if you mean if there is a serious penalty for instantiating a variable in memory rather than using it directly, no, there's not. Actually probably there will be no penalty at all if the compiler is smart enough, which shouldn't be a problem in cases like this one (specially with optimization enabled in the solidity compiler). That being said, I'd only ...


2

You could do this: if (now < limitRemovalDate && _offer > OFFER_LIMIT) revert("some message"); Or you could do this: require(now < limitRemovalDate && _offer > OFFER_LIMIT, "some message"); Which is technically the same just cleaner.


1

No. It would be expensive and it would not scale. The name of the game is to economize on writes and avoid loops. It's so important that your approach to problems like this may seem counter-intuitive, at first. You have to work out what the value would be if the data was updated in place. For that, you would just need to know the original number and the ...


0

These answers are good but I noticed they are a little on the old side and there is a way to send a transaction even when they have no ether. They just need a little help: https://medium.com/@andreafspeziale/understanding-ethereum-meta-transaction-d0d632da4eb2 It's tricky, but it doesn't depend on a protocol upgrade. A grossly summarized process works ...


Top 50 recent answers are included