New answers tagged

1

You didn't explain the periodicity and other details. Is the membership fixed or do they come and go? Does the contract continue to gain/lose on operations, or is this a wrap-up and final settlement? In the simplest case I can think of, all members join (deposit), then things happen, then you establish the entitlement of each member at a point in time and ...


0

pragma solidity ^0.5.0; contract Product { Factory public factory; Product public x; constructor(Product _reference, Factory _factory) public{ x = _reference; factory = _factory; } function haveFactoryCreateProductWithReferenceToThis() public { emit ProductCreated(factory.createNewProduct(this)); } event ProductCreated(Product indexed ...


0

If you can possibly avoid doing a sort in a contract, that is probably what you should do. This might give you some ideas about how to avoid it: https://blog.b9lab.com/the-joy-of-minimalism-in-smart-contract-design-2303010c8b09 There are cases where a contract needs access to a sorted list. You have to think about the maximum possible size of the set and ...


1

You can avoid padding the bytes array with 0's with the toBytes implementations by determining the scriptNumSize function scriptNumSize(uint256 i) public view returns (uint256) { if (i > 0x7fffffff) { return 5; } else if (i > 0x7fffff ) { return 4; } else if (i > 0x7fff ) { return 3; } else if (i > 0x7f ) { return 2;...


1

goodvibration's answer is correct, but just to expand a bit: When you use mapping(address => Cookie[]) cookie; what you are getting is a multidimensional array, in a way. There's a "list" of addresses (the mapping) and each address has a list of Cookies (the array Cookies[]). Then, when a user sends a Cookie to the CookieJar, instead of setting the ...


1

The main constraint to keep in mind is you want to always organize things so you can complete the needed operations with functions of O(1) complexity, so they will have a consistent gas cost at any scale. In practical terms, avoid unbounded for loops and recursion (The stack depth limit will probably "get you" before it runs out of gas). The naive way is ...


0

From the Solidity documentation on dynamic arrays: Arrays have a length member that contains their number of elements. The length of memory arrays is fixed (but dynamic, i.e. it can depend on runtime parameters) once they are created. For dynamically-sized arrays (only available for storage), this member can be assigned to resize the array. and on the ...


0

To do this you'll need to make use of Solidity's experimental ABI encoder, like so: pragma solidity ^0.5.1; pragma experimental ABIEncoderV2; ... You can then create a getter function that returns an array of structs: function getChapterByBook(bytes32 memory _bookID) public view returns( ChapterData[] memory chapters ){ return books[_bookID]....


1

First you need the reference of the book and then you can get one chapters by passing the index of it (uint256 chapter). Try with this: pragma solidity ^0.5.0; contract NewBook { struct ChapterData { // string chapterID; string title; string color; uint pages; } struct BookData { // string bookID; ...


0

Try define the voting contract as follow: contract voting is admingroup { } You may have used different names, but this ensures that the admingroup contract is kind of like a base contract which voting is built on. This will carry over the array. Just make sure you write the code on the same contract page using remix and first deploy the admin contract ...


1

Try this: pragma solidity 0.5.1; contract NewBook { struct ChapterData { // string chapterID; string title; uint pages; } struct BookData { // string bookID; ChapterData[] chapters; } mapping(bytes32 => BookData) books; // bookId => BookData //This is where the problem occurs, how do ...


0

Yes, this is possible. Below is a smart contract code which is similar to your requirements. In this code, a user sends an integer value with the function call to the smart contract and based on the value sent the smart contract function returns a message. pragma solidity ^0.4.24; contract Test { uint256 x; string message; function check(...


0

Like many words in crypto (e.g. wallet), the term token has several distinct definitions, mostly depending on context. Token: usually short for ERC20 token on the Ethereum mainnet. Token (or replaced by token name or symbol): unit used by smart contracts for accounting (smart contracts work on integers, so there can't be any decimals). Think of it as the ...


1

It will be very difficult. I'll break it down into a few separate concerns. The first is just general programming. You need need numbers in the range of 0-99 to to pick people out of the array. Let us set the "randomness" concern aside for now and focus on scaling a uint. Let us suppose the uint to start with could be anything, so somewhere in the range ...


1

Yes, it does. To the EVM, setting a bool to false is equivalent to setting a uint to 0 in that it clears a storage slot. You can try it out with the code below. In this contract, the following transaction costs are: setBool() = 41705 setUint() = 41474 unsetBool() = 13386 unsetUint() = 13204 pragma solidity ^0.5.10; contract RefundTest { bool ...


0

I assign the same ID to a new block You don't assign storage/state to blocks. Blocks are only for ordering transactions that (may) change the state. The state itself is persistent. So, student[ID].passed is whatever you set it to previously, false by default. You probably need a more intricate data layout but I don't want to stray too far from the ...


2

There are two main reasons. To minimize contract size To ensure compliance If you make the smallest possible contract and use Augor.sol, then your contract will be at least as big as Augor.sol. contract Mine { Augor a; } You have defined a as an instance of Augor and that means all of the Augor bytecode is rolled up into yours. It's not evaluated for ...


1

Because often when you're writing contracts which interact with other contracts, the internal workings of those contracts are not relevant, just the externally exposed functions. By providing an Interface, other developers can write code that interacts perfectly with yours, without needing to see/include your entire codebase.


0

BTCRelay works as Bitcoin light client (SPV): https://en.bitcoinwiki.org/wiki/Simplified_Payment_Verification That's why I like Nakamoto-like consensuses: even smart contract can be a light client of this chain.


0

I think you have two general categories of problems to think about. Let's call them on-chain and off-chain, for now. There might be a better classification. With care, yes, you can obfuscate the votes with a commit/reveal pattern so no one can know what the votes are until all the votes are collected. That won't even hide who voted unless you go to a lot ...


2

From the docs: .selector returns the ABI function selector. The first four bytes of the call data for a function call specifies the function to be called. It is the first (left, high-order in big-endian) four bytes of the Keccak-256 (SHA-3) hash of the signature of the function. The signature is defined as the canonical expression of the basic ...


1

Try this out. pragma solidity > 0.5.1; contract Test { function test() public view returns (string memory) { return addressToString(address(this)); } function addressToString(address _addr) public pure returns(string memory) { bytes32 value = bytes32(uint256(_addr)); bytes ...


1

To manually test the MinterRole you need to change the account you are sending the transaction from. e.g. accounts[0] has the MinterRole, accounts[1] does not have the MinterRole so reverts when you attempt to mint. truffle(develop)> accounts = await web3.eth.getAccounts() truffle(develop)> token.mint(accounts[9], "10000000000000000000", {from:...


1

I cannot understand why the user would need or want to send ETH along when requesting a refund. This also means your resell function should not be payable. Now, to answer the question (even though it is very old, might still help someone), there are several possible causes to this reject, from the code your showed: You should not convert the wei amount to ...


2

Yes, you can use it. From the docs: The operators || and && apply the common short-circuiting rules. This means that in the expression f(x) || g(y), if f(x) evaluates to true, g(y) will not be evaluated even if it may have side-effects. Try with this code: pragma solidity ^0.5.0; contract Test { function comparePoints (uint ...


1

As the code says, you need to insert your address here (without "<>"). I've used one of Remix: // Add your wallet address here which will contain your total token supply treasury = address(0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c);


0

The shortest solution I discovered after several tries: uint length = uint(uint8(arr[i]));


0

Not an expert on web3j here, but you are trying to invoke something called contract.createRecord() when the function in the contract is called ...createChild(). The contract itself can't compile because you have a contract, Record, nested in a contract. It should look like: contract Child { // stuff } contract Parent { address[] public registry; ...


0

Read the top of the ERC20Mintable.sol file (which you have linked at the top of your own question): contract ERC20Mintable is ERC20, MinterRole ... Contract ERC20Mintable IS MinterRole (in contrast with HAS MinterRole). This mean that ERC20Mintable inherits all the (non-private) functions and variables of MinterRole. Hence you should call the function ...


0

the problem is my get function takes a parameter just modify this : var getUserFunction = function(cb,_contractAddress = contractAddress, _jsonFile = JSONFile){ var abi = JSONFile.abi; var contract = new web3.eth.Contract(abi,_contractAddress); contract.methods.getUser('0xF15372bcF1FdD963Ea5514Dc96432Da8e795A8de').call().then(function(_data){ cb(...


2

Storing anything secret on the blockchain is difficult. Whatever you store is visible for everyone. You can store data in an encrypted format but then you can't store the encryption key in the blockchain as everyone would have access to it. So you'd need to distribute it to those who need it outside the blockchain. The kind of access based restrictions you ...


3

It would be faster (and cheaper) to use addManyUsers(). In terms of speed, the blockchain processes transactions of all complexity at the same time (each block). What should be of concern to you is the cost of gas and the number of transactions being sent. When determining the best option from a choice of transactions, you should consider the total gas ...


1

This error refers to the bad formatting of Doxygen tags within DocString comments (commonly known as NatSpec Format comments). If you do not format these tags value correctly, the Solidity compiler " moans " and does not compile (even if the rest of the code is correct unfortunately !). Solving your problem NB: Your question is really old and I couldn't ...


0

First of all, int16 is just 2 bytes wide (16 bit), not 16 bytes. Did you mean int128? Second, you still may pack/unpack two int16 values into single bytes32 in Solidity 0.5.x, you just need a bit more type casts: function pack (int16 a, int16 b) public pure returns (bytes32) { return bytes32 (bytes2 (a)) >> 16 | bytes2 (b); } function unpack (...


0

The behavior changed in Solidity 0.5.x. Conversions between bytesX and uintY of different size are now disallowed due to bytesX padding on the right and uintY padding on the left which may cause unexpected conversion results. The size must now be adjusted within the type before the conversion. For example, you can convert a bytes4 (4 bytes) to a ...


0

The problem is most probably with gas limit. How did you calculate it? When transaction has some data attached, e.g. contract's method selector and parameters, zero bytes cost less than non-zero. So, transaction that sends tokens to 0x0011223344556677889900112233445566778899 will cost less than transaction, that send the same number of tokens to ...


1

As you mentioned, ABIEncoderV2 is currently in experimental state. This means that the creators do not vouch for its use in production. Additionally, there have been two critical bugs(1, 2) found in Solidity surrounding ABIEncoderV2 within the last 3 months (at the time of writing), one being just 4 days ago. Finally, auditing firms such as Zeppelin have ...


1

At Blend, we used ZeppelinOS to make our regular Ethereum smart contracts upgradable. Here is our step-by-step guide and sample code.


1

Solution to your 1st question You can do something like this function getCampaigns(int start, int end) public returns(Campaign[] memory) { for(int i = start ; i < end && end <= deployedCampaigns.length; i++) { Campaign.push(deployedCampaigns[i]) } return } Solution to your 2nd question You can get the ...


1

Yes, the gas will be paid for by you, the sender of the transaction. The gas will not be taken from the contract.


1

You can refer to this link to solve your doubts. Listen to events using web.js


2

The EVM bytecode (compiled form) is available/observable to all users at all times. The data in contract states, including variables explicitly marked private, is available/observable to all users at all times. private describes visibility to other contracts but it is a misunderstanding to assume it implies protection for confidential information. ...


0

Strictly speaking, there is no such thing as a transaction sent from smart contract. Every valid transaction has to be signed by some private key, and address, derived from this private key, becomes from address of the transaction. As long as smart contract addresses are not derived from private keys, there could not be any transactions originating from ...


0

BCD contract has already been deployed. I don't have access to its transfer function. Can you help how to set up an offchain watcher, and implement it's findings in ABC transfer function. Also, there won't be any newly minted ABC, coins will be sent from contract owner address.


1

You do not need to explicitly state the second variable declaration. You can write it as follows: (bool success, ) = king.call.value(compensation)(""); require(success);


1

You are getting a reversion because a call returns two values and you are treating it as one. When performing king.call.value(compensation)(""), what you actually receive back is the success bool and the bytes response. As it stands, you are trying to check for the bool value, but ignoring the fact that it also returns a response. Your code should look as ...


3

Try with this: pragma solidity ^0.5.1; contract MKotET1_12{ address payable king; uint public claimPrice = 100; function calculateCompensation() public returns(uint) {} function() external payable { if (msg.value < claimPrice) revert(); uint compensation = calculateCompensation(); (bool success, ) = king....


0

Yes, you can do this. There are two ways to do it: 1) In the transfer function of BCD token, you would check if the transfer is send to the particular erc20 address in question. If the transfer is being made to the desired address, you would call the mint function on ABC token and mint these tokens in the same transaction. The code would look something like:...


0

So, after a lot of guessing and trying, I experimented switching geth and solc versions. I did that because I remember doing these stuff last year, and didn't have to go through so much hassle. In the end, only switching solc version was enough. I replaced my solc version and repeated everything I had previously done, exactly the same way, and it worked. I ...


0

The problem is: structA tempStructA; is declared (implicitly) as an uninitialized storage pointer. It's uninitialized because there is no right side expression, e.g. = structAs[index];. It's storage because memory wasn't explicitly declared with structA memory tempStructA; So, we have a structA starting in storage slot 0 which means the variables are laid ...


Top 50 recent answers are included