Questions tagged [contract-design]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
36 views

Random distribution of large amount of NFT

I'm an beginner in solidity, and with a teamate we have a project for an NFT contract. I have a contract with 5000 NFT limite (cards, and 20 specific card form a familily, each family and cards are ...
0
votes
0answers
13 views

Change TUSD smart contract from legacy to current [closed]

I have a Qty of TUSD token which runs on ETH however it was in Coinbase and I forgot about it for a long time till now, the problem is that Coinbase has stopped supporting this token before the ...
2
votes
1answer
33 views

how do we use `commit/reveal` to count votes?

Let's say we are doing an election and it's easy to note that we need commit/reveal scheme to hide votes. So, we store hashes while users commit their votes. Now, let's say the election is over. How ...
1
vote
3answers
85 views

how does commit/reveal solve front-running?

I am trying to make sure I understand something correctly, so I will pose a problem with a solution. Problem: Let's say commit has been called. After this, we call the reveal. attacker listens to ...
0
votes
2answers
36 views

how can we stop front running for `approve` [duplicate]

function approve(address _spender, uint256 _value) returns (bool success) This is the ordinary ERC20 approval method. It's easy to figure out that we have a problem of front-running. Alice gives ...
1
vote
1answer
11 views

How to empty uint array after value is assigned?

