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
4 votes
3 answers
1k views

Importing a contract from another contract in NodeJS app

I'm using a function in my NodeJS app to deploy contracts. The user inputs the contract he wishes to deploy and the app deploys it. The structure of the app is . ├── app │   ├── models │   │   └── ...
mcansado's user avatar
  • 841
4 votes
0 answers
406 views

Gas cost for bigInt library

I am working on a big integer library in the online compiler. Currently having gas/computational time issues with the modulus function. I first implemented it using repeated subtraction: function ...
user avatar
4 votes
2 answers
1k views

Sending string to deployed contract function

var source = fs.readFileSync("./vote.sol", "utf-8") var compiled = web3.eth.compile.solidity(source); var abi = compiled.identify.info.abiDefinition; var Vote = web3.eth.contract(abi); var ...
nick carraway's user avatar
4 votes
1 answer
1k views

passing byte[] to smart contract using nethereum

I made a solidity function that allow a user to send multiple transactions with the same nonce as a singleton Tx signer: function multipleTransferPreSigned ( bytes[] _signature, address[] ...
Hadar Keidar's user avatar
4 votes
3 answers
4k views

How to properly write Solidity unit tests?

I would like to write maintainable and readable unit tests for my code. Requirements: Test different actors. E.g. a bank contract and three customers interacting with it. Test for errors. E.g. test ...
user3669782's user avatar
4 votes
1 answer
1k views

Why are getters of public state variables not recognised by interfaces?

In code like the below, address public balance has an automatic getter function (as can be seen in the corresponding ABI). However we need to redefine it to avoid the compiler complaining that Test ...
Adam Dossa's user avatar
  • 1,287
4 votes
1 answer
1k views

How do I connect to the Remix JavaScript VM from my front end

I have been developing using Remix and Metamask but it's a slow progress when pushing to the test networks. I have switched to the JS VM in Remix but I am not sure about how to connect my frontend to ...
ORStudios's user avatar
  • 443
3 votes
1 answer
51 views

Smart Contract/Nextjs Error: Returned values aren't valid, did it run Out of Gas?

I'm having an error while calling one of the function of the deployed contract from Next.js Error: Parameter decoding error: Returned values aren't valid, did it run Out of Gas? You might also see ...
Mohsin's user avatar
  • 31
3 votes
0 answers
59 views

Implementing Verkle Trees in Solidity, Generating Proofs, and Using Zokrates

I'm working on implementing Verkle Trees and looking for guidance on how to implement Verkle Trees in Solidity. I have a working python code with implementation of verkle trees, proof generation and ...
Shrigouri's user avatar
3 votes
0 answers
29 views

Smart contract in Solidity: call a function from a contract written in Vyper

I'm writing a contract in Solidity, in which I'm trying to call a function from another contract written in Vyper. To do so, I've checked the corresponding function in the ABI of the Vyper contract, ...
Tom's user avatar
  • 31
3 votes
1 answer
129 views

Ethers js is creating transaction for pure function

I am trying to call a pure function via ethers js and store the data in a variable. Now I supposed that variable to contain the return value from the contract, but instead, that variable contains ...
Zartaj Afser's user avatar
  • 2,150
3 votes
1 answer
59 views

Modefiers Overloading

Compiling this code: pragma solidity ^0.8.17; contract OverloadModifier { uint public a = 0; bytes public b = 0x00; modifier m(uint _a) { _; } modifier m(bytes _b) { _; } ...
Ahmed Rami Berrahal's user avatar
3 votes
1 answer
358 views

In forge tests, how can I import events?

In forge tests I've been redeclaring events within the test file so that I can use vm.assertEmit. Is there a way to import events from the contract I am testing instead? e.g. // SPDX-License-...
Milk's user avatar
  • 391
3 votes
0 answers
165 views

Can't Access Properties Off of Struct In Foundry / Forge: Possibly Due to Nested Mapping

I am unable to get attributes off a struct in my contract from my Foundry test file. How can I get a property off an instance of a struct in my contract from my Foundry test file. In DAO.sol contract (...
currenthandle's user avatar
3 votes
0 answers
487 views

How to deploy smart contract with raw transaction

I want to deploy transaction with raw transaction without using hardhat or web3 method. my code looks like this. // constructor params const name = 'My Contract'; const symbol = 'MC'; const maxSupply =...
rrrrssss's user avatar
3 votes
1 answer
552 views

Working with huff contract in foundry (a few questions)

I'm trying to deploy huff contract in foundry to goerli testnet (it is deployed), BUT: Why is so that my runtime code looks like it was written in Solidity ? Is there a way to avoid this and create ...
obsessed's user avatar
3 votes
1 answer
489 views

Merkle tree airdrop how to build

I am writing an ERC20 token contract (contract token) with a mint of 2 million tokens. I am also writing a Merkle tree airdrop contract and sending it to this contract (contract Merkle tree). So, let'...
Ingrosso's user avatar
3 votes
0 answers
45 views

Elegant way to purposefully charge more gas in a smart contract

I am trying to run tests to see how much a smart contract will cost, but since I am in my research period, I have to make some assumptions on how my smart contract will be developed. I would like to ...
Barney Chambers's user avatar
3 votes
0 answers
41 views

Classical bit-fiddling tricks that don't work in the EVM

Many classical bit-fiddling/bit-hacking tricks work very well on the EVM and allow one to save a significant amount of gas when programming in Yul/Solidity (for a reference to the classics, see Sean ...
Netanel's user avatar
  • 51
3 votes
2 answers
572 views

Testing VrfCoordinatorV2Mock fulfillRandomWords gets stuck

I am testing a smart contract that uses Chainlink's VRF Oracle. Locally, I am using a mock to test with. In the unit test it never executes the fulfillRandomWords function that on my smart contract, ...
Anas Latique's user avatar
3 votes
0 answers
168 views

Function to parameter tuple for decode

I have an interface with a defined function: interface IERC20 { function approve(address spender, uint256 amount) external returns (bool); } Does solidity have a way of specifying the function's ...
Apetoshi Rugamoto's user avatar
3 votes
1 answer
36 views

from where do we give the gas fees while deploying from vscode on a testnet?

just a quick question I was following the patrick collins course on solidity with javascript and in it, we deployed a contract created on vscode using hardhat deploy on a testnet rinkeby But since ...
Jaskaran Singh's user avatar
3 votes
0 answers
270 views

How to pass a 2-dimensional array to Etherscan?

How do you pass a 2D array into etherscan? This works in remix but not etherscan: [[1,2],[3,4],[5,6]]
p0pps's user avatar
  • 278
3 votes
0 answers
489 views

Hardhat test increasing account balance

I'm running the test outlined below using Hardhat. The smart contract has a function to output 'msg.sender.balance', and the test file calls this function, then waits for the next block, then calls ...
Rick's user avatar
  • 91
3 votes
1 answer
436 views

How to configure EVM in IntelliJ with Solidity plugin

There is a related question/answer from 5 years ago but back then the plugin only provided syntax highlighting. Now, I know I can compile from the solidity file opened in IntelliJ, clicking on a play/...
mehrlicht's user avatar
3 votes
1 answer
2k views

How to pass bytes parameter to contract method call using Web3.js?

I'm trying to call a method in a contract and the method is like this: function myMethod(uint8 tid, bytes calldata _bytes) public view returns (string memory) { ... } I'm using Web3.js to ...
Farzad Z's user avatar
3 votes
0 answers
371 views

Embedded vs linked libraries

I recently became aware of linked vs embedded libraries. My understanding is that if your library uses public pure functions and/or manages storage, then you need to deploy and link the library to ...
Nolan Jannotta's user avatar
3 votes
0 answers
167 views

How to store secure private keys on a server, that are being used for 'gasless' minting using EIP-712 based messages?

NOTE: By 'gasless' I mean that I won't have to mint the tokens for the user, they can mint it themselves provided they have a valid signature. Hi, In my NFT (ERC-721) contract, I'm allowing callers to ...
Sol Man's user avatar
  • 31
3 votes
0 answers
117 views

How to pass by value in Solidity?

I have checked older posts in regards to this topic, but I suppose Solidity got updated in the meanwhile because they are not up-to-date/do not apply anymore. I have the following contract: // SPDX-...
Jacob Krieg's user avatar
3 votes
0 answers
219 views

Does brownie have functionality to analyze gas costs for all function calls?

Does brownie have any sort of functionality that gives a breakdown of the cost to deploy all contracts and execute all function calls within a brownie project with min, max and average gas cost ...
MShakeG's user avatar
  • 1,408
3 votes
0 answers
96 views

Two external/public functions calling a private function. Where to put nonReentrant()?

I have a case similar to those examples bellow. Assuming buy() & discountBuy() has no call, transfer or send, would it be safe to let the nonReentrant() in the private _internalBuy()? It seems to ...
Arthur's user avatar
  • 31
3 votes
1 answer
3k views

Should I use totalSupply() or a custom counter for ERC-721 token id?

I'm following OpenZeppelin ERC721 guide. They use a counter (Counters.Counter) for the tokenId. My contract inherits from ERC721Enumerable so I have totalSupply() out of the box. I was wondering if I ...
Hector T.'s user avatar
3 votes
1 answer
117 views

cross chain token

I see a lot of projects that have their token on multiple chains. I was wondering how they do it? I guess they build a contract for each blockchain but how the liquidity works? how can people move ...
Amit Wagner's user avatar
3 votes
1 answer
76 views

Is there an incentive to delete variables / array values / other stored items?

I am working on an application where my storage will grow and grow. I could delete data as I go, but I dont see any incentive to do so. Is there something I'm overlooking? Specifically talking about ...
p0pps's user avatar
  • 278
3 votes
0 answers
807 views

Incompatible EIP155-based V 1 and chain id 1

It's my first question here so please don't be so strict. I have such a scenario: I start learning how blockchain works, downloaded truffle, ganache cli, created an account on infura and all that ...
AGJoYy's user avatar
  • 386
3 votes
0 answers
449 views

Creating an Automatic NFT trader

(Apologies for keeping the questions so broad but not sure of the starting point at this stage) Hi All, I am trying to build an automatic NFT trader where a smart contract will buy the NFT from ...
Rwiju Pal's user avatar
3 votes
0 answers
811 views

ethers.js can't handle functions with variant call signature?

I get type errors in hardhat when my contracts have two versions of the same function which differ only by call signature, i.e. contract MyContract { string memory public _defaultVersion ="1.0....
GGizmos's user avatar
  • 701
3 votes
0 answers
570 views

How to calculate sine and cosine in Solidity?

How can I calculate sine and cosine? Is there any library?
Haseeb Saeed's user avatar
3 votes
1 answer
354 views

Error: exceeds block gas limit / transaction underpriced

When I call the function .send({ from: accounts[0], gas: "5000000000" }); and attempt to deploy my contract, I get an :Error: exceeds block gas limit." When I switch to a much lower ...
Louis L's user avatar
  • 31
3 votes
0 answers
304 views

Signing a hash with EIP712

Is it possible to sign just a hash with the EIP712 standard (either within Solidity or Ethers.js)? If so, how? All that I'm finding online is the full EIP712 process of domain, types, values, signing ...
dNyrM's user avatar
  • 711
3 votes
0 answers
181 views

Include library function without function body

Using solc 0.5.0 it's possible to compile a contract that has a library function implemented with no body. For example: library Hasher { function MiMCSponge(uint256 in_xL, uint256 in_xR) external ...
GeraldHost's user avatar
3 votes
0 answers
140 views

Uniswap path generation

The uniswap contract has a function called swapTokensForExactTokens. One of the arguments to this function is an array of addresses called "path" which is the route that the transfer will ...
Rishi's user avatar
  • 31
3 votes
0 answers
648 views

Contract location and inheritance with private variables

When inheriting from a contract, all functions of the parent are accessible in the deployed child's contract's namespace (contract address) Yet when a parent's function is called they read/write from ...
Marcellvs's user avatar
  • 423
3 votes
0 answers
510 views

Solidity sourceMap and opcodes. No map entries for every code?

After compiling a simple contract, the output are these values: "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH1 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP ...
Juan Ignacio Pérez Sacristán's user avatar
3 votes
0 answers
998 views

abi.encodeWithSignature and abi.encode have inconsistent results with dynamic arrays

pragma solidity 0.8.0; function isMemberOfArrayEncodedTest(address member, address [] memory memberArray) public returns (string memory){ bytes4 sig = bytes4(keccak256("isMemberOfArray(...
John Sterlacci's user avatar
3 votes
0 answers
422 views

How can I do contract call transaction from Metamask qr code scan?

I have a payable function in the smart contract that takes some ether from the sender and does some tasks. I want to generate QR code for this contract call transaction so that user can scan and ...
Abishek Bashyal's user avatar
3 votes
0 answers
49 views

Cannot access .length property of dynamic array in Solidity

I have a mapping like below. struct A { //Some fields } mapping(address => A[]) testMapping; When I add a new item to that array, I can use the code below and it works well. testMapping[msg....
Batın Evirgen's user avatar
3 votes
0 answers
369 views

Struct getter and Setter using inline assembly in solidity

I have a storage slot defined bytes32 internal constant USER_STRUCT_SLOT = 0xd722976edd762e336e189ef10d2d356b8698dc8a2e03a97b539ab9d3974a1630; struct UserData { uint256 level; ...
CryptoScroller's user avatar
3 votes
1 answer
31 views

Difference in calldata and arguments

This may be a dumb question, but I'm trying to understand is there a difference re: byte-wise or gas-wise in between using calldata and explicitly mentioning arguments. For example, for this struct: ...
Ruham's user avatar
  • 953
3 votes
0 answers
1k views

Uniswap JS SDK returns invalid pair address for two ERC20 tokens in hardhat network

I create two ERC20 tokens, deploy them with hardhat on hardhat network, then create Uniswap pair, then retrieve its address with SDK's Fetcher and with my contract. Fetcher returns different address ...
rlib's user avatar
  • 289