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 ...
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, ...
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.
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 ...
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 ...
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 ...
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 ...
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 ...
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/...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
solidity × 17441contract-development × 2572
remix × 2443
web3js × 1689
truffle × 1209
contract-design × 1144
blockchain × 960
go-ethereum × 938
erc-20 × 919
tokens × 771
hardhat × 605
gas × 515
contract-deployment × 495
ether × 486
ethers.js × 484
javascript × 466
arrays × 456
evm × 431
nft × 409
mapping × 403
transactions × 402
erc-721 × 372
struct × 363
contract-invocation × 362
uniswap × 357