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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
23 views

How to initialise a mapping of a structure inside a function?

I am having a struct which is having a map and I want to update the map dynamically... Code : struct task { string description; status taskStatus; address assignedTo; ...
user avatar
  • 21
0 votes
0 answers
9 views

Running Solidity Smart Contract on FrontEnd

I have just understood the Uni-Directional Transfer Smart Contract documentation and would like to implement it on my front end (Javascript & HTML). However, I am unclear how to do so as the Smart ...
user avatar
0 votes
1 answer
17 views

how to call a rest api into smart caontract

My scenario is as follows: I use a private Ethereum network such as ganache. In a smart contract function, I need to call a web service and then continue processing based on it. I don't have any idea. ...
user avatar
0 votes
1 answer
15 views

Unable to require ERC-20 token in a Solidity function

I have a basic ERC-20 Token defined as import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; contract Token is ERC20 { constructor() ERC20("Token", "TOKEN") {} ...
user avatar
0 votes
1 answer
35 views

how to deploy a contract by sending ether to it's address

I'm trying to build a payment gateway and I generated address of a contract before deploying it with create2. how to deploy the contract by sending ether to new generated address? pragma solidity 0.8....
user avatar
  • 21
2 votes
0 answers
355 views

Why is the Vyper Bytecode smaller? What is it giving up?

I have two contracts that are essentially the same, but one is in vyper: # SPDX-License-Identifier: MIT # @version ^0.3.3 my_var: public(uint256) @external def update_var(my_new_var: uint256): ...
user avatar
0 votes
1 answer
20 views

Failing to verify signature

I'm trying to verify a signature using OpenZeppelin's SignatureChecker library, but always returns false. This is the verify function from the lib: function isValidSignatureNow( address ...
user avatar
  • 307
0 votes
1 answer
12 views

Remix not letting workspace download

Remix doesn't allow me download the workspace. I've been trying to hit the download button, but it doesn't allow me download the workspace.
user avatar
0 votes
1 answer
9 views

Solidity codes and there Theoretical information

Hello everyone i am learning solidity development from freecodescamp.org i don't have any coding background but now i cant find information about all the codes (syntex) like i want to understand every ...
user avatar
  • 1
0 votes
1 answer
28 views

Unable to transfer eth into contract in hardhat

I am working on some ERC20 tokens in which user have to send it to get tokens, i am getting some error while running it!! i am stuck at the const txHash = await addr1.sendTransaction({ to: ...
user avatar
  • 13
0 votes
1 answer
24 views

How to cast an array made up of user-defined value types to the underlying type in Solidity?

I have an array which is made up of user-defined value types: type UD60x18 is uint256; UD60x18 memory foo[] = new UD60x18[](2); Now, I would like to turn this into uint256. Can I cast this array to ...
user avatar
0 votes
1 answer
12 views

Transferring weth from my contract to an other wallet address on polygon without using bridges

I have a requirement where we are building a platform that receives funds on Ethereum L1 and sends that fund back to the same address on polygon L2. I know bridges are there to transfer funds from l1 ...
user avatar
0 votes
0 answers
19 views

How to convert address to bytes in solidity? [duplicate]

I tried with this function, but it's not working, getting the same address input in output. function toBytes(address a) public pure returns (bytes memory b){ assembly { let m := mload(0x40) a ...
user avatar
0 votes
1 answer
28 views

Different gas amount for erc20 Transfer functions

I have used Transfer function for an erc20 in different contracts with the same codes. The point is here, in different times there was different gas while the function was the same. The input of the ...
user avatar
0 votes
1 answer
16 views

How can I use UniswapV2 to create my own LP tokens?

I'm new to DeFi and liquidity farming. I'm just trying to build a simple LP farming application for testing and I'm trying to generate some of my own LP tokens to be used as my reward tokens. I'd like ...
user avatar
0 votes
2 answers
46 views

How to access mapping in solidity?

This is the solution to my previous question How to access mapping in contract? | Solved by @kerry99 This time I have added the strct Vertex inside the mapping, now how call the value of x and y into ...
user avatar
0 votes
0 answers
21 views

The block number when you await solidity call in javascript

If I await two solidity calls in javascript sequentially: await contract.A().call(); await contract.B().call(); does it mean they will guarantee to happen in two different blocks? Thanks. EDIT: both ...
user avatar
0 votes
1 answer
21 views

Gas optimization of calldata input variables

I have some external functions what receives address lists as calldata to save gas. I know that creating a copy from global variables inside functions can be useful to read less from blockchain ...
user avatar
  • 186
0 votes
1 answer
31 views

Returned error: VM Exception while processing transaction: revert when i use UniswapV2router functions

I'm using my owned cloned UniswapV2 smart contracts(core+periphery) and deployed them using ganache network, so when i start testing functions, i started with createPair() function located in ...
user avatar
0 votes
0 answers
15 views

How to calculate amountOutMin parameter in the UniswapV3 swapRouter.exactInputSingle() function using an onchain oracle?

Can someone tell me how to calculate the amountOutMin parameter in the swapRouter.exactInputSingle() function using an onchain oracle? I've got a working uniswapV3 oracle that can retrieve the price ...
user avatar
0 votes
2 answers
18 views

Does solidity have a method like range() to generate numbers within the range like [1:5] -> [1,2,3,4,5]? Or need to use for loop?

I'm new to Solidity. Does solidity have a method like range() to generate numbers within the range like [1:5] -> [1,2,3,4,5]? Or need to use for loop? For example, a = list(range(1,21)) is what I ...
user avatar
  • 1
0 votes
0 answers
28 views

How to get solidity custom errors on dApp?

I would like to get the custom error code from my dApp, however, I can't get it when the smart contract is using revert. However, I can get the error reason when the solidity contract use required. Ex....
user avatar
0 votes
0 answers
10 views

UUPS Upgradeable Smart Contract Access Control - Ownership Transfer

I am working on a UUPS upgradeable contract that I need to transfer the ownership of to an admin. I am using openzeppelin's AccessControl on the contract. I read that for upgradeable contracts, the ...
user avatar
0 votes
0 answers
12 views

why would I need to call `ens.resolver()` on chain?

I was reading the following link and somehow, the question popped up in my head. It suggests that - transforming from string name to bytes32 _node should happen off-chain. Let's just assume that this ...
user avatar
0 votes
2 answers
26 views

The Ethernaut King Challenge

I am trying to pass level 9 of Ethernaut challenges known as the King contract. My designed contract for hacking the King contract is as follows: pragma solidity 0.8.0; contract MaliciousKing { ...
user avatar
0 votes
2 answers
77 views

[SOLVED]PatrickCollins Solidity Course 2022 - Lesson 7: 11:20:38 -> TypeError: ethers.getContract is not a function

AssertionError: Expected transaction to be reverted with You need to spend more ETH!, but other exception was thrown: Error: Transaction reverted: function returned an unexpected amount of data I was ...
user avatar
0 votes
1 answer
17 views

How do I write smart contracts that are LP tokens?

I'm very new to blockchain and DeFi, and I'd like to ask a questions regarding LP tokens. If I wanted to list 4 LP tokens, with farm reward proportions of: 80/60/40/20, how do I go about writing them? ...
user avatar
0 votes
1 answer
18 views

when to use require and when to use revert in solidity

Require and revert function does same task so when to use which function ? Which function uses less gas fees ?
user avatar
  • 21
0 votes
0 answers
11 views

SolcInstallationError: Downloaded binary would not execute, or returned unexpected output on Windows 10

I was previously working on windows 8.1 but recently upgraded to windows 10 so I could use the Ganache GUI. The code seemed to work absolutely fine for windows 8.1 but I cannot seem to install solc on ...
user avatar
0 votes
2 answers
12 views

Latest remix version is not detecting metamask

I just updated Remix to the latest version and it is not detecting metamask wallet when I try to select Injected Web3 from the list of environments.
user avatar
  • 760
0 votes
0 answers
18 views

How to send a "Address" from Javascript to Solidity Contract

Hi i have created frontend and working with web3js. Now what i am trying to do is: Updating the data in the contract. Add the address in the contract (So here in form i am asking the user to put the ...
user avatar
0 votes
2 answers
24 views

How to get the balance of impersonate account in hardhat

I am new at hardhat, i saw how to impersonate account as it went successful i try to get the balance of that address, unable to get not sure why. here is the output ... i saw the some where like if it ...
user avatar
  • 13
0 votes
1 answer
15 views

How do I send my custom erc20 token from ethreum to arbitrum?

I am trying to send my custom erc20 tokens from ethreum (testnet) to arbitrum(testnet) through arbitrum bridge. But not sure if I had to map my token first or arbitrum bridge does that itself? How ...
user avatar
1 vote
2 answers
18 views

Smart contract is not available on the blockchain during the constructor call

I have the following sample code: // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '@openzeppelin/contracts/token/ERC20/ERC20....
user avatar
0 votes
1 answer
15 views

ERC721 setApproveForAll for 2+ operators

I was wondering how setApproveForAll is working. If the USER approves 2 operators(operatorA and operatorB), and operatorA create an auction and sells the USER's NFT first, is the job of operatorB to ...
user avatar
0 votes
1 answer
37 views

Return bytes from inline assembly

I have two little tests in which I'm trying to return bytes that are populated via inline assembly. It works when I'm using a pre-defined return variable, but I'm getting a buffer overrun when I try ...
user avatar
  • 3
0 votes
1 answer
31 views

Dealing with tokens with different decimals in wei

I have two tokens, tokenA which has a decimal value of 18 and tokenB with 9 decimals. I would like to buy tokenB for tokenA or vica-versa. The question is that do I need to make any conversions with ...
user avatar
  • 186
0 votes
2 answers
50 views

Help Please Solidity version pragma statement in these files doesn't match the configured compilers in your config*contracts/hello-world.sol ("0.8.4")

Hi Please am unable to figure out why i get this error while trying to compile my interact.js script using npx hardhat run scripts/interact.js --network ropsten on vs code : Error HH606: The project ...
user avatar
0 votes
0 answers
17 views

How do you find the child contract address when deployed from a factory?

I'm experimenting with the OpenZeppelin crowdsale contracts, using the MintedCrowdsale example. When this is deployed, hardhat logs out the contract address for MyCrowdsaleDeployer. Question: Where ...
user avatar
0 votes
1 answer
17 views

Hardhat chain fork on the test rather than config file

I saw that it is possible to test with Hardhat on a forked chain, via the config file. Is it possible to do it on the test file instead? In a beforeEach, maybe. I only want some of my tests to run on ...
user avatar
2 votes
1 answer
15 views

Truffle contract factory test with Javascript

Here is my smart contract source code. // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; contract CampaignFactory { address[] public deployedCampaigns; function createCampaign(uint ...
user avatar
0 votes
0 answers
15 views

I've been struggling to verify and publish my contract source code

I'm new to Solidity and Ethereum smart contract deployment, so I have been struggling with the verify and publish contract source code part. I don't know where I went wrong with this: // SPDX-License-...
user avatar
0 votes
0 answers
8 views

Decrypt Open SSL with a public key within Solidity contract

I wish to implement a whitelist function to my NFT minting solidity contract that also includes an NFT asset limit. For example, user A is allowed to mint 1 NFT, and user B 3 NFTs etc. I also wish to ...
user avatar
0 votes
0 answers
15 views

i'm working on an NFT collection following a tutorial video on web3 dao. my contract isnt compiling and it's showing the error below

//SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import "@openzeppelin/contracts/access/Ownable....
user avatar
0 votes
1 answer
18 views

calldata encoding

I have been having an error with the following function call: IVault(VaultContract).depositFor( address(this), 47545929749321238, address(this) ...
user avatar
  • 925
0 votes
0 answers
24 views

Make user withdraw tokens

As a best -and most secure- practice, how do you make an user to withdraw tokens from your contract, without them having to initiate the withdrawal procedure (aka calling a withdraw function), instead ...
user avatar
  • 307
0 votes
0 answers
31 views

Passing array to external function in inline assembly

How can I pass a (nested) array to an external function if the call is made within an inline assembly block? I wrote the following little test contract and everything works just fine until I add the ...
user avatar
  • 3
1 vote
2 answers
30 views

window is not defined when used with next.js

I am trying to write a React-next.js app. I have the following file that exports an instance of Web3 by passing in window.ethereum to the constructor. import Web3 from 'web3'; const web3 = new Web3(...
user avatar
0 votes
1 answer
12 views

Not able to use "connect()" method to sign transactions with different account in HARDHAT

I am making a smart contract so that I can send messages and other addresses can also send messages in that contract. So the message, block.timestamp and the sender's address will be stored in an &...
user avatar
0 votes
1 answer
19 views

Ethers.js ignore revert

I'm using Hardhat to deploy my contract locally, and Ethers.js and Node.js run a Javascript file which makes sequential calls to the contract to simulate user activity. When the contract reverts (for ...
user avatar
  • 41