Questions tagged [contract-design]

for high-level questions about the choices made during contract construction

349 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
0
votes
1answer
20 views

Array of Struct

I have two structs - property and owner. struct owner { string ownerName; string ownerID; } struct property { string location; uint sqFeet; owner[] owners; } I want to ...
0
votes
0answers
39 views

How do I access data in another contract/node?

I have two contracts - Data.sol and Buy.sol. Data.sol contains information on products, etc. I want to use Buy.sol to get and update data in Data.sol, somewhat like having a database. I know this can ...
0
votes
0answers
12 views

Need some feedback/critique on a smart contract that allows anyone to send Eth and split it (50:50) with two other accounts

pragma solidity 0.8.1; contract splitFunds { mapping(address => uint) public beneficiaryBalances; address[2] public beneficiaryList; event LogReceived(address sender, uint amount); event ...
0
votes
0answers
11 views

Continuous Funding Chainlink VRF Oracle activity

What is a good way to fund a project that implements a function that pulls chainlink VRF data for random number generation? I don't want the function to stop working because of no more funds left, ...
0
votes
1answer
19 views

How can I log text (and see the logs)

I'm writing a contract using remix, and I'm hitting an error but I can't debug it. When I enter the transaction hash in remix it tells me the json is empty (""). I'm testing on the ropsten ...
0
votes
1answer
40 views

Why this delegatecall attack not working?

I am confused by this simple contract. The main purpose is to bypass the OnlyContract() modifier. Victim contract. pragma solidity 0.7.6; contract Victim { modifier OnlyContract() { ...
0
votes
0answers
113 views

test return value of transaction

contractA function test() internal { stateVariable = 20; uint num = 20; assembly { mstore(0x00, num) return(0x00, 0x20) } } How do I test the return ? I am using hardhat , but i don'...
0
votes
0answers
129 views

How to implement crypto refunds in a smart contract?

I am quite new to cryptocurrencies and after some investigation I thought this might be the right place to ask. Problem: I have a small business and I would like to offer to my customers the option to ...
0
votes
1answer
25 views

What is the legitimate use case of using library contract without using contract address?

Let us look at the following contract contract LibraryA { function getSenderAddress() public returns (address); } contract LibraryB { function getSenderAddress() public returns (address);...
0
votes
0answers
22 views

How to create a smart contract which hold different erc20 tokens or ETH?

I want to make a simple smart contract. where any user can send ETH (or any ERC20 token) to the smart contract. but how to keep track of every token, their weight in the smart contract, and the ...
0
votes
0answers
16 views

Saving gas on large amount of token distribution

I was wondering if this function is safe to use? is there any way to reentrancy or cause arithmetic issues? function sendBatchCS(address[] _recipients, uint[] _values) external returns (bool) { ...
0
votes
0answers
44 views

ERC165 - why is it a good idea?

I am trying to understand ERC165. Let's say we have a contract - contractB and we have a contract contractA. I think, what this ERC says is that before contractA can call the contractB's function, it ...
0
votes
0answers
26 views

Are there any simple, simulated smart contracts to try out?

The barriers to buy, sell and trade cryptocurrencies are fairly low. Anyone can try it now. But very few of the same people can say that they've ever tried to enter into a smart contract. Are there ...
0
votes
0answers
23 views

estimating gas costs for dapps

I am new to ethereum and I am trying to build something like a vault where you can withdraw and deposit assets, based on the dApps protocols you are using (e.g :- yEarn, aave). I know there will be ...
0
votes
0answers
17 views

why can I specify `memory` if function is internal?

In the latest compiler versions, we can do the following: function balanceOf(uint[5] memory data) external view returns (uint256) { Until some version of the compiler, i couldn't specify memory, ...
0
votes
0answers
37 views

how does calldata not work in this case?

pragma solidity ^0.7.4; contract D { function test2(uint[1] calldata good) external { uint c = good[0]; } } This code is perfectly valid. What I do is deploy ...
0
votes
0answers
15 views

what's the difference between assembly part and opcode part in remix?

In the remix, there's compilations details button. When you click, one can see Bytecode and also assembly parts. Bytecode is an object which has object key and opcodes key in it. As far as I can see, ...
0
votes
0answers
24 views

ethereum solidity - gas cost wrong

This is bugging me so much time and spent hours and hours on this, I'd really appreciate your help so much.... // this costs 21394 function test2() external { } // this costs 21507 function ...
0
votes
0answers
27 views

Smart contract for selling log-in subscription service

If not ethereum, which smart contract token would be best suited for fulfilling the sale of a month-long anonaymous subscription for cryptocurrency that enables the buyer to have their own username ...
0
votes
0answers
27 views

how do i call a constructor from another constructor?

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/token/ERC20/ERC20.sol"; contract MyToken is ERC20 { constructor(uint supply) public { // ...
0
votes
1answer
27 views

Returning a dynamic array of structs

I'm trying to return a dynamic array of structs created on the fly from storage data, similar to how we return ViewModel from DB data in MVC. What is the best way of doing it in Solidity? Tried ...
0
votes
0answers
61 views

Is it possible to execute a smart-contract function at the next (or other block) number?

I simply need a function to be executed not at the block number when the function is initiated but to wait for any of the next block numbers. I can do this with a require, where person executes the ...
0
votes
1answer
33 views

when do smart contract wallets need to sign transaction by themselves?

Do smart contract wallets ever store priv/pub keys or something ? Of course, It would be then seen on the blockchain if it did, but I am asking this because somewhere, I've read that sometimes smart ...
0
votes
0answers
35 views

wallet and smart contract connection

I am just here to make sure that i understand what smart contract wallet and what wallet means. These 2 guesses of mine are highly related so what my question is simple. Am I right about assuming the ...
0
votes
0answers
17 views

parity hack - how does this work?

I am looking at the following contract https://eips.ethereum.org/EIPS/eip-1822#erc-20-token Look at the following line : Ensures no one can manipulate the Logic Contract. IMPORTANT: I am going to ...
0
votes
0answers
23 views

How to manage transactions by an Admin in an ethereum based private network?

I am implementing a private blockchain with the Ethereum based solution Hyperledger Besu. One thing I would like to do is: Allow someone to create a transaction. This transaction is only sent if the ...
0
votes
0answers
15 views

Use new to generate an instance of a sub-contract in a smart contract

When we write a smart contract, we can use the keyword new in the code to generate an instance of a sub-contract. I want to know whether the instance of this sub-contract has an address, and can ...
0
votes
0answers
36 views

store data in any slot

contract test { bytes32 private constant ownerSlot = keccak256("ownerSlot"); constructor(address _implementation) public { bytes32 s = ownerSlot; assembly { ...
0
votes
0answers
19 views

estimateGas - how does it work when there's an internal call?

I've read the following: The catch about gas estimation is that the node will try out your tx with different gas values, and return the lowest one for which your tx doesn't fail. But it only looks at ...
0
votes
0answers
23 views

erc20 and tokensale how to use interface

I have ERC20 interface copied from here link - zeppelin Now, I have a contract called ERC20 which looks like this: contract ERC20Token is IERC20 { uint8 public decimals = 18; // other ...
0
votes
0answers
74 views

Mint ERC-1155 Token with user defined variables

I would like to allow users to change the property of their items. Let it be the color. In my understanding though there is no way of changing the property of an already minted erc-1155 token. ...
0
votes
1answer
18 views

Trying to do interaction between 2 contracts. But compilation failure showing should be declared Abstract

WinCon.sol EnemyCon.sol To create interaction, I am creating interface for EnemyCon in WinCon.sol, but Remix is throwing compilation error stating "EnemyCon should be marked abstract". I ...
0
votes
1answer
42 views

An attack to my contract similar to ERC-20 approval() exploit

I have function setNonRecurringFlow(uint256 _child, int256 _remainingSwapCredit) external; function setRecurringFlow( uint256 _child, int256 _maxSwapCredit, int256 ...
0
votes
0answers
105 views

solidity call function how gas gets forwarded

It's said that: someAddress.call.value(y)() will send the provided ether and trigger code execution. The executed code is given all available gas for execution making this type of value transfer ...
0
votes
1answer
38 views

Is calling another contract via its address risky?

The below screenshot is from Andreas' book. I don't understand why this programming technique is so risky. See the text in the red block in the image. We have the .sol file, and the Bytecode on the ...
0
votes
1answer
27 views

why separate assignments are better than single?

I've read that: It is more gas efficient to initialize a tightly packed struct with separate assignments instead of a single assignment. Separate assignments makes it easier for the optimizer to ...
0
votes
1answer
31 views

constructor input arguments or hardcoded values? best practice

What is the rationale for choosing to use constructor input arguments over hardcoded values? and what is best practice?
0
votes
1answer
192 views

Prevent Transfer of ERC20 token to contract address?

I want my ERC20 contract to be transferred to EOA addresses only and some specific contract address only. I don't want to lose my tokens by mistakenly transferring to a contract address that cannot ...
0
votes
1answer
34 views

Car Traceability

I want to deploy a smart contract for tracing cars. For example, say I am producing 10 cars Now what I want is to create a smart contract for tracing cars. So my smart contract will have three ...
0
votes
0answers
22 views

What is the difference in the two mapping structures

Is the below mapping structure a legit way to create a restricted mapping, or is the latter best practice? mapping(address => SomeStruct)[5] private structs; and mapping(address => mapping(...
0
votes
0answers
41 views

hardening infinite loops

What is the best way to 'harden' an infinite loop, if you are in a scenario where you would find it necessary to iterate over an array, would it be a best practice to put an assert condition in ...
0
votes
1answer
211 views

How do I count the elements of an array in solidity?

In my project, I want to count the elements of an array as follows: struct Server{ uint sernum; uint num; uint data; } Server [] public datta; function ...
0
votes
1answer
33 views

zero-initialisation of storage values in constructor or gas optimization

is it better to pay extra gas to initialise storage variables that are empty as zeroes in the constructor, or save the gas since the default is zero?
0
votes
0answers
82 views

Unbounded loop solidity internals

Under the hood, what happens in an unbounded loop? let's say I'm trying to send tokens to an infinite amount of addresses and end up with an out of gas error. Will the function which executes the ...
0
votes
0answers
24 views

Can I make a delegatecall to a Solidity contract that is compiled with a higher compiler version?

Lets say that I have the contracts A and B. A needs to make a delegatecall to B. A is (for some reason) compiled with a compiler version that is lower than B's compiler version. Can I safely assume ...
0
votes
0answers
36 views

Deliver a dapp to a client, how to set as owner?

So, as a freelancer that wants to make a smart contract for a client, how do you set such client as the owner of the contract? Would it be setting the owner variable to the eth address of the client, ...
0
votes
1answer
127 views

Deleting an array in storage (>= 0.6.0)

I need to add elements to a resizable myArray and then delete the myArray. I don't know what the length of myArray will be before the loop, and it's not possible to resize a memory array; that leaves ...
0
votes
1answer
26 views

When using mapping, why use an address over bytes32?

From an end user standpoint, they will never want to use the address for searching for mapped data when they could just submit a username for function parameters, so is there any specific reason why ...
0
votes
0answers
49 views

Compile error. Fallback function error

I use pragma 0.6.2. I am trying copile in truffle code which contain this lines: fallback() external payable{} I an getting error: The payable fallback function is defined here. fallback() external ...
0
votes
0answers
296 views

How do i withdraw Eth from a contract i created

New to blockchain.. havent a clue.. I managed to create a new contract with Eth. I moved money from MyEtherum Wallet to Metamask and into a contract, somehow? I have no coding experience but need ...

1
3 4
5
6 7