msg.value raises error and doesn't send eth to contract - blockchain

I am trying to write a simple Contract in Remix and cannot find a solution for the following problem: Trying to transfer a specific amount of Ethereum to the contract.
The contract compiles and deploys without any problems.
But when I try to call the function I get the following error message you can see on the picture below. The problem can't be not enough Ethereum, I got about 2 Ethereum on the Rinkeby Testnetwork.
https://i.stack.imgur.com/a2hXj.png
I can click on "Send Transaction" which will open up Metamask:
https://i.stack.imgur.com/vba66.png
And after a few seconds the transaction fails... :
https://i.stack.imgur.com/pT9hy.png
I am using the msg.value() function. My code is the following:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
contract Contract {
function sendEth() public payable {
require(msg.value > .02 ether, "Not enough ETH");
}
}
If anyone got a hint, I would really appreciate it, cause I am on it for way too long now.

The third screenshot shows that you're sending 0 wei along with the transaction. So the require condition in your Solidity code fails, as 0 is not more than 0.02 ether.
A contract is not able to pull any ETH from your wallet - you need to specify how much you want to send with the transaction.
In Remix, there's a "Value" input in the "Deploy and run transactions" tab that allows you to specify the amount.

Related

transfer token out of contract

i had a small question that i creast a contract A and there is 1 busd token in the contract A, now i want to transfer the 1 busd out of contract by owner address
how to set the contractA?
i have use this code to deploy and test
pragma solidity ^0.8;
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
}
contract MyContract {
address owner = 0xFAD69bCefb704c1803A9Bf8f04BC314E78838F88;
function withdrawToken(address tokenContract, uint256 amount) external {
// send `amount` of tokens
// from the balance of this contract
// to the `owner` address
IERC20(tokenContract).transfer(owner, amount);
}
}
the feedback is
This contract may be abstract, it may not implement an abstract parent's methods completely or it may not invoke an inherited contract's constructor correctly.
can someone help me? thanks in advance , i am beginner.
find a way to transfer the busd out of contract .
I recognize this code from my other answer. :)
You're trying to deploy the IERC20 interface - which throws the "This contract may be abstract" error.
You need to deploy the other contract. Depending on how you deploy the contract, there are different ways to do that.
Here's another answer that shows how to select the desired contract in Remix IDE. However, note that this code won't work on the Remix emulated network, as the BUSD contract is not available there. You'll need to deploy the code either to the mainnet or your local fork of the mainnet, where the BUSD contract is available.

address.call.value(amount)( ) method is not working with me

I've written a very simple method in solidity to send Ethereum to account but unfortunately it is not working
(ALREADY TRIED SEND AND TRANSFER METHOD)
function sendByCallValue(address payable _receiver, uint _amount) public payable {
(bool success, ) = _receiver.call{value:_amount}("");
require(success, "Transfer failed.");
}
I'm calling this function from REMIX IDE by passing an address and amount but it is throwing error.
In pic you will find this:
to : NftStaker.sendByCallValue(address,uint256) 0xEf9f1ACE83dfbB8f559Da621f4aEA72C6EB10eBf
which I think should be like this
to : 0xEf9f1ACE83dfbB8f559Da621f4aEA72C6EB10eBf
I'm not sure which thing is throwing error.
The transaction output shows that you're passing 0 wei along with the transaction, and trying to send 10 wei from the contract address.
It doesn't show how much the contract owns, but assuming it's less than 10 wei, the transaction fails because the .call() is trying to send from the contract more than it owns.
You can specify the value to send along with the transaction in the "Deploy & run transactions" of the Remix IDE.

What changed with solidity this Sunday? Contract deployment is not working anymore with "function should be payable" error

I was successfully testing my smart contract using remix editor, and starting this weekend my contract is not deploying anymore, even I have not applied any changes to it.
This is the part of the code which fails while I debug the error (marked line #5):
1 constructor(address _router) public ERC20("Test Token", "TEST") payable {
2 IUniswapV2Router02 _uniswapV2Rtr = IUniswapV2Router02(_router);
4
5 address _uniswapV2Pair = IUniswapV2Factory(_uniswapV2Rtr.factory()).createPair(address(this), _uniswapV2Rtr.WETH());
6 ...
7 }
Deployed gives me this error:
creation of TestToken errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
I don't understand what has been changed on deployer, and debugger does not specify which function should be defined as payable. And code was working perfectly before this Sunday. Which function deployer want me to make payable? And why this happens that code was working before? Does solidity applied some changes on the engine?

how to solve type error in solidity Remix

my solidity smart contract is compiling in remix with out any error .
my contract code is below:
pragma solidity >=0.4.0 <0.6.0;
contract NewConreact {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}
it is compiling in remix perfectly but when i run it to triger set() and get()i got:
"error: Failed to decode output: TypeError: Cannot read property
'length' of undefined"
this error.
I found a closed issue in solidity git repo but didn't find any solution.
I also increase the gas limit but didn't work.
somebody, please help me to figure out the problem.
This normally happens when the deployment is failing with unknown reasons - may be you tried with Injected web3 or web3 provider like Ganache-cli and it somehow failed deployment and however the contract interface was still appended to the UI. This could have made you confuse that the contract got deployed correctly.
The work around is to view and expand the log output of the transaction for deploying the contract. Make sure your contract is successful before doing transactions.
Please provide your logs if you are still unable to do the transactions even after you have deployed the contract successfully.
Try using Chrome, avoid Safari, and be sure to remove the "s" from the solidity Remix site > won't work > https://remix but http://remix will. Once I moved to Chrome it worked

Error sending value to Ethereum smart contract

I have geth 1.5.2 and work on testnet with Mist-linux64-0-8-7. I stuck at a simple issue when I try to send some ether (value) to my contract by calling any function.
For example, even this dummy function does not work with non-zero value but works normally with zero value:
function t() returns (uint){
return 1;
}
What is surprising here that I can see a warning in Mist with the message "It seems this transaction will fail. If you submit it, it may consume all the gas you send."
This does not depend on the gas amount that I provide.
Even if I put 500,000 of gas the transaction seem not to complete.
You can see its result here:
https://testnet.etherscan.io/tx/0x3206118530079d1b416dc649c6f0a89283f9457e9189f259b3429cf0c6a998d0
There is a message
Warning! Error encountered during contract execution [Bad jump
destination]
I tried to run different functions in different contracts. I was even using sendTransaction functionality to do the same from geth console directly but I still can't make it work.
I didn't find if anybody had similar problem. Please help me if you have any idea.
From Solidity 0.4 onwards:
Functions that want to receive Ether have to specify the new payable
modifier (otherwise they throw).
A throw consumes all gas, so use function t() payable returns (uint).