New answers tagged

1

Currently, it is impossible to return struct in solidity. Though you can use experimental ABIEncoderV2. pragma solidity 0.5.9; pragma experimental ABIEncoderV2; contract company { struct contractDetails { string contractId; string companyA; string companyB; address A; address B; uint256 timestamp; string signHash; bool ...


1

The reason for that is because your solc-js compiler version is lower than 0.5.11 but you want the version of your contract to be higher than 0.5.11 so the compiler give error. A simple way to solve this is change pragma solidity ^0.5.11 to pragma solidity ^0.5.0 or just update your solc-js compiler with npm install solc


1

I think this will work: result.events.numberSaved.returnValues['number']


1

I changed genesis.json now it is working { "config": { "chainId": 9663080, "homesteadBlock": 0, "eip150Block": 0, "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0, "ethash": {} }, "nonce": "0x0", "timestamp": "0x5d5cdc87"...


2

You can try events, check this out: https://solidity.readthedocs.io/en/v0.5.10/structure-of-a-contract.html?highlight=events#events


2

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


1

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.


0

First, you should clarify what is the _address address that you pass to the getContract() function. Anyway, there is no good way of viewing all the mapping's elements. But there are some options: Use dynamically sized array. It is easier to show all the elements, however, the elemend can be accessed only by uint id. It is suitable for you if _contractId ...


0

To solve my problem I used a quick and dirty solution, similar to the trick used in hellopeach answer but doesn't provide you the remix interface. set up a virtual local server on port 80 for remix.ethereum.org. Put in the document root a simple valid index.html edit the hosts file to add a reference to remix.ethereum.org for 127.0.0.1 restart the web ...


0

You can't compile ABI. The error is because the Solidity compiler is expecting to see Solidity code, but instead it's seeing something else (JSON).


0

While another answer showing the use of the new keyword was accepted, I don't believe it directly addressed the fundamental misconception in the posed question. The key is to realize test = Test(addr) is not a use of the constructor. That's why you can't pass any constructor args. It's actually an explicit cast of an address to a contract. A new ...


0

I tried the same and my code worked perfectly. There was no such error as well. I cannot say about bug or something, just make sure that you are passing the values properly. Edited answer: I did the same as yours and its giving error creation of FundRaiser errored: Error encoding arguments: Error: invalid number value (arg="", type="number", value=...


0

Apologies all - I had simply failed to fund the faucet correctly before executing the withdraw function (i.e. the initial transfer from MetaMask had not confirmed)


-1

Change the solidity version your are using. Change the first line of your solidity file to this pragma solidity >0.4.2;


0

You appear to have created local copies of the OpenZeppelin Contracts. It is recommended to install npm install @openzeppelin/contracts and then import. Your Token is commented out, and whilst it is mintable, an initial supply is also minted. When using with a MintedCrowdsale you don't need to pre-mint tokens as tokens will be minted as they are sold. ...


1

If you just want to recover your contracts and migrate them to the secure version, you can run Remix IDE locally and change the hosts file to point remix.ethereum.org to your local machine. The steps are as follows: Install nodejs. There are many ways of doing this on a Mac, I prefer to use nvm (https://github.com/nvm-sh/nvm/blob/master/README.md) Install ...


0

The way to continue using Remix with a local Web3 provider is Allowing mixed content. To allow it in Chrome try to connect to your local Web3 Provider in https://remix.ethereum.org, it will through an error but in the url bar right side it appears an icon where you can click an "Allow unsafe scripts"... it should connect. Don't know how to do it in Firefox......


0

raj. I guess you can pick a license type on the Verify page https://ropsten.etherscan.io/verifyContract?a={yourcontractaddress}


1

I am not sure about modifying the nonce with send methods. You can use instead classic web3.eth.sendTransaction method (https://web3js.readthedocs.io/en/v1.2.1/web3-eth.html#sendtransaction). However, you'll need to provide the data field for this transaction. const nonceThatIWant = x; const txObject = smartContractObject.methods.addSomething(_valueToAdd); ...


1

Make sure that you are providing some withdraw_amount in the Value datafield in Remix IDE. By default it has value as 0. Consider this answer for your reference. https://ethereum.stackexchange.com/a/68640/53398 Let me know if the problem still persists. Edited solution: I've find out the error you are facing. When you're running this contract, you ...


0

as far as i concern you are trying to fire multiple transaction called "seneth" which has functionality to give ether. but you must be careful when you're trying to firing multiple at once there is following exception such as: 1. a fired transaction should be waiting for 30 seconds or less to be completed receive by blockchain network. 2. you can only send ...


0

Deploy contracts To deploy contracts do the following: Install MetaMask In MetaMask: select Main Ethereum Network or one of the test networks Make sure you have some ETH in your account (either by buying it or getting it via a faucet for the test networks) In Remix, via the plugin manager: add "Solidity compiler" and "Deploy & run transactions" Select ...


0

Try this mysmartContract.getPastEvents('numberSaved', { fromBlock: 0, toBlock: 'latest' }, function(error, events){ console.log(events); }) .then(function(events){ console.log(events) // same results as the optional callback above }); Actually, I took the example from Web3 docs.


0

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 ...


2

The value is actually returned, but we just don't have a way to get it with web3 libraries yet. Think about it: how can your client get the return value if it has no clue when or if the transaction will be included in a block. Luckily for you, there's a solution. It's called "Events", check it out: https://solidity.readthedocs.io/en/v0.5.10/structure-of-a-...


2

Abdul! There is a typo in your call function arguments. You should remove a space from test function signature, i.e. abi.encodeWithSignature("test(address,address)") Every symbol in the string is important since the whole string is hashed in encodeWithSignature function.


1

This should implement the functionality you tried to implement in the question pragma solidity ^0.5.0; contract TusharCoin { uint256 public totalSupply; string public name; string public symbol; uint32 public decimals; address public owner; mapping(address => uint256 ) balances; event Transfer(address to, uint256 amount); ...


2

You basically have to use an array. You could use a mapping inside a mapping of some sorts but the problem is that you can't iterate over a mapping so you would have no way of knowing what hashes you have stored - unless you already know the hashes in which case storing them here is pointless. So you need something like mapping (address => string[]) ...


1

You misunderstood the flow. You have User => Escrow.deposit() 1. Escrow => token.approve(this, amount) 2. Escrow => token.transferFrom(msg.sender, amount); // msg.sender did not approve this That won't work for the same reason I (for example) can't approve myself to withdraw your funds and then do it. It has to go: User => token....


0

When you create a SubToken from the MainContract, the SubToken constructor doesn't add the newly created token to the SubToken Tokens mapping and it is this mapping that is used in getInformations. Both your factory (MainContract) and token (SubToken) have mappings for tokens. I don't know your requirements for having this data captured in both places. I ...


2

You could look at OpenZeppelin Contracts ERC20 Token documentation to see if this meets your needs for an ERC20 Token. You may also want to use the OpenZeppelin IERC20 interface. Note that you should only use OpenZeppelin code published in an official release, so you should include the version tag in your import when using Remix or you can take a look at ...


0

Rate is explained in the OpenZeppelin Contracts Crowdsale documentation: https://docs.openzeppelin.com/contracts/2.x/crowdsales#crowdsale-rate You can also ask questions about how to use OpenZeppelin Contracts in the Community Forum Disclosure: I am the the Community Manager at OpenZeppelin


1

An interface cannot contain functions declared as internal or public, only as external. If you can declare your interface as contract and will not have that limitation. contract Bob { function foo() internal; } contract Mar is Bob { function vote() public { foo(); } function foo() internal { } }


1

pragma solidity ^0.5.0; import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol'; contract SubToken{ mapping(address => uint) balances; string symbol; string name; uint8 decimals; uint totalSupply; using SafeMath for uint; address contract_address; ...


1

Let's try. Monolithic pragma solidity ^0.5.0; contract A { function doIt() public { } function doOther(uint value5) public { } } 39293 gas Inheritance pragma solidity ^0.5.0; contract A2 { function doIt() public { } } contract B2 is A2 { function doOther(uint value5) public { } } 39293 gas when deploying contract B2. ...


0

If you are using ContractInstance.events.allEvents() there is a parameter 'fromBlock' which defaults to 'LatestBlock', so to get older events you should set a block number as a start point


0

here is the correct code. pragma solidity ^0.4.17; contract TugOfWar { int public score = 0; int constant endAt = 1 ether; bool public gameOver = false; event GameEnded(bool gameOver); event ScoreChanged(int amount,bool direction); function up() external payable { require(msg.value > 0); require(!gameOver); ...


1

That error will appear if you have declared the _data parameter of _safeTransferFrom as bytes storage. A way to fix it is to declare it as memory function _safeTransferFrom( address _from, address _to, uint256 _tokenId, bytes memory _data // _data is declared as memory )


1

So I finally figured it out. Thanks to all of you for your contributions! I really appreciate it. I figured out a really simple solution that works well and requires less gas. I added a function receiveFunds to the Portfolio contract: function receiveFunds() public payable { // function to receive funds received = msg.value; availableFunds += ...


2

If contract A owns tokens and you want contract B to spend then contract A has to approve contract B. And contract B has to use transferFrom with. contract A { ERC20 token; // <--- generic ERC20 token contract B seller; // <--- ticket seller accepts ERC20 tokens event TicketPurchased(uint); function buyTicket(uint amount) public { // ...


0

From their Gitter channel: [as of the time of writing] There is no default option. Compiler version is set in the URL. So it only depends on that. An alternative to setting a default compiler would be to bookmark the URL of the compiler version you want to "set as default". Whenever you want to use remix, you can then just click on the bookmark to load ...


1

By default, Remix online compiler uses the version v0.5.1+commit.c8a2cb62.js, which is set in the configuration files. Github repo: https://github.com/ethereum/remix-ide File compilerContainer.js (line 26). defaultVersion: 'soljson-v0.5.1+commit.c8a2cb62.js', // this default version is defined: in makeMockCompiler (for browser test) and in package.json (...


0

function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = balances[from].sub(tokens); allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); balances[to] = balances[to].add(tokens); Transfer(from, to, tokens); return true; } What is your allowance ...


0

With the new solidity compiler this is possible. Probably you would have to end up adding the pragma declaration for experimental ABIEncoderV2 at the top of the contract definition file. I am using 0.5.9 and works fine. pragma solidity ^0.5.9; pragma experimental ABIEncoderV2;


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('...


0

Just chiming in for the benefit of others who come across this. @Majd is right about the logic error. Even so, there are additional errors in this. The for loop is an anti-pattern. Its mere existence is not a problem, but the fact that there could be no upper limit to the number of users, therefore the number of iterations, therefore the gas cost of this ...


0

From a gas perspective - specifically, if this were ever being called by another contract as part of a transaction, rather than just a call being made directly - then not having another function call on the stack is going to be cheaper: pragma solidity ^0.5.1; contract PlayerExample { uint private maximumPlayers = 10; uint private players = 5; ...


0

If you use a function you have the possibility to add extra functionality to it when needed, for example access checks. Otherwise I don't see much benefits in using a function.


2

You can not declare function name same as variables name because solidity automatic create the getter function of public variables.


1

The nonce in transactions is a concept for preventing certain types of attacks (at least double-spend). When you make your first transaction from an account the nonce is 1. For every subsequent transaction you have to increment the nonce by 1. If you try to send two transactions with the same nonce the other one will fail with the error message you are ...


Top 50 recent answers are included