Questions tagged [solidity]

Solidity is a contract-oriented, high-level language whose syntax is similar to that of JavaScript and it is designed for writing smart contracts in Ethereum to run on the EVM. Solidity is statically typed, supports inheritance, libraries and complex user-defined types among other features.

1,624 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
2
votes
0answers
66 views

Why truffle deploy fail with address value=0 after I upgrade to version 5.0.5?

I have a truffle 2_deploy_contracts.js something like this : const sample = artifacts.require('./Sample.sol'); module.exports = function(deployer) { deployer .then(()=>deployer.deploy(...
2
votes
0answers
41 views

Why I can't use two functions with same name, but different parameters

I have a function which returns address but it gives me error if I try to read it. I'll explain by a quick example: Solidity: contract TestOneReturn { mapping(uint => uint) m_Data; ...
2
votes
0answers
46 views

Function call always returns 0

Working with a simple contract to get the hang of this. I can't seem to get the correct value back from my contract function. It always outputs 0. Truffle version: 4.1.15 Contract: pragma solidity ...
2
votes
0answers
255 views

solidity-coverage show 0% coverage

I'm trying to make a test coverage for MetaCoin. This is my package.json, truffle-config.js and .solcover.js: module.exports = { port: 8555, norpc: true, compileCommand: '../...
2
votes
0answers
27 views

Can I import a Library from a Library?

Is it possible to import a library into another library? I give a simplified example below of what I'd like to achieve: library structLib { struct Point { uint X; uint Y; } } ...
2
votes
0answers
25 views

How to change prefix of signature in Javascript?

Is it possible to change the signature prefix, which by default: "\x19Ethereum Signed Message:\n32" Can I change it to another prefix? I need to get a signature in solidity in this way: bytes32 ...
2
votes
1answer
49 views

Trying to understand why my test.js fails

I have a function that is not passing my tests in JS but the function works as expected in Remix. Can you help me contract.sol function test1 () public view returns(bool){ return(true); } ...
2
votes
0answers
30 views

How does the Solidity compiler translate the `using .. for` statement?

I'm trying to figure out how using [Library] for [type] is compiled by the solc compiler. I noticed that address placeholders are not in the bytecode as with other library references. So what ...
2
votes
1answer
148 views

Call a payable contract's function from another contract via an interface

I have two contracts, they are connected via an interface. When user calls contract1 function, it uses an interface to call contract2 function which updates it's storage. My problem is that I can ...
2
votes
1answer
39 views

How to get the return type of a function of an already deployed contract?

I am currently working on a real estate blockchain project. Now I have 2 contracts user.sol and property.sol. The person who is registered on the website through user.sol can only buy or sell property ...
2
votes
0answers
44 views

Can I send transaction to a view|pure function?

This is the contract: uint public result; address public owner; constructor() public { owner = msg.sender; } function add(uint a, uint b) public returns(uint) { result = a + b; return ...
2
votes
1answer
116 views

Web3JS incorrect return value

When I return a string array with web3 I don't get the original array as expected, but rather I get an array of the same size, with the index off by one. So instead of ["One","Two","Three"] I get ["",...
2
votes
0answers
37 views

How to add function buy to buy button that need array index

I am new to this smart contract and blockchain. I'm trying to do simple selling goods dapps. But i'm stuck at the buy button. I have array for the products. constructor() public { goods[0].owner =...
2
votes
1answer
33 views

mapping data is not returned from SmartContract during the first time add operation

I have the below given SmartContract and the test. Please note that, when i try to execute the test, only after the second call to the grantAccess method, I am able to get the mapped value. pragma ...
2
votes
1answer
181 views

Passing one contract instance as an argument to the constructor of another contract

I need to use the functions of the ERC20 contract in another contract. The ERC20 contract is from the openZeppelin contract library. I found the following code on a website: import "../../...
2
votes
0answers
89 views

Using OpenZeppelin's increaseTime.js

I'm writing a test for a time-dependent solidity function. I'd like to use the increaseTime.js helper from v1.12.0 of OpenZeppelin's library. When I try to call this helper inside my test, I get an ...
2
votes
0answers
51 views

web3 - get all contract public variables?

I have an abstract worker contract and few that inherit from it. Those contracts have some public variables, each one different. I want to display them on my website. Is there any way to return all ...
2
votes
0answers
27 views

One time catastrophic solidity bug suddenly vanished

I'm writing a Blackjack game in solidity. In the following function, the player ended up winning one time with a hand strength of 30 after doubling down even though they should have busted. ...
2
votes
1answer
220 views

Remix: Gas required exceeds allowance or always failing transaction

I have a contract which has transferFrom function mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; mapping (address => bool) public ...
2
votes
0answers
134 views

How to implement percentage deposit function to smart contract

I need to implement on the deposit function when the ownerAddress is doing a deposit a 10% to be freeze in the smart contract and and if the ownerAddress want's to call the returnDeposit function by ...
2
votes
0answers
61 views

Why is putting data to storage more expensive during the deployment of contract than storing the same data by a method?

I am working with truffle and solidity (v0.4.23) and found out that when I pass in an argument of constructor some bigger amount of data (16kB) that are saved to storage of a smart contract, it is ...
2
votes
1answer
31 views

Why use different gas?

I have this contract with this functions, why each use different gas amount? pragma solidity 0.4.24; contract Foo { //transaction cost: 21471 gas //execution cost: 199 gas //total cost: 21670 ...
2
votes
0answers
96 views

Can I call a library function from a payable function?

I seem to get a revert each time I try this. I'm unable to get any useful revert message from truffle, so any assistance there might also help solve this. I have a library: library LibInterface { ....
2
votes
1answer
55 views

Transaction execution and interacting with truffle

pragma solidity ^0.4.23; contract Hotelbooking{ address receiver; function deposit(uint256 _amount) payable public { require(msg.value == _amount); // nothing else to do! ...
2
votes
2answers
126 views

Truffle interaction with my smart contract getting Vm exception

pragma solidity ^0.4.23; contract Hotelbooking { event Transfer( address indexed _from, address indexed _to, uint256 _value ); mapping(address => uint256) public ...
2
votes
0answers
71 views

STOP after RETURN in bytecode generated by solidity

I am currently analyzing the code generated by the solidity compiler. Let's take this simple example: pragma solidity^0.4.24; contract test { constructor() public { } } The code generated with ...
2
votes
1answer
90 views

Transmit array as first parameter in web3.js

When I develop in solidity combined with web3.js, I face some problem recently. I create a contract code below //setContractDetail(index,bool isConsentItem,uint8[] detailItems) function ...
2
votes
1answer
218 views

Geth Sync Problems | Rinkeby, Ropsten | Deploy contracts

Get Geth to sync --> Rinkeby test network. For the love of god I just want to deploy a contract. I have deployed it to Ganache-cli, GUI, remixIDE, deployed with truffle/Infuria.io...I keep failing to ...
2
votes
0answers
38 views

What is the command PUSH29 010..00 in solidity compiled bytecode?

If you take a look to the bytecode of several contracts compiled from solidity you can notice that in the first ".data" basic block there is this command: PUSH29 ...
2
votes
0answers
49 views

Interacting with a complex deployed contract from my other contract

For example, I want to call a create market function from augur in my contract. I'm using the recommended pattern, but there are additional contracts that this function brings in, ex ICash, IMarket ...
2
votes
0answers
413 views

Contract too large

I am sure this has already been answered but I could not find a clear answer. I get the following error: Contract creation initialization returns data with length of more than 24576 bytes. The ...
2
votes
0answers
41 views

How does createProxyImpl work in ProxyFactory Contract?

function createProxyImpl(address _target, bytes _data) internal returns (address proxyContract) { assembly { let contractCode := mload(0x40) // Find empty storage location using "...
2
votes
1answer
23 views

Contract - Demo - Identifier - Only 3 Lines for my contract to work - ¿does somebody know how to fix this?

pragma solidity ^0.4.23; contract Owned { address owner; function owned() public { owner = msg.sender; } modifier onlyOwner { require(msg.sender == owner); ...
2
votes
2answers
183 views

Error when running Truffle Test in Terminal

I am trying to use truffle to test my smart contracts and have written some test files. I am getting an error on the terminal trying to run the test and am unsure what the reason is. I access my ...
2
votes
1answer
257 views

How can we compile multiple smart contracts by compile.js file?

My compile.js file is below const path = require('path'); const fs = require('fs'); const solc = require('solc'); const ballotPath = path.resolve(__dirname, 'contracts', 'blocktitans_ballot.sol'); ...
2
votes
1answer
181 views

call other contract's external function , the error: The contract code couldn't be stored, please check your gas amount

when I deploy a contract, the truffle frame told me this error :“The contract code couldn't be stored, please check your gas amount”。 the solidity code is: 1) Base.sol pragma solidity ^0.4.22; ...
2
votes
0answers
27 views

msg.sender is not showing corect value

I am facing a strange issue. Please read the below case craefully and assit me to geth this issue resolved. I have ERC20Token created by Zeppling templates. [Please ignore syntaxes, I am just trying ...
2
votes
0answers
53 views

Is returning an array of structs possible yet?

From what I can tell this should be possible now: function test2 () public view returns (Post[]) { Post memory post; post.sender = msg.sender; post.link = "test"; ...
2
votes
1answer
32 views

Assertion Rely on Balance Amounts

Is it possible in Ethereum blockchain to have two or more events simultaneously occurred? Regarding the following solidity code: function _transfer(address _from, address _to, uint _value) ...
2
votes
2answers
479 views

Solidity Event logs

I have a JS code which is connected to ganache. I am trying to call a solidity function which in tern emit the event. In JS i am watching the event. Now when i call the function first time it sets ...
2
votes
0answers
160 views

Signature generated through web3.eth.sign not leading to same address after fromRpcSig

I am trying to write sign a challenge using web3.eth.sign, web3 uses ganache.provider(), But when i do fromRpcSig(signature) ecrecover(challenge) which results in different address. But when i sign ...
2
votes
0answers
55 views

Estimated gas is always low

web3.eth.estimateGas is always calculating low gas for the transaction. Here is a reference to a trasaction in ropsten. https://ropsten.etherscan.io/tx/...
2
votes
0answers
196 views

Getting Json file from remix

I have been deploying contracts on rinkeby but we are almost done to go to mainnet. I have been comparing deployments with truffle and remix and there is a huge difference in gas uses, so I would ...
2
votes
1answer
55 views

What order is code copied for inheritance?

The Solidity documentation says it supports inheritance by copying code, but is unclear about where the code is copied to. I am building a genesis block for a Quorum-based chain, starting from the ...
2
votes
1answer
129 views

Created Crowdsales contract, sending ropsten ETH to the contract and Failed

I created crowdsale contract - https://ropsten.etherscan.io/address/0xfbb2759ef0b7169d0a2effa971845ea0f99f87b1 My token - https://ropsten.etherscan.io/token/0x0f26c1c05f1bbBC7Eff0488F1a98619e8a9758cf ...
2
votes
1answer
53 views

Any way to do compile-time computation using rational_const and a constant value?

Of the following three declarations ufixed constant TEST1 = 256; uint constant TEST2 = 256; uint[] testTable1 = [uint(0.001 * TEST1), uint(0.01 * TEST1), uint(1.1 * TEST1)]; uint[] testTable2 = [uint(...
2
votes
1answer
104 views

Function to return tuples throws error on frontend

I have similar functions like this and they work fine: function getBarsOfParticipant() external view returns (uint256[], uint16[], bool[]) { uint256[] barIds = participantToBarIds[msg.sender];...
2
votes
1answer
377 views

web3.py constructor(address type)

I tried to deploy the contract on my testrpc, but I get error when my constructor using "address" type. Here is my python code: import json import web3 from solc import compile_source from web3....
2
votes
1answer
40 views

I am unable to verify my contract on etherscan

Unable to verify my contract on etherscan. This is the link - https://ropsten.etherscan.io/address/0xc68c67a1864060631817be1eebdb91e8661fae7a . Please help. Its urgent. Here is my code: pragma ...
2
votes
2answers
670 views

Gas Estimation Failed in Remix

Found my own problem. Can't really use the transfer function as it is written. It assumes the owner uses it. So made a new function for the "minting" function for the faucet to use. Not sure why the ...