Questions tagged [contract-design]

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

347 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1
vote
0answers
153 views

Tutorials on how to make generative NFT on the Ethereum blockchain using Blender 3D

I’m looking for a tutorial that covers how to create generative art for the Ethereum blockchain using Blender 3D. I’ve only been able to find the coding portions but no tutorials on how to implement ...
1
vote
1answer
17 views

Do contract size increase with gas in block?

I'm trying to deploy a contract with REMIX but it throw an error "smart contract too large, not enough gas". Is REMIX hardcoded for contract size ? Do smart contract size increase with ...
1
vote
0answers
21 views

What is the meaning of decentralization?

In persuit to understand blockhain decentralization: If I am not wrong, it helps prevent control with one entity. Consider a hypothetical example of a service which takes a string and returns a ...
1
vote
1answer
42 views

Untitleded.sol:5:77: ParserError: Expected type name function sendmessage(string message) view public returns(string message, memory) { ^----^(i need)

I've seen the other StackExchange errors but it didn't help me. Untitleded.sol:5:77: ParserError: Expected type name function sendmessage(string message) view public returns(string message, memory) { ...
1
vote
0answers
54 views

how to decode/encode ipfs for contracts

It's known that IPFS can use 2 types of CID, v0 and v1. In my contract, I let users store bytes data parameter. They can store some simple text on it or even pass the ipfs hash. This question is about ...
1
vote
0answers
21 views

ERC1155 minter function

im working on a ERC1155 token. as you may know openzeppelin has a presetMinter for it, but i want to mint my token with more complex things. i see 3 methods to do it: 1- without using presetMinter ...
1
vote
0answers
7 views

How did the CryptoKitties contracts update, given that contracts are immutable?

How did the CryptoKitties contracts update? There were CryptoKitties bounty programs which suggests that the contracts changed over time in order to address issues. How? I peeked at the sources for ...
1
vote
0answers
33 views

Smart contract copying code beyong code length

I've seen a couple smart contracts (eg the contract decompiled in this answer) use this pattern: Code[Code.Length:Code.Length+x] This surprised me because I would expect Code.Length to mark the end of ...
1
vote
0answers
20 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
0answers
23 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; ...
1
vote
0answers
28 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
14 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
26 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 ...
1
vote
1answer
22 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?
1
vote
0answers
101 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
25 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 ...
1
vote
0answers
17 views

what does link mean in truffle?

I saw the following : what does `deploy.link` exactly do in `truffle` I have safe.sol library safe { function safeMultiply(uint256 a, uint256 b) internal pure returns (uint256) { if (a ...
1
vote
1answer
40 views

Fungible tokens owned by non-fungible tokens

I'm quite a Noob when it comes to smart contracts, and I'm trying to design a market place. I will tokenise existing real world assets into ERC 721 tokens. The owner of each ERC721 will be eligible to ...
1
vote
0answers
60 views

copy array from storage to memory

uint[2] testStorage; function assemblyStorage() public returns (uint a, uint b){ testStorage[0] = 5; testStorage[1] = 10; uint[2] memory testMemory = testStorage; ...
1
vote
0answers
23 views

why do i have to specify memory in arguments?

My function body looks like this: function element(uint a, uint b, uint[2] memory c) public returns(uint e, uint f, uint g, uint k) { I am wondering why do I put memory keyword before c ? I know that ...
1
vote
0answers
27 views

why mload(0) returns wrong number?

int x; // Storage slot #0 mapping (uint => uint) y; // Storage slot #1 uint [] z; // Storage slot #2 function element() public returns (uint a, uint b, uint c) { z.push(45);...
1
vote
0answers
80 views

how do storage and memory variable work?

So, in an ordinary programming language, we have stack and heap. Reference types such as array gets stored in heap. and the variable which holds the address(pointer) of this array is stored in stack.. ...
1
vote
1answer
35 views

Explicitly conversion of addres and payable

i can't understand this Explicit conversions to and from address are permitted for integers, integer literals, contact types and bytes20. However, Solidity prevents the conversions of address payable(...
1
vote
0answers
34 views

function overloads when the function is payable

I'm calling a function from another contract using an interface. The called function is payable and also overloaded. Example: contract OverloadedContract { function foo(uint x) external payable ...
1
vote
1answer
22 views

Puzzle- how to implement simple savings pool (via cDai) without iterating over unbounded loops?

Consider this example of a very simple savings contract, where users send Dai, which the contract converts to cDai. At any time users are free to withdraw their share of the accrued interest. I cannot ...
1
vote
1answer
47 views

Storing name values off-chain in events and web3.js

Somewhere I read the advice to store name (title, geographical name, people name, etc.) value off-chain in events. But if a value is stored in an event, is there an efficient way to retrieve its ...
1
vote
1answer
29 views

arrays and structs for function arguments

A lot of contracts and libraries with functions that use arrays and structs for arguments. Structs can themselves include arrays, structs and mappings. For example: function doSomething(MyStruct ...
1
vote
3answers
418 views

How do you implement a front-end contract with back-end functionality in Solidity?

How do you create a front end contract that calls a back end with the idea of being able to upgrade or change the back end contracts without having to redeploy the front end contracts?
1
vote
1answer
83 views

Error Handling on Contract Calls to Other Contracts

I'm trying to call a function from another contract and need a way to accommodate errors. Say contract A has the method getBalance: function getBalance(address x) public view ...
1
vote
0answers
84 views

Error: Operator << not compatible with types bytes1 and int_const 1 return b10 << 1;

I don't know how to correct the code of function 4 & 5. pragma solidity ^0.4.4; contract C { bytes1 b10 = 0x6c;// l-> 0110 1100 6c转换为10进制-》12*16^0+6*16^1=108 bytes1 b11 = 0x69; ...
1
vote
0answers
236 views

how can i translate the ethers.js “getSigner” utility to web3?

I have a web3 object but I'm working off an example that uses ethersProvider.getSigner(). Is there an equivalent (or mostly equivalent) in the web3 library? For reference, the ethersProvider is ...
1
vote
1answer
60 views

Using contract to create Child contracts (web3j Java wrapper)

I have a simple Parent contract that creates child contracts and stores their address. contract Parent { address[] public registry; function createChild () public { address newChild =...
1
vote
2answers
82 views

Storage/Retrieval of mapped structure data

I want to store the structure data in a mapping i.e. if I have a student structure as described below, then I should be able to have a myriad of students and distinguish between them using wallet ...
1
vote
1answer
70 views

Events in hub/factory contract

I have written a contract with the hub/factory pattern in which I need to capture the address of the contract that is being created, for this I am using events. Contract A Function A1 -- Call to ...
1
vote
1answer
2k views

Overflow/Underflow issues?

pragma solidity 0.5.1; contract basics{ using SafeMath for *; uint time; address payable sender; uint amount; event moneySent(address s,uint a); mapping(address=>person) ...
1
vote
1answer
27 views

Does etherum support smart contrast that has many subcontracts that can be executed once they are called by others

Can I have a main smart contrast that has many subcontracts that can be executed once they are called by other people? And the subcontracts can update the status of the main one if some conditions are ...
1
vote
1answer
34 views

Use Values Returned from One Function in Another

need a little help if you can spare the time. Making a little card game where people can collect "warrior" cards. We'll have an initial 12 master "cards" that supply the initial traits for the ...
1
vote
0answers
15 views

How the following scenario be achieved using smart contracts?

Assuming we have two parties (A & B). How the following scenario be achieved using smart contracts? User A will deposit some funds (x coins). user A can receive penalty funds from user B, So user ...
1
vote
0answers
18 views

Secuirty Token Escrow setllement

Is Esrcow could be applied in ST 20 tokens ? If yes, please guide for the same.
1
vote
0answers
44 views

Hardcoded Address

I did an audit on a smart contract and it says it has a hardcoded address. constructor() public { symbol = "0PUCKS"; name = "0 Pucks Token"; decimals = 18; ...
1
vote
1answer
32 views

Is it possible to have a contract run whenever a wallet address receives a transaction?

I'd like to build some code that monitors a wallet address, and performs an action whenever that wallet receives a transaction. I could do this with say javascript or whatever, but that doesn't offer ...
1
vote
0answers
61 views

state channel between smart contracts

In my scenario, there are data sellers and data buyers which might be persons or organizations. I would like to create a smart contract for data seller and another smart contract for data buyer where ...
1
vote
3answers
78 views

Cost-effective way to calculate final user balance based on variable events

Apologies for the title. I'm not sure what would be a more descriptive way to name this question. Assume there is a contract which has 3 potential parties. Buyers, sellers and shareholders. Buyers/...
1
vote
0answers
30 views

Is there a way for a smart contract to manage a codebase?

For example, could one set up a smart contract with governance protocols which could merge PR’s in a github repository? How might one govern open source via a smart contract? In a related vein, is ...
1
vote
1answer
93 views

Solidity/Remix Error: The constructor should be payable if you send value enum change state

I'm using this (State Machine) design pattern in solidity and having an error when changing the state after executing the first function. Any hint? Thank you! Error: revert The transaction has been ...
1
vote
0answers
394 views

Modifier to only allow access via staticcall

I'm trying to create a modifier that only allows a function to be called using staticcall. Using the view declaration in Solidity 0.5.0 guarantees that a function won't change state, but it still ...
1
vote
0answers
77 views

Smart contract design for gas refund

I'm designing a proxy smart contract that will be filled with eth by users so that anyone has an incentive to perform transactions useful to the user. I won't go into the detail of "usefulness" here. ...
1
vote
1answer
71 views

Insurance platform's and Ethereum smart contracts

I am trying to create a proof of concept for an insurance platform, a one that deals with risk and selling promises of coverage. A similar idea will be the car insurance platform's where you pay each ...
1
vote
1answer
173 views

Force two users to send the same amount of ether when starting a game

In my smart contract, I want the two participants to send the same amount of ether so they can start a game of rock, paper, scissors. How can I modify the sendEnoughCash() function do that? This is ...
1
vote
1answer
265 views

smart contract and private blockchain

I have some IoT(Internet of things) nodes sharing the received data from sensors with each others. I partitioned them to 2 private(permissioned) networks: Network 1 includes: X,Y,Z nodes trusting ...

1
2
3 4 5
7