New answers tagged

0

Deploying a single contract will be cheaper than deploying multiple contracts with the same functions. There are many costs associated with a transaction and the creation of a contract. To start, every Ethereum transaction costs 21,000 gas, no matter what the transaction is. Additionally, contract creations use a number of different opcodes, which all have ...


1

The first option is close. Before execution the transaction gasLimit * gasPrice are removed from the sender account Transaction is executed unusedGas * gasPrice is returned to sender usedGas * gasPrice is send to miner The state changes in 1, 3 and 4 are unusual in that there's only one part involved. See here https://github.com/ethereum/go-ethereum/blob/...


2

The first time, it succeeds - silently. No event is emitted, so you would have to check the bytecode length at that addresses to positively confirm that it worked. The second time, it fails - silently. The effect of "self destruct" is there is no code to raise an error because there is nothing to do. This can create an eery sense that something ...


1

You can use an emoji directly in a string literal in Solidity versions 0.6.12 and earlier. You cannot do so with version 0.7.0 or later. Solidity version 0.7.0 updated the parser to disallow non-printable characters in string literals. Instead, they introduced the concept of Unicode string literals, such as unicode"😃", which allows you to use ...


1

There's a cap to the maximum refundable gas. Only half of the total used gas can be refunded. (*) In the example at most you can refund (21000 + 5000) / 2 = 13000 gas. So it will be at 21000 + 5000 - min(13000, 15000) = 26000 - 13000 = 13000. Very close to the measured amount. (*) The exact details are in Ethereum's Yellow Paper Section 6.2 Execution.


0

Nothing is free. Processing instructions cost gas, just much much less than a transaction that changes state. It may not cost gas when the EVM is run in popular IDEs, which can lead to the false belief that pure functions cost nothing. This basic function: function bigLoop(uint max) public pure returns (uint) { uint n; for(n = 0; n < ...


2

The ("official") Solidity compiler and associated utilities are written in C++. But Solidity is its own language with its own grammar. does that mean that smart contracts require some level of C++ programming skills to get by? No. You could write a Solidity compiler in any language you like as long as the output of compilation is valid EVM ...


0

Can anyone in simple terms explain what expansion cost means? When your contract writes to memory, you pay for the costs associated with the number of bytes written. However, if you are writing to an area of memory that hasn't been written to before, there is an associated additional cost with using it for the first time. Think of it as an additional tax ...


1

__$de3f906ec3d3531c3d498f8b283d7f02e6$__ is a placeholder for library address. The deployment process of smart contracts look somewhat like this Library is compiled Library is deployed, gets an address Contract using library is compiled Contract is "linked" - all placeholders in the bytecode are replaced with the library address Contract is ...


0

After re-reading Solidity docs, I have realized that I still can declare a dynamic memory array in a view and initialize its dimensions to a variable (as opposed to declaring a fixed-size array which would need a compile-time constant): Record[] memory records = findRecords(); //get records from storage ViewModel[] memory results = new ViewModel[](records....


1

The term operator has been first introduced by the EIP-721 to define addresses authorized (or approved) by a NFT owner to spend all of his token Ids. In EIP-1155, the operator is set by the token owner thanks to the following function : function setApprovalForAll(address _operator, bool _approved) external { operatorApproval[msg.sender][_operator] = ...


1

Disclaimer I am adding this answer on the off chance that it helps future readers. Answer to the q. 1: G is what is called the "trusted setup" phase. In trusted setup, a secret (the lambda) is used to create proving and verifying keys (pk, vk); that secret is also called "toxic waste" and has to be destroyed or the owner will be able to ...


0

The question was asked in February 2018, that seems like an ancient history in the Etheruem space. Key terms "meta transactions" and "gas station network": https://opengsn.org/ https://docs.openzeppelin.com/learn/sending-gasless-transactions EIP-1613: https://eips.ethereum.org/EIPS/eip-1613 Recent examples of gasless token sends: USDC ...


3

It could be the Oracle that traces the delivery - many DHL-type delivery networks provide APIs to their information systems. Although there are certain subtleties with determining the identifier of the tracked "package".


3

Your biggest problem is that a contract can only receive assets which are inside the blockchain. You can't send regular money ($, €, any fiat) in blockchain and you can't send goods in blockchain. What you'd basically need is some way for an external party to tell the contract about the state of the assets (money and goods) outside blockchain. But it's ...


2

The examples that you gave fit well into bytes32 and they can be transferred to the contract as an array, which can be split into pairs inside. If you just want to transfer big data through a contract without processing it in it, then it is probably better to use a decentralized file system (IPFS, Ethereum Swarm) or cloud storage, and put a link to the data ...


1

Solidity 0.5+ has a different syntax for calling parent constructors. // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; contract Parent { public string name; constructor(string _name) { name = _name; } } contract Child is Parent { constructor() Parent("Guybrush Threepwood") { // Child ...


0

The new and correct way of importing the package is the top import that you posted: import "@openzeppelin/contracts/math/SafeMath.sol"; The bottom way is the old package. It is not recommended to use that one, as it may not be up-to-date.


0

While there are specific implementations of 1155 trying to be retrocompatible with 721, It sounds to me like the ERC998 is what you are looking for. A composable token using erc721 and therefore compatible with it. It allows for erc721 to own erc20 tokens.


1

There's a possibly unintended usage of selfdestruct, which can be handy at times or possibly a security flaw (if you don't account for it): you can use it to send ether to a contract that doesn't have a fallback/receive function. One use-case I have found this handy for is during testing; you can use a liquidity pool that contains a large number of tokens ...


1

If you call it from an externally-owned account: It is better to check the allowance in advance, because doing so can save you a bit of gas if it is insufficient and the transaction would subsequently revert. If you call it from a smart-contract account: Depending on how you want your contract function to behave - for example - you may want it to do ...


0

The more important difference is that if funcName reverts then for case 2 bla will also revert. For case 2 calls returns a boolean indicating if the call has failed, and have the posibility to ignore the failure. Using raw call is low level and discouraged because it is easy to make mistakes. Since solc 0.6 you can use try/catch try myContract.funcName(...


1

Solidity has a StackTooDeepException. This means that you can only have 16 local variables at any given time. Scoping, in this sense, allows the contract to create local variables within a specific scope (for example, within brackets {...}), and then destroy them within that scope. The reason this is important is because the newly created/destroyed variable ...


-1

Effectively, there is no difference. Using an interface provides compile time safety checks on arguments used. And simplifies the usage of return values the same way. This is a quick, simple example, but basically these code lines are equivalent. <Type> returnTuple = address.call( <payload as byyes> ); <Type> returnTuple = address.call( ...


Top 50 recent answers are included