New answers tagged

0 votes

How to construct deployable bytecode from runtime bytecode?

Using modern web3.js const bytecode = await web3.eth.getCode(contract) const creationCode = new web3.eth.Contract([]).deploy({ data: bytecode })._deployData
user avatar
0 votes

How to implement a counter (variable that is updated every time the contract is called) in Solidity?

If the desired behaviour is that your contract stores an internal counter and anytime that the function show is called you retrieve the value of that counter and increment it by one afterwards, then ...
user avatar
  • 179
0 votes

In Solidity, what are the differences in purpose between overriding isApprovedForAll() and enabling meta-transactions?

OpenSea gave me this answer to the question: As a quick disclaimer, I am not a developer, but I can hopefully help to clarify a bit more on this. Generally, the 'isApprovedForAll' refers to Token ...
user avatar
0 votes

What is the correct way to implement meta-transactions for OpenSea using Polygon?

OpenSea gave me this answer to the question: I've checked in with our developers and they've let me know both examples you've provided should work; the code detailed in our developer docs was written ...
user avatar
0 votes

Set address as constant in Vyper

this compiles successfully: CONTRACT_ADDRESS: constant(address) = 0x251C4A81963B45b86330F5483A22D041b455d2f0 The address must be checksummed first. For example in python this can be done like this: ...
user avatar
  • 115
0 votes

ProviderError: Error: Transaction reverted: function selector was not recognized and there's no fallback function

I got this error when running this on the hardhat network. Once I switched to a real network like kovan it worked. If you're hitting this error try running against a real network.
user avatar
0 votes

Setup Ganache with Metamask. What and where is a Chain ID?

I think your Metamask already has a local network so delete that network first and then try it. it works for me.
user avatar
0 votes

Linking to Compound Smart Contract

your CompoundERC20 is only an abstract contract. you should import from https://github.com/compound-finance/compound-protocol/tree/master/contracts
user avatar
  • 1
1 vote
Accepted

Contract has callable functions not in ABI or source code

We could help better if you included more details such as contract addresses. But in your case it seems like that contract is a Proxy Contract, this is why you don't see the implementation nor the ...
user avatar
1 vote
Accepted

How to transfer an NFT from a contract address to a wallet address

If you did not already, you should first approve your contract from your EOA to give permission. Then you should be able to transfer the ERC721 token. And transfer_out function should be: def ...
user avatar
0 votes

What is the execution order of Inherited constructors in solidity?

Current Solidity docs provide the answer in this paragraph: https://docs.soliditylang.org/en/v0.8.13/contracts.html#multiple-inheritance-and-linearization Basically: Solidity guarantees that all the ...
user avatar
0 votes

TypeError: No matching declaration found after argument-dependent lookup

Looks like you may have had some formatting issues when posting your question. Regardless of that the Error you're seeing is because the first argument in your call to require needs to evaluate to a ...
user avatar
  • 101
1 vote
Accepted

Create contract with contract

MomContract deploys a daughter contract only on its constructor, which only runs onces, you should have a function you can call several times for you to deploy the daughter at will.
user avatar
  • 1,164
2 votes
Accepted

Why doesn't address(this).balance work in a state variable?

uint public balance = address(this).balance; sets the balance state variable to the the address' balance at the time the contract is created, which is 0. It will not update its value unless some ...
user avatar
  • 146
0 votes

Using "hardhat deploy" plugin, and it is not getting the deployed contracts

Are you sure, you ran your node bevor running this and deployed your contracts on the correct chain? so before getting the contract you need to run your node like yarn hardhat node depending on the ...
user avatar
0 votes
Accepted

Why Solidity Compiler Allows declaring storage variables inside functions?

This is an uninitialized storage pointer which points to slot 0. I used 0.8.14 (version is important here). No warning was raised. Previous compilers did indeed warn about this. Data storage data ...
user avatar
  • 51.2k
0 votes

How to delete an element at a certain index in an array?

A solution that consumes a bit more gas compared to others. // Preload any custom data through other functions address[] customArray; function removeIndex(uint256 index) external { address[] ...
user avatar
0 votes

