3 votes

Implement smart contract that can spend user's tokens with just one approve

This is part of the ERC20 specification. See here, the transferFrom() function. https://eips.ethereum.org/EIPS/eip-20#methods Users send a transaction to the token contract to approve your contract to ...
Rob Hitchens's user avatar
  • 54.8k
2 votes

Implement smart contract that can spend user's tokens with just one approve

As Rob Hitchens said, this is an already existing feature of Erc20 tokens. However, i would like to add that you can't do that with ETH, since it's not a token. But you can do this with wrapped eth, ...
Yann's user avatar
  • 56
2 votes

Eth price dont update after another function iteration

Ethereum generates a new block every ~12 seconds. All on-chain data remains the same during the interval. So, it is normal to have no updates in 5 seconds.
0xsam's user avatar
  • 81
1 vote

Avoiding loops in Solidity for a simple situation

Looping through all users is not just very gas inefficient, it may become impossible once your contract has a lot of users and the looping consumes more gas than the block gas limit. I would recommend ...
merkleplant's user avatar
1 vote

Prices on Dexes

Price can change only between blocks. On ethereum a block lasts 12 seconds, during which the price doesn't change. Also if no trade happens in a block, the price still doesn't change. You're ...
0xSanson's user avatar
  • 2,774
1 vote
Accepted

What's the best way to raise a number to the power of a fractional exponent in Solidity

You can achieve this with the pow function of PRBMath. Here's an example: pragma solidity >=0.8.22; import { UD60x18, ud } from "@prb/math/src/UD60x18.sol"; contract Foo { function ...
Paul Razvan Berg's user avatar
1 vote
Accepted

How to decode storage value of a struct

First of all, a struct is just the logical grouping, from the storage perspective the structs can be omitted. So just the variables/property types define how the storage is packed. A slot occupies ...
tenbits's user avatar
  • 2,004
1 vote

Adding Uniswap interface to a ERC20 token smart contract

Some tokens create their a token pair and register it with uniswap. They implement some form of integration with the token pair, like charging a percentage for fees or dynamically adjusting the token ...
Ismael's user avatar
  • 31k
1 vote
Accepted

Im trying to build a cryptocurrency(USD tether just like USD) that works with ethereum and polygon,

The simplest way to create a token with solidity is to inherit ERC20 contract and add whatever features you want. https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/...
0xsam's user avatar
  • 81

Only top scored, non community-wiki answers of a minimum length are eligible