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

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.

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.

Unable to deploy smart contract to Polygon, Gas estimation error, Internal JSON-RPC error

Good afternoon,
I am new to Polygon (but have some Ethereum experience) and I am attempting to deploy the smart contract from the chainlink documentation https://docs.chain.link/docs/fulfilling-requests/ on the Polygon MUMBAI testnet, using remix as my in browser IDE.
I initially attempted to launch the original contract, as published in the docs. I got this error message:
"Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" }"
When that failed, I trimmed it down to a smaller, more bare bones contract (in case there is a smart contract size limit on Polygon). Here is the trimmed down code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "#chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "#chainlink/contracts/src/v0.8/ConfirmedOwner.sol";
contract ATestnetConsumer is ChainlinkClient, ConfirmedOwner {
using Chainlink for Chainlink.Request;
uint256 constant private ORACLE_PAYMENT = 1 * LINK_DIVISIBILITY/10;
uint256 public currentPrice;
int256 public changeDay;
bytes32 public lastMarket;
event RequestEthereumPriceFulfilled(
bytes32 indexed requestId,
uint256 indexed price
);
constructor() ConfirmedOwner(msg.sender){
setPublicChainlinkToken();
}
function requestEthereumPrice(address _oracle, string memory _jobId)
public
onlyOwner
{
Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(_jobId), address(this), this.fulfillEthereumPrice.selector);
req.add("get", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD");
req.add("path", "USD");
req.addInt("times", 100);
sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
}
function fulfillEthereumPrice(bytes32 _requestId, uint256 _price)
public
recordChainlinkFulfillment(_requestId)
{
emit RequestEthereumPriceFulfilled(_requestId, _price);
currentPrice = _price;
}
function getChainlinkToken() public view returns (address) {
return chainlinkTokenAddress();
}
function withdrawLink() public onlyOwner {
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer");
}
function cancelRequest(
bytes32 _requestId,
uint256 _payment,
bytes4 _callbackFunctionId,
uint256 _expiration
)
public
onlyOwner
{
cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
}
function stringToBytes32(string memory source) private pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}
assembly { // solhint-disable-line no-inline-assembly
result := mload(add(source, 32))
}
}
}
But I get the same error. My wallet is funded with MATIC and LINK on polygon (mumbai). I am able to deploy the oracle contract to the mumbai testnet (and can see it on polygon scan https://mumbai.polygonscan.com/address/0x078cF10C20f7A8aac7b49F078B38007A49334b96 ), so it appears its all set up correctly, just for some reason this contract errors out.
I also increased the max gas I was willing to pay, I have attempted to just push the transaction through (it mines but the resulting contract fails to have any data https://mumbai.polygonscan.com/address/0xb9bc5681a15353c9b1b19d3db097323b92137ddd ).
I was also able to deploy a contract that does does not use Oracles but is a working contract (on Rinkeby) to Mumbai, further indicating its specific to this contract, or the Chainlink infrastructure on Polygon in general.
Side note, I am attempting to run and use my own Chainlink node on Polygon, but that should not be effecting this issue, as in this demo contract you send the node info and the job ID as parameters when you make a call to this function, its not in the smart contract itself.
What I have considered is wrong:
-Contract size is too big (even after I trimmed it down??)
-MATIC is not the only currency for gas on polygon?
-There is an unknown error in the Chinlink Documentation
-Something unique about Polygon is throwing an error
Thanks!
After going through and commenting line by line, I was able to track down the code that was at fault. I had gone in and changed the LINK address in ChainlinkClient.sol to the mumbai LINK address. As written, the demo code calls setPublicChainlinkToken(); which then assigns the stored value as the link token address. Changing that value to the correct address did not solve my issue. Instead, I used setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB); and that has cleared up my issue.

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?

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

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.

VM Exception while processing transaction: revert

I have 2 Contracts. One is an ERC721 Token (NFTCollectables). The other one is a market including an auction system (NFTMarket).
An auction can be claimed after it ended and only by the highest bidder.
When claiming an auction the transfer method of the NFTCollectables contract is called to transfer the NFT from the markets address to the address of the highest bidder.
I do not exactly understand why the exception comes, but it occurs at/inside the transfer method of the NFTCollectables contract. The strange thing is that even the last line of code inside the transfer method is getting executed (tested by putting a require(false, 'test') after _transfer(msg.sender, to, nftId)). But nothing after ctr.transfer(auction.highestBid.bidder, auction.nftId) is getting executed (tested by putting a require(false, 'test') after it).
Could it have to do with the gas limit?
Any idea is appreciated, thanks!
NFTMarket
function claimAuction(uint auctionIndex) external {
require(auctionIndex < auctions.length, "no auction");
Auction memory auction = auctions[auctionIndex];
require(block.timestamp <= auction.end, "auction still active");
NFTCollectables ctr = NFTCollectables(nftCollectablesAddress);
ctr.transfer(auction.highestBid.bidder, auction.nftId);
// deleting auction from active auctions list
for (uint i; i < activeAuctionIndexes.length; i++) {
if (activeAuctionIndexes[i] == auctionIndex) {
delete activeAuctionIndexes[i];
break;
}
}
emit AuctionEnd(auction.highestBid.bidder, auction.highestBid.price, auction.nftId);
}
NFTCollectables
function transfer(address payable to, uint nftId) external payable {
require(_exists(nftId), "transfer of non existing token");
require(_isApprovedOrOwner(msg.sender, nftId), "Sender not approved nor owner");
_transfer(msg.sender, to, nftId);
}
If you have deployed the contracts on the public network, like mainnet or testnet, use https://tenderly.co or EtherScan to debug the revert reason.
If you are running the contracts using unit tests then keep modifying the contracts e.g. by removing lines to see when it starts failing. Or alternatively use a better smart contract development framework like Brownie which will give you the cause of revert right away.
We had implemented a function on our codebase that i can share with you. This function is used to transfer ownership of nft to who wins the auction.
function transferNFTtoNewOwner(NFTItem memory t,address oldOwner, address newOwner) internal {
require(newOwner != address(0), "New owner can't be address zero.");
XXXX storage r = creatureList[t.tokenAddress][t.tokenId];
IERC721 nft = IERC721(t.tokenAddress);
nft.safeTransferFrom(oldOwner, newOwner, t.tokenId);
address currOwner = nft.ownerOf(t.tokenId);
require(newOwner == currOwner, "Problem on nft transfer");
r.owner = newOwner;
}
The major differences are we used safetransferfrom here. If your contract owns the NFT then you can call safeTransfer. and after that we checked the nft owner with require statement. If you put this statement and change your transfer function to safetransfer and the transaction still revert without giving any error on etherscan then you can investigate about your nft contract.