I am new to solidity. I was playing around and wanted to know if I could make a contract fetch ether from one account and transfer it to another account. Thank You
how to make contract fetch ether from an account
342 views Asked by hahahoho At
2
There are 2 answers
0
Raghav Sood
On
Unless the account you are retrieving the ether from is also a contract and provides a method allowing ether withdrawal, this is not possible. A contract cannot autonomously retrieve ether from a externally owned account.
An alternative is to move your ether to the Wrapped Ether (WETH) contract, which provides you an ether-backed ERC20 token instead, which then gives you access to approve() and transferFrom()
Related Questions in ETHEREUM
- Gas estimation failed | Returned error: gas required exceeds allowance (16966)
- Historical data scrapping / collection for Ethereum
- IERC20 token.transfer always fails when called from within smart contract
- Installation Private Blockchain
- Call Uniswap V3 QuoterV2 `quoteExactOutput()` function with dart (flutter)
- Can I swap with 1inch swap apis with forked hardhart?
- Ethereum: why are the addresses still generated from the uncompressed public keys?
- WEB3.PHP Contract getEvents
- Ethereum: how to generate a valid address from the public key?
- Merkle Tree that should handle both odd and even numbers of leaves
- Uniswap v3 flashloan remainging balance not correct after paying off the loan
- Fetching Approved USDT Amount from User to Admin Wallet Using Etherscan USDT Contract Code
- How data saved using a smart contract is stored in the Ethereum blockchain
- Understanding the process of setting up a Geth client on a private network and running a DApp
- uniswapRouter.getAmountsOut returns less value of token B than present in reverses
Related Questions in SOLIDITY
- Solidity based blockchain not getting account and networkId
- unexpected keyword or identifier .ts(1434)
- Gas estimation failed | Returned error: gas required exceeds allowance (16966)
- This is the solidity code to list nft in marketplace after minting but while calling makeItem function Error is showing that Faliled to estimate gas
- My question is regarding installation of a package in VS code but im getting an error in installing it
- unsupported addressable value (argument="target", value=null, code=INVALID_ARGUMENT, version=6.11.1
- Error when deploying contract using ethers v6
- Error when fetching pending voters from smart contract using ethers.js
- IERC20 token.transfer always fails when called from within smart contract
- Solidity: How can I get an array of owners of my ERC20 and make a smart contract that uses that without exceeding the gas limit?
- Solidity call pancakeswap v3 contract exception
- Merkle Tree that should handle both odd and even numbers of leaves
- Uniswap v3 flashloan remainging balance not correct after paying off the loan
- connecting trust wallet mobile to my dapp
- Solidity Smart Contract & Hedera Hashgraph Javascript SDK Integration
Related Questions in SMARTCONTRACTS
- Gas estimation failed | Returned error: gas required exceeds allowance (16966)
- This is the solidity code to list nft in marketplace after minting but while calling makeItem function Error is showing that Faliled to estimate gas
- how i need place arg in code for funtion send?
- Uniswap v3 flashloan remainging balance not correct after paying off the loan
- Blind signing when trying to send USDT over Arbitrum network
- connecting trust wallet mobile to my dapp
- Solidity Smart Contract & Hedera Hashgraph Javascript SDK Integration
- Trying to interact with a contract using is function selector, how do i get the block hash?
- a sales tax on stonfi or dedust (The Open Network)
- After issuing the NFT smart contract I made, it cannot be viewed by OpenSea
- no scripts folder in hardhat framework instead there's ignition folder with a subfolder named modules
- Ensure smart contract integrity in web applications
- How to generate multi hop swap path with ethers.js?
- How does the fee get calculated in hardhat?
- Function for returning a wallet balance
Related Questions in ETHER
- How can i verify contract in bscscan if i was already deployed using remix.ethereum.org?
- swap doesn't working and giving error "Transaction failed"
- Calling a method in a smart contract: nonce has already been used, Nonce too low
- Got this error when getting token balances using web3
- How get signature form message forms on Netherum
- Unable to get the deployed contract address using etherjs
- How to fix "invalid transaction key: 0" error when attempting to execute gasless transactions with OpenZeppelin and ether.js?
- ethers.utils.formatEther(10000000000, "ether") not working using ether.js
- Can't start mining with geth
- Message:: invalid fragment object (argument="value", value={}, code=INVALID_ARGUMENT, version=abi/5.7.0)
- What is cheaper in gas (Ethereum): Repeated if/else statements or storing an attribute as part of a struct?
- After registry of both the consumer and prosumer properly, when I try to do the transaction, the transaction is reverted
- TypeError: Cannot read properties of undefined (reading 'inputs')
- Is it possible to use uniswap sdk with other than mainnet networks
- Calculating number of validators on dune
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
The short answer is that you cannot use a contract to fetch ether from another address. If some form of this was possible, it would be hard to prevent malicious actors from doing this to everybody.
The longer answer is that in Solidity, it is more favorable to pull transactions rather than to push them. Keeping this in mind, you should not attempt to fetch ether from an account, but rather you should design the contract in such a way that the account involved would pull their allocation out of the contract. You can do one of two things:
Both of these work, but you cannot have the contract fetch ether from the first user automatically.
There are ways where this is seemingly possible, but it is done with a pre-signed transaction from User1, which is most likely what you are not trying to achieve.