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.

5,296 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3 votes
0 answers
24 views

Is it possible to call a higher-level function from within assembly?

Take the following code: contract Foo { function increment(uint256 x) external returns (uint256 result) { result = x + 1; } function increment_twice(uint256 x) external ...
Paul Razvan Berg's user avatar
3 votes
1 answer
113 views

how do I know that NFT is from the right person

I understand the NFT (at least solidity part).. There's something that's bugging me though. Let's say someone made a super great cat(cat1), published it to ipfs, then called the ERC721 contract and ...
Nika Kurashvili's user avatar
3 votes
0 answers
835 views

Uniswap addLiquidity Error: "revert TransferHelper: TRANSFER_FROM_FAILED"

I'm having issues with the addLiquidity() call failing due to what likely seems to be an approval issue and producing the following error code: Internal JSON-RPC error. { "message": "VM ...
T-Man-Stan's user avatar
3 votes
0 answers
768 views

Safe implementation on Solidity 0.8.0 of a withdrawal and a refund

I'm here for asking of a SECURE way to implement on solidity 0.8.0 two functions: 1-Withdrawal() which sends all the ether of the smart contract to the owner address. My current implementation is: //...
Simone Tosatto's user avatar
3 votes
1 answer
432 views

Can abi.encodeWithSignature be optimized by pre-compute?

I have a proxy implementation with method exchange and delegator with method exchange2 with the following code: function exchange2(int128 i, int128 j, uint256 dx, uint256 min_dy) public { (...
lebed2045's user avatar
  • 295
3 votes
0 answers
2k views

Swap tokens to Ether on Uniswap V2 TRANSFER_FROM_FAILED

I am trying to swap DAI to ETH on kovan testnet my wallet and contract both have DAI tokens. Whenever I swap the token through web3 the transaction fails Fail with error 'TransferHelper: ...
Marr's user avatar
  • 327
3 votes
0 answers
415 views

solc unable to import scoped packages

I am trying to import these lines on solidity and compile it with solc import '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol'; import '@uniswap/v2-periphery/contracts/interfaces/...
Marr's user avatar
  • 327
3 votes
0 answers
2k views

The gas-cost of a static-call of a pure function

A pure function doesn't cost anything when called from an off-chain script (or from some other constant function). But it does cost when called from a transaction (i.e., from a non-constant function). ...
goodvibration's user avatar
3 votes
0 answers
472 views

Catch Internal Out of Gas Exception in Solidity Code

I ran this transaction which executed correctly, but one of the internal calls gave me back an out of gas error. I had a try/catch mechanism to let my code terminate silently (to set some really ...
Jason Trump's user avatar
3 votes
2 answers
275 views

Set and delete storage variable in same tx

I did some poking around and didn't see an answer... and I figure someone knows this off the top of their head. Question: what is the gas cost associated with setting and deleting a storage variable ...
kronosapiens's user avatar
3 votes
0 answers
3k views

How to Download source code of existing smart contracts on ethereum block chain

We are working on a project which requires smart contract source codes for analysis in ethereum blockchain. Can anyone suggest us how to download the source codes of various smart contracts already ...
Ravi Teja K.R.'s user avatar
3 votes
0 answers
882 views

Best way to run tests in Truffle for contracts that rely on mainnet dependencies?

I could create mocks of the dependencies but I'd really like to be able to fork mainnet using Ganache in a way similar to this (https://medium.com/@samajammin/how-to-interact-with-ethereums-mainnet-in-...
Michael C's user avatar
  • 433
3 votes
0 answers
145 views

Ethereum Smart Contracts/dApp’s open source license?

Can a smart contract in which it’s source was released be GPLv3/GNU licensed? I.e. if a company were to release the source code to a smart contract, can that smart contracts source code be GPLv3/GNU ...
geedapp's user avatar
  • 31
3 votes
2 answers
1k views

Cannot deploy new contracts with pending transactions (Ropsten)

I have a very strange and annoying problem. I am trying to deploy a new contract however it just keeps cycling. I have the same problem on the POA testnet and on Ropsten. Please see below: I have ...
Philip Rutovitz's user avatar
3 votes
1 answer
2k views

Contract Fallback function with ERC20

I see the fallback function of a contract as a way of "depositing" an Ether value to the contract. My question is very simple I guess, but I couldn't find the answer yet. Is it possible to develop a ...
João Quintanilha's user avatar
3 votes
0 answers
673 views

Anything like a static delegatecall from a view function?

let's say there are two contracts A and B, where A calls methods in B. I understand that A can modify and read storage in B with B.call() and B.staticcall(), ie. A can execute B's methods in the ...
hellopeach's user avatar
3 votes
2 answers
180 views

Auction contract problem regarding highest bid display

I have an Auction contract which has a function like this: function bid() payable{ //calculate and store highest bid value } But because each transaction takes time to mine, so when a user bids ...
Indigo's user avatar
  • 31
3 votes
2 answers
233 views

Best way to create identity contracts for organisations

What is the best way to create identity contracts for organisations based on their information like name, address, organisation type(buyer/seller) etc. I have tried using factory pattern to create ...
Mikey's user avatar
  • 41
3 votes
0 answers
104 views

One-to-many mapping inside struct

I have two structs: struct A{ uint bid; mapping(uint => B[]) BMap; //bid - index for struct B } struct B{ uint cid; } mapping(uint => A[]) AMap; How can we push and fetch 'cid' ...
angelmaria's user avatar
  • 1,061
3 votes
0 answers
975 views

Can I extend the interface of a contract without redeploying it?

The case I'm dealing with is a contract which should serve as a Data Abstraction Layer. So ideally, it should provide only getter functions and setter functions. For example, my interface is: ...
goodvibration's user avatar
3 votes
0 answers
245 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(...
user76333's user avatar
  • 167
3 votes
1 answer
489 views

Passing in an array of complex structs

I am wondering what pattern I am supposed to follow in Solidity to take in an array of structs as a parameter. I am translating code from CPP and mostly everything translates directly besides this (...
0TTT0's user avatar
  • 662
3 votes
1 answer
319 views

How to use enums for conditions on constructor?

I am learning to code with solidity. need help to solve this I have a membership system where users can have basic, gold, diamond membership types. Users can use coupons every 5 minutes and for basic ...
Ophelia's user avatar
  • 37
3 votes
0 answers
679 views

Questions on MinterRole contract in openzeppelin

I am using the openzeppelin for creating the ICO contract. I am concerned about the MinterRole here. After I develop Token contract, I added the sale contract as a minter using "addMinter" function. ...
iappmaker's user avatar
  • 813
3 votes
1 answer
330 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 ["",...
Felix Dolderer's user avatar
3 votes
1 answer
1k 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 "../../...
saurab marjara's user avatar
3 votes
0 answers
159 views

solc: [libevmasm/CMakeFiles/evmasm.dir/Assembly.cpp.o] Error 1

I am trying to install solc v0.4.25 through brew on a Mac. Please note that I was able to install its latest version solc v.0.5.0 using brew install solidity; but I am unable to install its previous ...
alper's user avatar
  • 8,368
3 votes
1 answer
1k 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 ...
fortza italia's user avatar
3 votes
1 answer
1k views

Error Ganache: Run out of gas - Works in Remix/Not from dApp

I am working on an application that stores and retrieves personal data on/from the ethereum blockchain. Just working on this to improve my Solidity and SC expertise and get comfortable with the ...
Valentijn van den Hout's user avatar
3 votes
1 answer
496 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 ...
user46230's user avatar
3 votes
0 answers
55 views

Delegatecall Scope - Correct me if I'm wrong

When any contract function is called - delegatecall or otherwise - the EVM loads the requisite pointers & values into that call frame's volatile stack/memory. Example: Let's say we have contract ...
Ask P's user avatar
  • 241
3 votes
2 answers
669 views

Check your gas amount error ERC721

I am trying to deploy contracts to Ganache for testing using Truffle, but no matter what I set gas price / gas limit / gas to both in truffle.js and Ganache itself, it always get check gas amount on ...
Forrest Colyer's user avatar
3 votes
1 answer
124 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 ...
ohsully's user avatar
  • 580
3 votes
1 answer
1k views

Drizzle cacheCall is not updating data correctly

I have a react component which is interacting with a solidity contract via drizzle. I store a cacheCall index in the constructor: this.opcTokenCacheCallIndex = context.drizzle.contracts.OPCToken....
CollaborativeLearner's user avatar
3 votes
1 answer
242 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];...
Mindful's user avatar
  • 393
3 votes
0 answers
347 views

Why does this work with Solidity 0.4.21 but not 0.4.22?

I have this simple set of contracts. pragma solidity ^0.4.21; contract FirstContract { bool public isTrue = true; function sayHello() public pure returns(bool) { return true; } } ...
Rob Hitchens's user avatar
  • 54.7k
3 votes
1 answer
3k views

How to unpack/decode parameters encoded with web3.eth.abi.encodeParameters in Solidity?

My client app (nodejs) packs some arguments to pass to a smart contracts as bytes _data (similar to ERC223 calls with fallback). I pack the arguments in my JS client like this: const packedArgs = ...
Andrey's user avatar
  • 1,117
3 votes
0 answers
382 views

delegatecall on library always run out of gas

I'm trying to replicate the Dynamic Library attack of this paper under a recent version of solidity and the EVM. Streamlining down the code, I've created this very simple contract (which is, in ...
Cristiano Paris's user avatar
3 votes
1 answer
1k views

ERC223 Token Fallback Function Usage

I'm currently writing the "Trade" smart contract which is similar to "Crowdsale" smart contract. The only function that I want to add is "sell" function. In general Crowdsale smart contract is used ...
rachel_hong's user avatar
3 votes
0 answers
1k views

How to use logx in Solidity?

Aim: To log data from a smart contract. Following function is written in accordance with low level interface to Logs in ethereum. However, due to lack of documentation, and being new in Solidity, I ...
Karan's user avatar
  • 416
3 votes
0 answers
283 views

How to parse through the logsBloom of a block or transaction using solidity

Currently trying to figure out how to parse through the logsBloom portion of block and transaction headers using solidity. I've researched the topic so far and have come to the understanding that RLP ...
hextet's user avatar
  • 1,573
3 votes
2 answers
28k views

TypeError: Cannot read property 'then' of undefined

I am having an error with Web3. After going through all possibilities I decided to post a question hoping for someone with a solution. The error I keep getting is: TypeError: Cannot read property '...
H Ali's user avatar
  • 31
3 votes
0 answers
203 views

Solidity : About function calls between deployed contracts

I want to make a function call between a token (MyToken.sol) that inherits MintableToken.sol of OpenZeppelin and manipulate that token (Buy. Sol). (MyToken.sol) pragma solidity ^0.4.21; import "...
kk bonjour's user avatar
3 votes
0 answers
624 views

Testing solidity default function with Truffle and async/await

I am developing a crowd sale contract in solidity. The fallback function is payable so that investors can send ether to the contract. If incoming transaction is accepted then information about the ...
rodneymo's user avatar
3 votes
0 answers
80 views

Methods and constants order in the contract ABI

Is it possible to annotate methods and constants order in the contract ABI before compilation?
Dmytro Zarezenko's user avatar
3 votes
2 answers
4k views

How to inherit an interface?

This code works - taken from Wiki - pragma solidity ^0.4.18; contract ERC20Interface { function transfer(address to, uint tokens) public returns (bool success); } contract FixedSupplyToken is ...
Trevor Lee Oakley's user avatar
3 votes
1 answer
104 views

Non-specific error from truffle debugger

I am testing a contract which is using ecrecover function of solidity. While its testing when i go with a failed test case while debugging, it doesn't go step by step and at the end return the same ...
Aniket's user avatar
  • 3,515
3 votes
1 answer
1k views

Loop with optimal gas usage

I currently have the following loop (some stuff left out) mapping (address => uint) pendingWithdrawals; function example () private{ address[] tempList = List; for(uint k = 0; k < ...
Gabe's user avatar
  • 363
3 votes
0 answers
298 views

Benefits of library versus a plain contract (upgradeability)

I'm trying to find what the benefit is of a library. I found the following statements. (Please correct me if i'm wrong) Cost less gas to deploy Uses the storage of the calling contract the library ...
just_trying_stuff's user avatar
3 votes
2 answers
2k views

How to set dynamic buy and sell price for my token?

I have built a simple erc-20 token. I used the code given on ethereum.org code as a reference. There they have talked about setting the price of my token. But how do I set it dynamically, as in ...
sushantmit's user avatar