3

Yup, it does cache the numbers, even without the optimizer enabled! When passing 65535 (max uint16) as the parameter x, it costs 1003 gas to run either foo or bar. I ran this test with Solidity v0.8.3 on Remix. contract PowersOfTwo { uint256 internal constant TWO_POW_1 = 2**1; uint256 internal constant TWO_POW_2 = 2**2; uint256 internal constant ...


2

Yes, it is possible. Moreover that technique was already used against MakerDao, read https://forum.makerdao.com/t/urgent-flash-loans-and-securing-the-maker-protocol/4901. It can be fixed by requiring funds to be locked for a period of time longer than a block.


2

You can accomplish something like this using staticcall: contract Test { function test (bool transaction) public view { if (transaction) { (bool success,) = address(this).staticcall(abi.encodeWithSignature("foo()")); require(success, "Contract call failed"); } } function foo () public { // ... } } ...


2

You can include in your contract a key that only your app know, but... the Ethereum net make public the smart contracts code, then I dont know how you can avoid decrypting the communication between the app and the contract. Maybe if you dont verify the contract the code of it stay hidden. Other solution I can think is to create 2 contracts, where the second ...


2

I think the question is too general in nature so the only possible answer is "it depends." The right way to structure the contract depends on what the contract is supposed to do. Deployment is a specific step in the lifecycle of the contract. What needs to happen at that stage? For example, it might be unacceptable to have an instance of the ...


2

Here are the key topics and keywords to search for: Generally: "Whitelist" the tokens you DO accept. Use the "approve and transferFrom" pattern. Decide if your token list will be static or changeable and consider the "Ownable" pattern to control access to the maintenance function if the latter. Otherwise, consider populating ...


1

It always depends on your needs. The biggest difference is that you can't iterate over a mapping. So if you store two entries (key => value) in a mapping, there is no way to get the values without knowing the keys. In your example, it also depends on your needs. If you only want to access the answers based on known key (so for example a function which ...


1

NFTs are auctioned in various ways on various platforms. An auctions could theoretically be completely centralized - an owner says they're taking bids until a certain time, potentially even off-chain, and at the end of the time, the bidder informs the winner they have won, accepts their payment, and sends the NFT. There wouldn't be much you could do with a ...


1

By default, a contract without a payable function can't receive Ether. However, there are some exceptions, or tricks, on how it's possible: https://ethereum.stackexchange.com/a/63988/31933 But for normal usage, you need a receive payable (https://docs.soliditylang.org/en/v0.8.0/contracts.html#receive-ether-function) function in the contract. So the minimum ...


1

IMHO, it's not a terrific example for teaching. Hash functions are very useful for validating information and they are used to prove things with Smart Contracts as well as on the blockchain itself. For example, block transactions are hashed which is a sort of fingerprint for authentic blocks. Previous blockhashes are part of that functions, so it forms a ...


1

You can do this: constructor() { foo(); } function foo() public { ... but you cannot do this: constructor() { this.foo(); // external call to non-existant function } function foo() external { foo() is indeed available as an external function from functions but the constructor doesn't "write" the code until the end, so foo() does not exist ...


1

I'm not sure why it's written that way in the docs. If you have the contract source code (as is the case here), you can freely create new instances of it. It's just a matter of whether you want to do that (or whether you should do that). My guess is that the doc is trying to say that "don't accidentally create a new instance of it when you just wanted ...


1

In a recent post by Vitalik Buterin on Reddit he mentions several proposals that were considered in the protocol design but didn't make the cut. One of the proposals called delayed calls would introduce an opcode ALARM that allow a contract to execute in a future block. The proposal has several use cases but it was discarded due to time constraints.


1

Deep down, an array is a mapping with range-bound keys. The most expensive aspect is the SSTORE operations and SLOAD operations which are the same in both cases. An array has additional steps (operations, so gas) to check that row is not out of range. A dynamic array is significantly more expensive because each push overwrites the length and range checks ...


1

If I understand correctly, you want that Bob proves that he is Bob, the owner of the NFT, when he makes a request to your server. The server wants to be sure that the request was sent from Bob and not someone else pretending to be Bob. The answer is yes, you can do this. To prove that he is indeed Bob, Bob should send a transaction to a smart contract that ...


1

It is unlikely anybody is willing to invest unless you have what takes it to execute it before the ICO. Because it is unlikely you do not know what you are doing and you fail and people lose their money. Even better you first build a working minimal viable product, then raise money.


1

the answer is no. it will not compile view functions cannot modify the state and the compiler check this and give you back TypeError: Function declared as view, but this expression (potentially) modifies the state Tested it with solidity 0.8.3


1

Depends on the exchange, but I doubt a trade is a new contract in any dex (decentralized exchange). A trade is typically a call to a certain function in a contract. That function executes the trade by calling some background contract functionality to calculate ratios and so on. If you wish to trade token A for token B, the trade looks typically something ...


1

Any guesses as to what in the hell type of a contract is paying out 40+ Ether at a time upon request A contract that is selling NFTs. If you look at the top (internal) transaction in that list (this one), you'll see a series of transfers. If you look at the Input Data field, you'll see the called function: Function: acceptBid(address _originContract, ...


1

Yes. In fact that’s how the Chainlink nodes operate. When calling buildChainlinkRequest and sendChainlinkRequestTo In the any API call feature you are actually emitting events that chainlink nodes look for. You can modify this to have a node looo for your specific event, but you need to use a node that uses an ethLog initiator instead of runLog. Check out ...


1

You could have a contract which stores the addresses of each of your deployed contracts. Perhaps with mapping(bytes32 => address) public contract_addresses; It could have a function exposed for adding new records to that mapping, which you could make a call to in the constructor of each contract. Just remember to make sure the deploying address is ...


1

It does not work because as you said A and B addresses are not stored in B and A. The exemple you linked his about compilation and importing, and cannot works in test (infinite loop and no setup for a and b values). Something like that should do the trick for the setup but be aware that the infinite loop is still present contract InterfaceOfA { ...


Only top voted, non community-wiki answers of a minimum length are eligible