Hot answers tagged

6

Guys I really hate my life. It took me over 10 hours to find the solution to this problem. I compiled the contract with various different methods. Deployment worked with each of the but the contract couldn't be verified nontheless. After a while I figured out that I didn't set the optimisation checkbox on etherscan to "yes". I was compiling optimized all ...


5

I deployed the contract on the Kovan test net. Deployment versions same as you. Everything worked properly. I see no reason for it not to work on Ropsten. How did you deploy the contract? Maybe share the address to I can try to verify it.


4

you can make use of abi.encodePacked function function random() private view returns(uint){ uint source = block.difficulty + now; return uint(keccak256(abi.encodePacked(source))); }


4

It seems like you treated "315f6b6f74000000000000000000000000000000000000000000000000000000" like a string instead of the hexadecimal byte sequence it actually is. Via web3 0.2.x: web3.sha3('315f6b6f74000000000000000000000000000000000000000000000000000000') > "0x90a0076f07f9884805bdc4d668c55756ff42238a0ad7b824b8a267783e822544" web3.sha3('...


4

This seems to be working. But you can test it out on your own with your specific use-case in remix.


4

You need to choose the right compiler version. On the right sidebar you can see your current compiler version. The compiler version must match the number used in the pragma solidity! Expand the dropdown and choose 0.5.12 nightly. You should probably downgrade to a full commit version like 0.5.11 commit. I hope this helps!


4

A reverted transaction generally means that the logic of the smart contract being used failed or there's not enough gas to complete the transaction. The transaction was still executed by the miner, and any gas used prior to the transaction being reverted needs to be paid for. Based on this, the reverted transaction is still mined and included into the block ...


4

Ethereum transactions follow a certain low-level structure: from: address (signed by this) to: address value: uint (ether) data: message data bytes The first four bytes of data are a function selector, where the selector is derived from a hash of the function name (source code) and arguments, truncated to four bytes. After that comes the arguments. That's ...


3

The reason you are getting that error is because num is of type uint8, and the sub() function of SafeMath is looking for type uint256. Additionally you declare using SafeMath for uint;, which confirms that it only works with uint256 (as uint is an alias for uint256). There are two ways to fix it: 1) Make num a uint256 type. Your code would look as follows: ...


3

Answer by Rob Hitchens - B9lab worked! I did face an error due to difference in version.In case you are using solidity version > 0.5.0, some changes that were required: pragma solidity ^0.5.0; contract HelloWorld { string saySomething; constructor() public { saySomething = "Hello World!"; } function speak() public view returns(...


3

As per your code, the owner of your contract is the Account Address with which you deploy the contract on the network: constructor() public { owner = msg.sender; ////For eg. 0xca35b7d915458ef540ade6068dfe2f44e8fa733c -> JS VM } Now since the transferOwnership() function call uses the modifier "onlyOwner", it mandates msg.sender for this transaction ...


3

It seems that Remix does this automatically. Library code: pragma solidity ^0.5.10; library Foo { struct F { uint256 x; } function foo (F storage f) external { f.x = 123456789; } } Main contract code: pragma solidity ^0.5.10; import './Foo.sol'; contract Bar { Foo.F public f; function bar () public { ...


3

Update: I am able to deploy my contract using solidity ^0.5.0 but higher versions does not work. Is your private network using the Constantinople EVM? If you can deploy 0.5.0 but not 0.5.7, you might be on Byzantium. In Remix, on the compiler tab, try changing the EVM version from "compiler default" to "Byzantium" and see if you're able to deploy ...


3

When you use the call function, you can control the returned success condition as a bool and check if the call succeed or not. function approveAndCall(address payable _spender, uint256 _value, bytes memory _data) public payable returns (bool) { require(_spender != address(this)); this.approve(_spender, _value); (bool success, ) = ...


3

This seems to be a remix bug. When you deploy it using web3 or so it should work properly. Everything should be fine. As the other answer stated you can bypass this problem.


3

Just use this: npm install web3


3

Think of your VM like a completely different machine. It has another IP for example. 127.0.0.1 accesses localhost and therefore your host machine. So how do you fix this? You need to connect to your VM with the correct IP. Go into your VM and run the command ifconfig. A lot of stuff gets returned. You will surely recognice the correct IP when you see it. ...


3

Two options: Change memory to storage, otherwise you're just creating a local Document object rather than referencing your documents mapping. Declare Document memory document at the beginning of the function, then initialize the fields of this object (as you are already doing), and finally set documents[_hash] = document at the end of the function.


3

This error is well known and the developer team is working on it in order to understand it better and fix. Go on the gitter channel dedicated to remix and you will find the discussion on going about it.


3

Getting started​ with Ethereum http://ethereum.org/beginners/​ https://docs.ethhub.io/ethereum-basics/what-is-ethereum/ Start developing https://cryptozombies.io/​ https://www.trufflesuite.com/tutorials/pet-shop​ https://ethernaut.openzeppelin.com/ (advanced)​ Smart Contract best practices - https://consensys.github.io/smart-contract-best-practices/ ...


3

It's not clear if you want to retrieve all the values in a mapping or use the mapping to store structures that contain interesting, multipart things. No to the first interpretation. Yes to the second. Lay out an instance (for one key) in a struct. Map the structs to the keys. struct MyStruct { uint part1; bool part2; ... } mapping(uint => ...


3

There is no limit on the number of blocks. It's possible there is an error in your contract or web3.js code which is only manifesting after a number of iterations. Also, make sure you're still passing the correct parameters to your contract. If I search for that error message "BigNumber Error: new BigNumber() not a base 16 number", then I can find a number ...


3

All you need to do is have the selfdestruct(address payable recipient) function. selfdestruct takes a single parameter that sends all ETH in the contract to that address. In your case, you can do: function finalize() public creatorOnly biddingClosedOnly { selfdestruct(_creator); } From the docs: selfdestruct(address payable recipient): destroy the ...


2

[ethjs-rpc] rpc error with payload in Solidity 0.5.0 happens if the passed parameters to the contract is empty, hence from DApp console log all parameters and see if any values are being passed as empty or null. Once you address the empty values to some concrete values rpc error will go way and transaction will be success.


2

pragma solidity '0.5.11'; contract Hello { string public productname='Hello World'; function setname (string memory name1) public { productname = name1; } function getname () public view returns (string memory) { return productname; } }


2

Interface support is advertised using ERC-165. This is documented in https://eips.ethereum.org/EIPS/eip-165 There are two cases where this is useful and these reasons motivated adding the feature as a requirement for all ERC-721 contracts: 1) Allowing off-chain entities (wallets, block explorers, Web3 clients) to recognize abilities of a contract. For ...


2

The fact that it gives the error Note: The constructor should be payable if you send value. is a bug. It obviously shouldn't give that error since you're not even executing a constructor when calling transferOwnership. Misc extra info: Prior to the Byzantium hard fork, there was no REVERT opcode. If a require failed, it would always consume all the gas.


2

It is hex ff (at the end), left padded with 31 0x0 to make a word. It's the first 32-byte word (0). In decimal, the value is 255. Hope it helps.


2

I voted for Jesse's answer. For the benefit of others who come across this, a little example of the last option mentioned: contract A { function someMethod(address sender) public{ // Something happens here // proceed using "sender" the msg.sender says the transaction is for. } } contract B { A instance = new A(); ...


Only top voted, non community-wiki answers of a minimum length are eligible