Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [solidity-best-practices]

The tag has no usage guidance.

0
votes
2answers
19 views

Call of contracts function reverted

Sorry for posting a block of code, but I just can't get this to work. I am using ganache for testing my contracts with mocha and NodeJS. Every time I call doTransfer, it fails. The call is reverted....
0
votes
0answers
20 views

How can I pass struct from one contract to another?

I have two contracts and I'm trying to pass the struct data from one to another, I can do this by creating a mapping and having a uint input associated with that struct but I'd like to get the struct ...
0
votes
1answer
28 views

What does ERC20Interface do in smart contracts?

I found this fantastic code used to generate a smart contract which allows you to send your ERC20 tokens to another address. A simple overview / explanation of how that works is as following: We ...
0
votes
2answers
21 views

Deploy ERC721 tokens to many addresses

How to I transfer many of my ERC721 tokens to many addresses? MyERC721: function mintUniqueTokenTo ( address _to, uint256 _tokenId, string _tokenURI // Store, receipient'...
3
votes
3answers
28 views

Function that returns address if is passed or msg.sender

I'm implementing an ERC721 contract and I want to execute the following logic. This is what I want: If the user pass to a method an address, return that address, if not, return the user's address. I ...
0
votes
1answer
16 views

Gas Estimatation

I am little confuse in the concept of Gas Estimation and price. When i add new user i get popup through metamask for the transaction amount and gas used which is totally fine. I checked my code in ...
0
votes
1answer
34 views

Solidity 0.5.x - make address array payable

I'm trying to write a contract that uses an address[] array which should contain payable addresses. But apparently creating a payable address array doesn't work in solidity 0.5.x. All I'm trying to ...
0
votes
1answer
22 views

Single Entrance Restriction

Please suggest that how two restric subscriber for single entry means no one can join twice. function selectionW1(address subscribersW1, uint subscriberWheelW1) public { require (...
0
votes
1answer
30 views

Is it ok to build app with huge data in ethereum blockchain

I agree that the smart contract works well for small Apps. Is it ok to develop a app with huge data. For this let us take an example of building a huge patient database across hospitals (only with key ...
0
votes
1answer
21 views

Function execution right based on external contract state, ballot and proposal example

i'm building a sample application which require voting. I think it needs to be split into 2 contracts where the owner of Ballot will create Proposal contracts. Splitting simply because the logic is ...
2
votes
1answer
29 views

Unused variables warning in address.call return tuple (bool, bytes memory)

I have the following code fragment. function forward(address destination, bytes memory data) public { (bool res, bytes memory retData) = destination.call(data); assert(res); } Since retData ...
1
vote
1answer
35 views

Problem with approve and transferFrom for making payments using ERC20 Token Contract

I have a contract that uses the ERC20 token contract for making payments. Now, in the ERC20 token contract we have the following implementation of approve function: function approve(address _spender,...
3
votes
2answers
93 views

factory contract storage patterns

i'm new to solidity and trying to understand the better storage option for the factory contract. i want: to be able to get all deployed contracts. to be able to get all deployed contracts by creator ...
2
votes
1answer
32 views

solidity ^0.5.0 factory pattern mapping apprach

new to solidity. Trying to understand the better approach for using a mapping storage in factory contract. 2 options: Use mapping(address => Contract[]) Use mapping(address => address[]) ...
1
vote
2answers
52 views

Is there any kind of locking protocol in Ethereum?

Is there any kind of locking protocol in ethereum, like can two transaction update the state variable same time ?, If yes then how would you avoid that ? Smart Contract XYZ is deployed and two people ...
2
votes
1answer
30 views

Add more logic to a payable function

Is it possible to include in a payable function a message such as "Transaction rejected - Company not registered" which is displayed when a transaction is rejected? My code is as per below: ...
2
votes
2answers
56 views

Why is the Eternal Storage approach still used if it hugely increases gas usage compared to storing data in structs?

I was wondering why is the eternal storage approach (first code snippet) still used? I know it's meant to make contracts upgradable but it seems too expensive to me. contract Storage { mapping(...
1
vote
1answer
30 views

Is ApproveAndCall also vulnerable to double withdrawal attack as is Approve?

As above, is ApproveAndCall also vulnerable to double withdrawal attack? https://www.reddit.com/r/ethereum/comments/6uckdx/reminder_about_problems_of_most_erc20_tokens/
1
vote
1answer
22 views

What about calls you can do safely in constructor?

As a matter of fact, there is more than one discussion about what are the call you can safely do in the constructor. Someone thinks “avoid all external call”, some other says “avoid to use ‘this’ or ...
2
votes
1answer
29 views

SOLIDITY: is anywhere formalized the assignment operator behaviour in nested statements?

As a matter of fact, solidity seems to have same behaviour of C in nested assignment. I.e. running the sample test contract below, calling nestedSum(1) results in the following: a=38, b=16, c=4 ...
0
votes
1answer
25 views

What is the work of self destruct in a contract?

How it can be used for handling force sending of ether to a contract without triggering fallback function ?
0
votes
1answer
16 views

What are the best Practices for writing truffle Tests for a Smart Contract ?

I am currently having a project where a banking system is to be made, what is the approach to get into it. Its suggested to write the tests first and then proceed with the smart contract. What are the ...
4
votes
1answer
2k views

TypeError: Data location must be “storage” or “memory” for parameter in function, but none was given

/// @dev Adds a new transaction to the transaction mapping, if transaction does not exist yet. /// @param destination Transaction target address. /// @param value Transaction ether value. /// @param ...
2
votes
2answers
30 views

Make Smart Contract Only Accessible from a Web App

I have got a Solidity smart contract which only interacts with a React front-end using web3. I want to restrict access to the smart contract so that only the React front-end can access the smart ...
1
vote
1answer
71 views

How to handle dynamic size string array in solidity?

I have a shop owner and a shop owner can have multiple products. I want to keep the products id in an array. Also, A public method can return all the product id list of a shop owner. I tried the ...
1
vote
2answers
17 views

Can I instantiate a struct with a member struct without supplying a member struct?

I have a struct containing another struct. The member struct does not yet exist when instantiating the containing struct. Is there a default for a struct (for address, int, etc' I would initialize ...
0
votes
1answer
33 views

Static Analysis raised 9 warning(s) that requires your attention. Click here to show the warning(s)

I receive these warnings in REMIX so the question is: Can I compile my contract and then verify it regardless of these warnings? pragma solidity ^0.4.25; library SafeMath { function mul(uint256 a,...
0
votes
0answers
14 views

Hello world for a browser app that has an off-chain data cache

I read here that bulk access to lists/arrays/etc is painful in solidity and in general data is often persisted elsewhere and dapps just interact with it to verify data integrity in order to be ...
0
votes
1answer
32 views

Return an array of mappings reflecting global state between struct associations?

I am looking for a construct that's something like "return an list of key value pairs," which I think would be implemented as an array of mappings. Is that right? That is, I'd like a data structure ...
2
votes
2answers
94 views

Best practices for generating a random uint256 [duplicate]

I've read through this thread and this thread and they offer a lot of interesting techniques, but what's the minimal code snippet for the currently accepted method of generating a random number in ...
0
votes
1answer
23 views

Managing unforeseen changes in contract development

I'm reading here: Centralized Administrator All dapps are fully decentralized by default, but that doesn't mean they can't have some sort of central manager, if you want them to. Maybe you ...
1
vote
1answer
34 views

Data persistence in ethereum smart contract across deployments

I have developed a SmartContract using ethereum which has an internal struct to store some of the privilege mapping. I find that whenever there is any change in the smart contract and the deployment ...
1
vote
1answer
27 views

What is the difference between writing emit in an event and not using emit? [duplicate]

For example, event CoinTransfer(address sender, address receiver, uint amount); What is the difference between CoinTransfer(msg.sender, receiver, amount); and emit CoinTransfer(msg.sender, receiver, ...
0
votes
1answer
17 views

Membership in a set of strings

I'm looking solidity help in storing a set of strings and checking for membership in that set. I have a concrete and an abstract question on that: Concrete What is the data structure in solidity ...
1
vote
1answer
26 views

Best practices on handling both Ξ and tokens

I'm writing a contract which handles both Ξ and ERC20 tokens. I know that many dApps use WETH and I understand what it does, but I'm not sure if it was integrated because that's the only way to ...
0
votes
0answers
26 views

Are function modifiers added to the stack in solidity? [duplicate]

I've got a function with a decent number of modifiers and I hit the CompilerError: Stack too deep, try removing local variables error. If I remove one of the modifiers though, everything's all right. ...
1
vote
2answers
28 views

Why are all parameters prepended by an underscore in ERC interfaces? [duplicate]

For instance, both ERC-721 and ERC-725 have underscores(_) before any function parameter. I understand that normally their goal is to avoid variable overloading. However, what is the rationale for ...
0
votes
2answers
80 views

What is the best practice for a tax payment Smart Contract?

I have just been introduced to Ethereum Smart Contracts and I have a faculty-related project that implies the usage of them. The idea is to create a DApp which allows clients (persons) pay taxes (in ...
0
votes
1answer
25 views

Solidity msg.sig is not consistent

I have 2 contracts pragma solidity ^0.4.24; contract C1 { event Sig(bytes4 sig); C2 c2; constructor(address c2Addr)public { c2 = C2(c2Addr); } function func1()public { ...
-1
votes
0answers
18 views

How to execute a method in smart contract automatically after a certain period of time? [duplicate]

I want to execute mint() method in an ERC20 smart contract automatically each year. How can I achieve the above?
0
votes
1answer
31 views

Diamond inheritence problem [duplicate]

interface I { } contract A is I { } contract B is A { } contract C is A { } contract D is B, C { } What would happen in this situation? How is this kind of diamond inheritance resolved in ...
1
vote
1answer
16 views

How to build a contact that allow rating?

If I have a contract that has a list of sellers, how would I code a simple contract that if some condition applies, the contract in an automatic way will increase the reputation/rating of the sender ??...
0
votes
1answer
25 views

Sending real ETH to contract on Rinkeby

I have a contract deployed to the Rinkeby testnet. It includes the following function: function deposit(uint amount) payable public { require(msg.value == amount); } If I try to send ETH to this ...
2
votes
3answers
203 views

How to map an address with a string array in solidity?

Goal: I wish to store an array of names with an address in a smart contract. It's more like Key-Value pairs where addresses are paired with a list of type strings. Can I use mapping to implement this?...
-1
votes
2answers
25 views

Solidity Token Sale? [closed]

How to build solid code Token Sale External? For example SmartContract : 0x5bE7E9B948cd6d026585F72CC567879ffd0b629b With fuction - updateTokenPerEth No need time. Give me recommend code.
2
votes
2answers
64 views

is selfdestruct a good practice?

A contract after selfdestruct cannot manage transactions, and as such any ether sent to it is lost. Wouldn't be better to switch to a contract defined state "dismissed" and reject any ether sent by ...
1
vote
1answer
138 views

Why use VS Code IDE instead of remix?

I've seen that during the course of tutorials I am following, the intructors have gradually shifted over to Visual Studio code rather than use remix. I could not find any such explanation as to why ...
1
vote
0answers
32 views

Should I checkAndCallSafeTransfer while creating NFT?

As per erc721 a good practice during transfer of an NFT is to use 'safeTransfer()' which calls: checkAndCallSafeTransfer of the IERC721Receiver interface. My question is, when creating a new ...
1
vote
1answer
44 views

Storing millions of values in mapping variable

Is it a good practice to store millions of values in a mapping variable for unique verification? For example, storing a customer name and unique number and later retrieve customer information from ...
1
vote
0answers
129 views

Best-pratice to write smart contract

I need your help to write a smart contract to the best way and avoid an attack. I have a function that user can call to buy Service and update the state. Now, I am confused, it will be different if I ...