People who code: we want your input. Take the Survey

New answers tagged

1

In the case where the calls are inside a solidity function function foo() public { uint256 amountx = 100 tokenOneContract(tokenOneAddress).transfer(address(this), to, amountx) tokenTwoContract(tokenTwoAddress).transfer(to, address(this), amountx); } Then either both functions will succeed or if any of them fails the whole transaction will revert....


1

It's more like a design preference. One of the most important principles in CS is DRY (Don't Repeat Yourself). One of the goals from that is to have less duplicate lines as possible, and thus less chance of a bug slipping into the written code. In your example above, you could possible have more than one implementation for approve with different signatures ...


1

Two things you can do change _safeMint behavior Override _safeMint and call its parrent contract MyToken is ERC721 { function _safeMint(address to, uint256 tokenId, bytes memory _data) internal override { /* Can do something here and modify input parameters */ super._safeMint(to, tokenId, _data); /* Can do something else here */ ...


0

Good question indeed, I think the best solution we have right now is Decentralized Autonomous Organization (DAO). These kind of changes should be managed by DAO through proposal based decision making.


1

One of the projects using such 'short' addresses is the Gas Token. From https://gastoken.io/#GST2 : The address of our GST2 GasToken, 0x0000000000b3F879cb30FE243b4Dfee438691c04, is hardcoded. Note that this address is very short (only 15 non-zero bytes instead of 20). We generated our GasToken contract at such an address on purpose, so as to save some gas ...


0

There were several audits that found important issues. Both audits won't recommend vyper for use in production. Then the Ethereum Foundation decided to support an alternative implementation in rust, while the original python implementation continues development independently. Vyper is an interesting alternative to solidity but the lack of a production ready ...


1

Events can be thought of as logs written in the blocks. It is useful for off-chain services that can subscribe to these events and take action. As they modify the storage, events increase (slightly) the gas cost of the transaction (more info here : How do events influence a transaction's gas?). A burn usually emits a Transfer event with the recipient ...


2

Replace "=" with "==" in require statement : require(msg.sender == data[i].owner, "Sender is not owner.");


1

You're right that not specifying decimals, would treat it as 0. It sounds tautological, but to answer your related questions, a totalSupply of 100 would be 100 tokens, and a transfer of 10, would transfer 10 tokens. When using decimals, make sure to see this question because it does affect the values for totalSupply and transfer amounts: Decimals on ERC20 ...


1

The smallest addressable chunk of storage is a 32-byte word. Arrays lay out the elements in separate words in discrete locations, so each single-byte element will be in its own slot. The smallest read/write op handles a full word even if many variables are packed in. The compiler will pack them in if they "fit". This struct can read two variables ...


2

It does not have anything to do with the function being virtual. Modifiers can only be used on functions with implementations. Modifiers have a special symbol _; (as indicated in line 8 your code), which means the body of the function you are modifying is inserted in that particular location. The modifier would only work here if you did something like this: ...


0

The transfer() function does not care if there are decimals or not. It is purely a cosmetic divisor for human display.


1

The term to implement you are looking for is called atomic transactions. Just look for atomic transactions in ethereum.


0

No. The contract size mainly depends on the source code. There are other factors like compiler version used, the EVM's opcode pricings, but they are minor variations. Remix in the "Deploy & Run transaction" tab has a "Gas Limit" input, with a default value of 3M gas.


2

I see this type of question popping up at a lot of different places and it is (unfortunately) often answered with "you don't need that" or "why would you want that". When strictly speaking Blockchain, this type of answer is right, assuming that all "communication" is done by sending a signed transaction to the blockchain. Here, ...


0

50,00,000 For clarity, I'll assume you meant for 50,000,000. With two decimal places, add two more zeroes, so: 50,000,000.00 => 5000000000. You still have the problem of indivisibility/precision at the low end, e.g. sending 1. This just doesn't go away. You can and should decide what happens to rounding errors because they are unavoidable. Hope it helps.


2

Yes, exactly. If a function contains require(msg.sender == address(this)); It means only the contract can call it. For example the Gnosis Multisig wallet has the modifier (syntax is for solc v0.4) modifier onlyWallet() { if (msg.sender != address(this)) throw; _; } This implies that any function with that modifier is only callable by the ...


3

The contract has to call one of its own functions and the message has to come from the outside. In that case, the msg.sender will indeed be itself. pragma solidity 0.7.6; interface IRecursive { function isMe() external view returns(bool); } contract Recursive is IRecursive { function isMe() external view override returns(bool) { if(msg....


0

Once you're ready to obtain external price data, be sure to check out the Chainlink docs on how to do this, it's super easy! I know this isn't a hackathon submission, but we also have a great hackathon resources page with some links that could be useful to you as part of your learning journey


1

It's possible and I think it already exists. However I would simply create a contract that wraps these 10 tokens minting a new "index token", you could even choose different quotes for token. Then you can burn this token to get back the 10 tokens, with a possible return/loss. If token get quote on a DEX then arbitrageurs should keep the price ...


1

The minimum is the functions your contract needs. Apart from possible code organization concerns on your side, there is no reason to include unused functions. Hope it helps


2

You need to establish the address(es) of the tokens to accept and then use the Approve and TransferFrom pattern. include "IERC20.sol"; contract Lotto { address public token; constructor(address token_) { token = token_; } function enter(unit amount) public payable { require(amount > .01 ether); // it is assumed that the ...


1

Contract-Orientated Programming - also called Design by Contract (DbC) - is a software engineering paradigm aimed at making software more reliable. "Design by contract (DbC), also known as contract programming, programming by contract and design-by-contract programming, is an approach for designing software." The "Contract" part of the ...


2

As written, it cannot be done. One of the important paradigm shifts for an experienced developer is the realization that a contract cannot, and will not, ever do something it wasn't programmed to do. There is no admin access, no direct access to the database (or "state"), and no way to repair anything unless it was proactively inserted into the ...


1

it depends on planning ahead and there might not be enough of that in this case. Think of it like a spaceship you shoot into space, on its way to another planet and going as fast as your engineers know how to make it go. There is no way to catch up to it but you exchange messages by radio signals. So ... if you had the foresight to create a language and send ...


0

Each blockchain state write, where a state is modified using SSTORE instruction is, going to cost a lot of gas. You need to design a different mechanism where all users as a pool members get new tokens through liquidity mining or similar program and then can claim any received tokens.


Top 50 recent answers are included