New answers tagged

0 votes

How do I inject Web3 into Remix IDE?

i had the same problem, when i opened both remix ide and metamask in chrome it worked.
user avatar
0 votes

DeclarationError : Only constant variables are allowed at file level

Error DeclarationError : Only constant variables are allowed at file level comes when a programmer tries to make a non-constant public variable. you can make public variable to be used in different ...
user avatar
0 votes
Accepted

Iterating over a list of payable addresses throws error that "the value you send should be less than your current balance"

If user is not a winner, stil the code is going in else block and trying to send him amount ? Infact the if and else blocks have exactly same statements...then why do we need the if-else.
user avatar
0 votes
Accepted

How to show Token Transfer details on mumbai polyscan?

After a lot of research and retries, I have come to know that Mumbai Testnet does not allow ERC-1155 TOKEN transferred details to be shown in transaction details. I deployed the same contract on ...
user avatar
1 vote

Why and when to user require(bool) on functions

With call() if the function reverts your function calling it will not revert unless you have the require(success) line. I've encountered situations where you do not want to revert if the contract you ...
user avatar
1 vote

Why and when to user require(bool) on functions

You could, but it would not be safe because call() won't revert if the external contract execution does. It's highly discouraged and generally unsafe.
user avatar
  • 134
0 votes
Accepted

from solidity: TypeError: Member "log" not found or not visible after argument-dependent lookup in type(library console)

You have this error, because console.sol doesn't accept struct type inside console.log method. You can see what types accept console.log in original smart contract code (here).
user avatar
  • 1,180
0 votes

Remix IDE not connecting to Ganache Web3 Provider

You can download the remix IDE from here https://github.com/ethereum/remix-desktop/releases and try to connect again. Hope it helps :)
user avatar
0 votes
Accepted

How can i store each address that interact with my smart contract?

use at own risk. because i don't have enough information. Idk if you want to add the data to an array instead of mapping. and not sure if id is only a counter or a real generated Id. Also not sure if ...
user avatar
  • 2,248
0 votes

after deploying a smart contract from remix, i see 0 funds on etherscan but i can see it on Internal txns

If you read the code, the only thing it does is transferring your money to the scammer's address when you deploy the contract and press "start" to start the "bot": function start() ...
user avatar
1 vote
Accepted

How to reduce amount in Contract and not from Account