Here is an uint array defined in smart contract: uint256[] public bidderItemID; And bidderItemID is assigned value in contract: bidderItemID = [1,2,3]; How can I empty bidderItemID after it is ...
0
votes
0answers
23 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
0answers
20 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
10 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
14 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) { ...
1
vote
0answers
17 views

ethereum makes extra space for no reason in memory

pragma solidity ^0.6.8; contract C { function test3(uint f) external returns(uint256[3] memory) { uint256[3] memory arr; arr[0] = 1; arr[1] = 2; arr[2] = 3; ...
1
vote
1answer
29 views

what does call stack of 1024 mean in solidity?

Assumption 1: If we create a local variable, call stack increases by 1, because we put this new local variable on the stack. if I create another local variable, it again increases by 1. So, with this ...
0
votes
0answers
11 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 ...
1
vote
0answers
22 views

scope of references to external smart contract, global variables, eleminiate redundant code

Imagine that there's a smart contract deployed which contains a number of sub-contracts like so: pragma solidity ^0.5.0; contract A { address contract = 0x6663130dDfF21E3BC963Ee902005223b9A202106; ...
0
votes
0answers
25 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
1answer
36 views

Solidity: Wrapping an ERC20 token inside of a new token

Is it possible to wrap and track a ERC20 token amount in another token? Would I need to use ERC-721 to do this? Let's say I send my ERC20 token to a specific smart contract which will wrap it in a new ...
1
vote
0answers
27 views

why does it copy into memory?

Let's say I have the following.. contract D { function again(uint256[3] memory bla) external returns(uint) { return bla[0]; } } contract A { function test(D f, ...
1
vote
0answers
10 views

why would I need to use `memory` in front-of parameter?

Let's say I have the following contract. contract D { function again(uint256[] memory bla) public returns(uint) { return bla[0]; } } contract A { function test(...
1
vote
0answers
19 views

How to implement variable interest rates efficiently

If a smart contract wants to pay interest on a balance of a user that's pretty much straight forward. You record the balance and the timestamp when a token was deposited and when the token is ...
0
votes
0answers
20 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 ...
1
vote
1answer
14 views

Several small or one big contract? (deloyment cost)

Does deploying several small contracts use more gas than deploying them as one, bigger contract with the same functions (that don't interact with each other)? How much is the difference?
0
votes
1answer
29 views

how does gas get taken from the account?

Let's say we call the function: function nice(uint a) public returns(uint256){ k = 100; z = 100; f = 100; require(a == 5); ...
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
20 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
9 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
17 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 ...
1
vote
1answer
17 views

Can I use an emoji as part of a string in Solidity?

Can I use an emoji in Solidity?
0
votes
0answers
14 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
1answer
21 views

selfdestruct: why am I able to execute the function containing selfdestruct(…) twice?

I have created the following contract with a destroy function invoking selfdestruct: pragma solidity >=0.5.0 < 0.7.0; contract Terminate{ function destroy() public { selfdestruct(msg....
1
vote
1answer
54 views

How much C++ is needed to write smart contracts?

Solidity seems to be written in C++ so does that mean that smart contracts require some level of C++ programming skills to get by? How much background knowledge is required for writing a simple one or ...
1
vote
1answer
25 views

Ethereum storage - how does this cost happen?

contract A { uint x = 10; function test2() public { x = 0; } } I can see that: Transaction cost is 13204 Execution cost is 5136 How can this be ? I ...
1
vote
0answers
51 views

Ethereum cost - how does it work in memory

This is really bugging me and doesn't seem any article that can help at all. wiki says further the gas costs for using memory: The fee for expanding memory is determined via a subtract-the-integrals ...
1
vote
1answer
19 views

what is expansion cost?

I am trying to understand what expansion cost is. We can see that there's this formula to count the memory cost - Now, It's also said that this formula doesn't include the expansion cost. Can anyone ...
3
votes
2answers
78 views

how can library change state?

I have Very Interesting cases about Libraries. CASE 1: I read the following in the official solidity docs: Library functions can only be called directly (i.e. without the use of DELEGATECALL) if they ...
0
votes
1answer
14 views

how does library end up in contract?

library C { function a() public returns (uint) { return 15; } } contract A { function a() public returns (uint) { return C.a(); } } This is the code I am using. I ...
0
votes
0answers
13 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
22 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 ...
1
vote
2answers
167 views

How two untrusted parties can make transactions without any involvement of the third-party?

I'm trying to create a contract where where PartyA and PartyB had to trade. PartyA sends money to a contract and PartyB sends goods to partyA. After partyA receives the goods it allows PartyB to ...
0
votes
1answer
20 views

Passing dynamic data to a contract

I'm trying to store records in a contract that are supposed to have an arbitrary number of fields. For example, one record would have "bitrate", another "ISBN" etc., in addition to ...
1
vote
1answer
31 views

Way to import library in a solidity smartcontract

I am studying smart contracts and I have looked at some popular projects on GithHub. I have seen imports like this: import "@openzeppelin/contracts/math/SafeMath.sol"; and like that: ...
0
votes
0answers
13 views

Is it possible to analyze transaction with a smart contract by inputting a transaction ID? [duplicate]

EDIT: Alright, this is a duplicate: Can a contract view the details of a transaction, given a transaction id? Edit2: answer is either to oraclize or do the API call to, for example, etherscan: https://...
0
votes
0answers
12 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 ...
1
vote
1answer
17 views

Before a transferFrom, is it better to check the allowance first?

transferFrom already checks the allowance, so does it make sense?
1
vote
1answer
47 views

What does scope do in the function itself?

Here is one of the functions I am curious about... function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external lock { require(amount0Out > 0 || amount1Out > 0, '...
1
vote
2answers
33 views

what's the difference between call and just using function?

Let's say I have a contract called contractA. It has the function: function bla(address test) { // way 1. test.call(abi.encodeWithSignature("first4bytes", arg1, arg2)) // way 2. ...
1
vote
1answer
18 views

In interface does the function listed have to be exactly the same as they are in contract?

In solidity 0.7.x, I am creating an interface of contract A in contract B to allow contract B call functions in contract A. contract A { function transfer(address recipient, uint256 amount) public ...
0
votes
1answer
37 views

How to disable/kill and get funds from a smart contract that I'm the owner?

I have a smart contract that is not being used anymore and still have funds. I would like to withdraw them and destruct or disable it. I didn't write the code but I'm the owner and the programmer ...
3
votes
1answer
21 views

What is the maximum size of string which we can store on solidity?

Is there a limit to the size of a string that we can store on the Ethereum blockchain?
1
vote
1answer
18 views

How to properly invalidate the manager?

In MyContract, I am providing special rights to the manager. But after some time and for some reason, I want to invalidate the manager. The following is my approach: // SPDX-License-Identifier: GPL-3....
1
vote
1answer
54 views

how to see contract that only has bytecode

I am looking at this contract - https://etherscan.io/address/0xf8681dad1ce4f1f414fb07fc07f81a3a82e91d8f#code but it turns out that there's only ByteCode and if I decompile it, the code it gives me is ...

1
2 3 4 5
35