The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

0

You deployed Hello three times. Your Test1 requires Hello.address passed into the function, so the next step is to copy Hello's address (clipboard icon) then use the drop-down box to select Test1 and deploy one of those. When the Test1 instance appears on the left, you'll see its Test() function wants an address. Paste Hello's address there. Hope it ...


1

You can enter them in the field next to the Deploy button, separated by commas. Or you can expand this field and you get individual fields for each parameter.


0

You don't have to use push with an array. You can add a new element modifying its length. Candidate[] public candidates; function addCandidate(string memory _name) public { uint idx = candidates.length; candidates.length += 1; candidates[idx].name = _name; } Another option is to use a mapping. You will need to keep the length separately. mapping (...


0

If you are somehow sure that the amount you want to burn is available in contract then just use .transfer() to transfer the ether to any other account. address(0).transfer(_amount); By the way this ether will be lost forever. If you send it to a known address, then at least it can be reused at later point. pragma solidity ^0.5.12; contract SillyContract { ...


2

The contract should try to send its funds but it will need to have some to begin with. You will have to send 1000000000 wei, or more when you deploy the deploy the contract. Any surplus will remain in the contract. I can't think of any good reason to do this so I'll refrain from suggesting improvements. Hope it helps. UPDATED WARN: I don't think anyone ...


0

Inside Purchase smart contract define counters for the total number of buyers and the total earnings like this: contract Purchase { uint public totalBuyers = 0; uint public totalEarnings = 0; ... } Then, when purchase is confirmed, increase these counters appropriately: function confrimReceived() public condition(msg.value == price) payable { ...


0

I solved the problem , contract need ether to work function2(in my case) , so ...this is the "Invaild opcode" solution.


0

Make Sure that you are calling function getTokenBalanceOf() after the call setToken() function. hope this will help you.


1

Yes, you do need to change function Contract (... to constructor(... because this is the new way to indicate the constructor. There is nothing else you need to do in the Factory to invoke the constructor. The constructor always runs one time on deployment, regardless of how the contract is deployed. It cannot be prevented/avoided even if you want to. In ...


2

You cannot assign it to a variable directly, you has to do it in a function or constructor Corrected Code: I had moved assignment operation to constructor pragma solidity ^0.5.1; contract MyContract{ struct student{ int RollNo; string Name; } student public s1=student({RollNo:1, Name:"Test Bunny"}); int public disint; ...


-1

Please check this Truffle console It allows call functions of smart contracts directly from your console.


0

Most ethereum nodes will put tx's from a particular address into a queue, with increasing unique nonces. tx's with larger nonces will not be sent as long as tx's with smaller nonces are pending. In the past, when I was able to run my own geth node and submit tx's to that, occasionally pending tx's would get stuck forever like you describe on mainnet or ...


0

It is probably because there are some array iterables which are going out of range. Invalid opcode error comes only in this case (For me though). New to blockchain and smart contracts!!! Correct me if I'm wrong.


0

(This is just an educated guess, to be 100% certain I'd need to see your entire contract and the series of calls leading up to the error) An INVALID opcode is raised when you attempt to access a storage location that hasn't been intialized. In this case, you are attempting to store data in a dynamic array emp at location emp.length-1. Because the length of ...


1

If you are sending the money to a contract, and not an account address, then the recipient contract must have a "fallback" function to be able to receive ETH. Fallback functions tend to look as follows: function() external payable {} though you can add logic within the fallback function if you wish. Using recipient.transfer(...) limits the transfer ...


0

As those both functions are in the same contract you simply have to call the other function inside deposit. Also if you want to receive Ethers with the deposit function it has to be marked payable. So something like this: pragma solidity ^0.5.0; contract MyContract { function deposit() payable external { // do some stuff ...


0

An address needs to be of type payable if you want to send Ethers into it. Looking at the answer here (and its comments): Member function "transfer" not found or not visible after argument-dependent lookup in contract? you can convert a regular address into address payable through uint160: Converting address to address payable is possible via ...


2

function Donations() private { This is not the same name as the contract, which would be the old style of constructor. If you rename to Donation(), the compiler will probably recognize you intend for this to be a constructor and warn you that the syntax should be changed to the new explicit form: constructor() public { There may be other issues, but your ...


1

I don't think so. So your options are: 1) Get by with less 2) Call separate functions to set more values. So in first function set 10 values and in another set another 10 values. 3) Combine data in different parameters into one by for example concatenating string. Note that it's expensive to split the string again into separate parameters.


1

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; } }


1

Javascript doesn't support polymorphism on the parameters when calling a function. With web3.js v1.xx you can specify the signature of the method you want to call. https://web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html#id12 myContract.methods['getDetails(string)'](..) o myContract.methods['getDetails(address)'](..)


Top 50 recent answers are included