How do I specify a different Solidity version in a Truffle contract?

in 2022.6, truffle 5.x + version, you can speicify the compiler version. e.g. Bby default , solc version is 0.4.x , you can make it 0.8.x $ cat truffle-config.js module.exports = { networks: { ...
user avatar
  • 160
1 vote
Accepted

How I can retrieve event logs generated by a contract?

you can listen for events in frontend, I'm assuming you're using ethers for contract interaction, ethers provide helpers for that, e.g. ethers.provider.on(contract.filters.Approval(), (args) => { ...
user avatar
0 votes

How to pass a blank bytes calldata into a solidity function call?

bytes memory data = new bytes(0);
user avatar
0 votes

how can library change state?

Libraries are stateless, they can store only 'constant' values. So even if delegatecall is used on library it wont be able to change the state of caller contract. For example when i tried to create ...
user avatar
0 votes

An unexpected error occurred: Error: Cannot find module '@nomiclabs/hardhat-waffle' [Hardhat, openzeppelin]

you lack the @nomiclabs/hardhat-waffle ethereum-waffle package in your dev folder. use yarn or npm to install it as a dev dependency, then modify the config file accordingly.
user avatar
0 votes

Do modifiers work in interfaces

What you can do is to use a virtual contract as an "interface" (as suggested above). The scheme is: abstract contract A { modifier adminOnly { /// checks admin _; } ...
user avatar
0 votes

Is it advisable to "wrapped" my tokens in order to use inside my Dapp to lessen gas cost?

Upto what I understand, you want that user's transaction would not be broadcasted to blockchain and would happen just in the server. This could be implemented but this would not make your app ...
user avatar
-1 votes

Are there well-solved and simple storage patterns for Solidity?

Thanks Rob for inspiration! Here is extended version of Mapped Structs with Delete-enabled Index that also support nested mappings, "unstructured" data and ownership Hope it will help ...
user avatar
0 votes

How to get all historic changes of a state variable in a smart contract?

To add to @pabloruiz55 's answer, I wanted to suggest yet another alternative that I think is better than storing an array, as it is O(1) in the number of historical updates: use a backwards linked ...
user avatar
  • 101
2 votes

Funds stucked in smart contract

The funds are not stuck, they are now controlled only by the creator (0x97ce82ccb3d8d6a02c87799f1d8d8af4dad77a0e). You need to contact them, asking to call again the transferOwnership function. In any ...
user avatar
0 votes

Is it possible to have a struct within an Event?

Here is the Zero-Error Solidity Smart Contract code to use struct with event & function parameter : //SPDX-License-Identifier:MIT pragma solidity >=0.8.0 <0.9.0; contract aakash4dev{ ...
user avatar
0 votes

Funds stucked in smart contract

Ok, So you could use upgradeable contract, Here's the link, https://docs.openzeppelin.com/learn/upgrading-smart-contracts You can create a new function, that may would allow you to withdraw funds from ...
user avatar
1 vote

Pushing a contract to an array in another contract

I would have thought an array of structs would have been the natural choice here but assuming there's a reason you want an array of contracts I stuck with your example. No issue pushing the contracts ...
user avatar
  • 358
1 vote
Accepted

Pushing a contract to an array in another contract

What version of solidity are you using and what is the error you are getting? I have tested your code and it works adding the data location "memory" to the parameter in the constructor of ...
user avatar
0 votes

Pushing a contract to an array in another contract

Do it in steps: function addDog() public { Dog newDog = new Dog("test"); dogs.push(newDog); }
user avatar
  • 48
1 vote

Putting consolidated events data on Blockchain

The easiest solution I see is to directly have everything be handled by the smart contract. When emitting these events that count towards your activity, then you can also just increase an activity ...
user avatar
  • 1,089
1 vote
Accepted

Get Signature for Tuple input for EIP712

Okay so it took me many hours to figure this out but I finally got it. After reading some EIP712 resources this worked: No changes were made on the Solidity side. However, on the Java side, I made a ...
user avatar
0 votes

Etherscan contract not updated even though contract updated

Can you elaborate? Smart contracts arent upgradeable. Once you deploy something on chain, it's here forever (Well it's an oversimplification, but thats the idea). What did you do exactly when you &...
user avatar
  • 946
2 votes

Downsides of using ERC721A over ERC721?

There's no "functional" downside to using ERC721A over ERC721 if you are going for sequential mints anyhow. The same differences between ERC721 <-> ERC721Enumerable pretty much apply ...
user avatar
  • 1,089
1 vote

Please help me find what this function does? Is there is a way around it

Stay away from this kind of contract. Actually, with that function in place, the contract owners can change the balances of the tokens as they prefer. Moreover, the contract is bugged or tries to hide ...
user avatar
0 votes

How to get a variable from the smart contract with web3 and abi?

2022 WebJs 1.7.3 If anyone struggle with it in 2022, then this is the solution import Web3 from "web3"; const web3 = new Web3(provider); const myContract = new web3.eth.Contract( ...
user avatar
0 votes

EIP-2612: Why doesn't it use `_transfer` instead of approvals

This is a very interesting question, and I've been pondering it for a while now. Reading the EIP (https://eips.ethereum.org/EIPS/eip-2612), it talks about "paying gas fee with tokens" and &...
user avatar
0 votes

Mınt Gas Fee Problem

There's nothing you can do. It depends how busy the network is and when lots of NFT drops happen at the same time it gas gets expensive. Assuming you're on Ethereum mainnet. Whether your contract ...
user avatar
  • 358
1 vote
Accepted

Signing a tuple (struct) for ECDSA.recover

Here is the solution guys: let msgHash = web3.utils.soliditySha3( { type: "uint256", value: tokenId }, { type: "uint256", value: priceNumber }, { type: "string&...
user avatar
0 votes

What is approve function doing in this code?

The approve function approves usage of the token to be transferred given the _amount. The wallet that calls the function is approving the DAI contract to use _amount from the wallet. dai.approve ...
user avatar
  • 76
1 vote
Accepted

How can I create an NFT that people can only mint by my website?

If you trust yourself, you can create a backend server. With this server, you can sign an object like: { requestID: 123, } Send this signature and object to your contract and verify, is it sent ...
user avatar
0 votes

When we redeploy a smart contract , Is the smart contract updated on the same block of the blockchain or a new block is created?

from wikipedia A blockchain is a growing list of records, called blocks, that are securely linked together. Each block contains a cryptographic hash of the previous block, a timestamp, and ...
user avatar
0 votes

When we redeploy a smart contract , Is the smart contract updated on the same block of the blockchain or a new block is created?

Blocks once created can not be modified, hence the new deployment is stored on a new block.
user avatar
1 vote

Could a company test and compile the source code in order to create a company specific application?

Given that Gnosis safe is no longer developed It is not true. The project is being developed and maintained. All the code is open source, and you can do whatever with it as long as it doesn't ...
user avatar
  • 616
3 votes

Binary search in Solidity arrays

OpenZeppelin wrote a binary search algorithm in Solidity v0.8. Here's their implementation (code taken from here): function findUpperBound(uint256[] storage array, uint256 element) internal view ...
user avatar
0 votes
Accepted

Stuck and need another pair of eyes. Return value from decimal

From what I understand you want the first 3 decimal places from the number you put into the function. If that is the case you do not need the while, the following will do. function getNumber(uint256 ...
user avatar
0 votes

Could a company test and compile the source code in order to create a company specific application?

If you are thinking about overwriting the code on the chain - that is not possible. You are not able to "update" the code at a certain address. I don't know how Gnosis safe works internally ...
user avatar
  • 495
0 votes
Accepted

Randomly shuffling a mapping in Solidity

With your response assuming that you can use an array there is a really straight forward solution! You can use the Fisher-Yates shuffle! The jist of it is that you are gonna iterate through the full ...
user avatar

Top 50 recent answers are included