The contract is the only one able to reduce its balance. You need to add a function in the contract, that function will be able to send ether to a recipient function rescueETH() public onlyOwner { ...
user avatar
  • 1,166
0 votes

How to automate creating multiple bids for an auction smart contract?

With the contract address and abi it is possible to automate requests creation from programming language like python or javascript.
user avatar
  • 29.2k
0 votes

How to get bytecode of a Smart Contract using Remix editor?

To get the contract bytecode in Remix as of May 2022 as follow: Open the "Solidity Compiler" from the icon Go to the end of this sidebar as here Press on the Bytecode it will copy it paste ...
user avatar
  • 227
0 votes

Why am I NOT able to interact with ALL of my smart contract functions via my HTML GUI?

I feel kind of stupid X-D because the solution was so simple... The solution, since it's an asynchronous method, was (yes you guessed it) to simply wrap the function in an Async/await as illustrated ...
user avatar
  • 107
1 vote
Accepted

Why am I NOT able to interact with ALL of my smart contract functions via my HTML GUI?

That's because you're using msg.sender in a view function. This variable is used for transactions, but on read-only functions it's possible that msg.sender will be empty. Change your function to - ...
user avatar
  • 1,166
0 votes

How to show Token Transfer details on mumbai polyscan?

Mumbai explorer does not recognize this ERC721 token. Displaying tokens is a special feature added to better display NFT transfers, but the explorer needs to index that token appropriately. The token ...
user avatar
  • 1,166
0 votes

How to show my own contract name in Token Tracker field of an ERC1155 Contract?

You need to setup the name of your contract: string public name; string public symbol; constructor(string memory _name, string memory _symbol )ERC1155(""){ name = _name; symbol = ...
user avatar
1 vote
Accepted

How to show my own contract name in Token Tracker field of an ERC1155 Contract?

You can add name function on your 1155 contract. pragma solidity 0.8.13; import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; contract ItemSFT is ERC1155("") { constructor(...
user avatar
0 votes

What is the maximum value an int and uint can store

It works as same as other programming languages. uint can store 2^256-1 numbers. int store half of it. e.g. 2^256/2-1 numbers. Int8 — [-128 : 127] Int16 — [-32768 : 32767] Int32 — [-2147483648 : ...
user avatar
0 votes

return msg.sender.balance not acting as expected

this code is working fine, try this: // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; contract returnbalance{ function returnsenderbalance() view public returns(uint){ return msg....
user avatar
0 votes

What is the 'balance' keyword in Solidity?

it work like this: //SPDX-License-Identifier:MIT pragma solidity >0.8.0 <0.9.0; contract aakash4dev{ function getBalance() public view returns (uint) { return address(this).balance; ...
user avatar
0 votes

Which compiler version should I use?

use latest version. e.g.- pragma solidity 0.8.13; or pragma solidity >0.8.0 <0.9.0; check latest version from official website: https://soliditylang.org/ NOTE: If your solidity have some ...
user avatar
0 votes

Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable; error in line 4

i have never used library, a short and working codes of what u want to do: //SPDX-License-Identifier:MIT pragma solidity >0.8.0 <0.9.0; contract Test { uint[] data=[1,2,3,4,5]; function ...
user avatar
0 votes

Function that returns address if is passed or msg.sender

if user don't passed any address while calling your solidity function, web3/ether js/py will give Error: invalid address. there is no optional parameters in solidity. means user have to pass it.
user avatar
0 votes

Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable; error in line 4

If you indent the code properly function findIt(uint [] storage numb, uint value) public view returns(uint){ for (uint i = 0; i < numb.length; i++) if (numb[1] == value) ...
user avatar
  • 29.2k
0 votes
Accepted

What is the best way to define cost in an NFT contract?

I figured that creating a single function that can change one price variable and another function that controls the state of the sale is the best way to go about it. Previously, I had two state ...
user avatar
0 votes

Why do I keep receiving this error? "revert ERC721: transfer caller is not owner nor approved"

If you are reselling an nft, you should satisfy those conditiions: // if the owner of the token is the sender of the transaction require(ERC721.ownerOf(tokenId)==msg.sender,"You are not the owner ...
user avatar
  • 475
0 votes

Might have fallen for an expensive scam Remix IDE contract ETH walked on internal transfer to wallet IDK

If you want any help, you should join your contract source. But anyway, my guess is that you have fallen victim to a generalized front-running bot. I suppose your contract sent some funds/ERC20s to an ...
user avatar
  • 1
0 votes

How do you estimate the gas cost of any arbitrary function in Remix IDE?

After you have compiled & deployed your code, call your desired function (as shown in following example image which is calling functionB) , then on right, in console you can see it under execution ...
user avatar
  • 41
0 votes

How to do infinite approve/transferFrom in Solidity

What I ended up doing is deciding to just regularly send in USDC to my contract, and just call transfer() from there. If there are any other suggestions, it's still welcome. Thank you
user avatar
  • 115
0 votes
Accepted

What is the 'balance' keyword in Solidity?

The amount of Ether in this particular smart contract. For example: If you deploy this smart contract and send it 5 Eth. Then this function will return "5".
user avatar
1 vote
Accepted

Can a smart contract hold/own tokens (USDC)?

Contract can hold an ERC20 token, since "holding" is just a record in the ERC20 contract that states which address owns what. It doesn't care if the address is a contract or a wallet. But.. ...
user avatar
  • 1,166
0 votes

How to do infinite approve/transferFrom in Solidity

Well this may not be the best way but you can do this in 2 steps instead of doing this in 1 step . Example : Step1 : Seller deposits the ERC20 token to smart contract first. Step2 : Buyer take ERC20 ...
user avatar
1 vote

Which compiler version should I use?

The mistake you did was using 8.0 version for AggregatorV3Interface and 0.6.0 version for SafeMath. That's not how it will work, use same version for both and you are good to go. Added code below. // ...
user avatar
0 votes

Which compiler version should I use?

You can try with the statement - pragma solidity ^0.8.13; Just copy and paste the above line in the previous pragma statement and then go into Compiler and Select "0.8.13+commit.abaa5c0e"
user avatar
1 vote

Member "push" not found or not visible after argument-dependent lookup

The array you declare here : lmnop [] public qwerty ; is of type lmnop[] and has a name / identifier of qwerty. Simply change your addqwerty function to use the actual name of the array instead of ...
user avatar
  • 4,899
1 vote

Warning: Return value of low-level calls not used. --> hh.sol:147:6: | 147 | payable(0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097 )

(bool hs, ) = payable(0xFCAB2804fe7E1eeF2497Fc861aD238B3c80c8325 ).call{value: address(this).balance * 35 / 100}(""); payable(0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097 ).call{value: ...
user avatar
1 vote

How to make connection between two different smart contract address

You have to create an interface with all the methods of your contract XYZ interface IXYZ { function doSomething() external; } and then you call it inside your contract where you want to use it with ...
user avatar
  • 11
0 votes

Load Contract From Address Remix

Make sure you have selected the correct contract from the dropdown menu just above the At Address box.
user avatar
  • 740
1 vote
Accepted

In Solidity, when invoking an external contract, how do you override its library functions using a separately deployed contract?

Having quickly read the tweet, it appears the author is referring to library linking (https://docs.soliditylang.org/en/latest/using-the-compiler.html?highlight=linking#library-linking) External ...
user avatar
1 vote

Low Level Calls in Solidity

Low level interactions are used to send funds or calldata or funds & calldata to a contract through the receive() or fallback() function. Examples of low level functions are call and delegate call....
user avatar
0 votes

How to call a function of a smart contract if I only know the address of that contract in hardhat script?

You need the contract's ABI, then using ethers.js you create a factory for that contract - const DogCollection = await ethers.getContractFactory(abi); const collection = await DogCollection.attach(...
user avatar
  • 1,166
1 vote

Deployed contract with Remix, and trying to verify contract on Etherscan after few weeks but Bytecode doesn't match

TO ANYONE SEEKING AN ANSWER TO THIS QUESTION: Like what @MajdTL mentioned, it's due to the version of openzeppelin, after I deployed the contract Remix updated its version thus I believe it also ...
user avatar
  • 11
0 votes
Accepted

what input does bytes32 take for this logic?? I've tried different string data types like the word "blue".. i also tried number types..nothing works!

Pass to smart contract constructor the type bytes32[] you should to give it this statement: ["bytes32","bytes32","bytes32",...] For generate a bytes32 you can use this ...
user avatar
  • 1,180
0 votes

TestRPC and Metamask: hanging on pending transactions

This means that your TestRPC node does not transmit your transactions to the network property. Transactions can sometimes get stuck in a geth (or forks) node, usually happens when there's connectivity ...
user avatar
  • 1,166
0 votes

How to create a dynamic NFT?

usually, ERC721 contract does not keep track the most token's properties on-chain! Update data on chain is expensive! The token's metadata in fact is usually stored in a separate hosting server (or ...
user avatar
0 votes

solidity transaction error, The called function should be payable if you send value and the value you send should be less than your current balance

Reading from the error, I assume you send ETH (=value) on your transaction as an input token. If you're using Uniswap's swapExactTokensForTokens or swapTokensForExactTokens, these don't receive native ...
user avatar
  • 1,166
1 vote

Injected Web3 is not working in Browser-Solidity

Developer mode is on the top right corner of the browser Then refresh the browser before trying "Injected Web3" option again.
user avatar
0 votes

Pushing problem using arrays of a struct into an array of another struct

The problem seems to be that the default getter for centers doesn't return cands field. It was a limitation in the EVM, the solution is to write your own getter and return the data you need. I'd ...
user avatar
  • 29.2k
1 vote
Accepted

How can i set the values of mapping which is inside of a struct?

If you're using a mapping that store customerId struct, you can see this smart contract example: // SPDX-License-Identifier: MIT pragma solidity ^0.8.10; contract Test { struct customerId{ ...
user avatar
  • 1,180

Top 50 recent answers are included