error with withdraw function unable to locate discrepencies [duplicate] - solidity

function finalizeRequest(uint index) public restricted {
Request storage request = requests[index];
require(request.approvalCount > (approversCount / 2));
require(!request.complete);
request.recipient.transfer(request.value);
request.complete = true;
}
error line ---> request.recipient.transfer(request.value);
can someone help me with this? Thank you.
solidity version I'm using:
pragma solidity >0.4.17 <0.8.0;

You need to mark the request.recipient as payable
payable(request.recipient).transfer(request.value);
From the docs page Solidity v0.8.0 Breaking Changes:
The global variables tx.origin and msg.sender have the type address instead of address payable. One can convert them into address payable by using an explicit conversion, i.e., payable(tx.origin) or payable(msg.sender).

If you are using a complier older than 0.6, you can declare recipient as address payable instead of address.
If you are using a compiler more or equal to 0.6, you can use the solution provided by #Petr Hejda.

There is no error in code its fine but upon execution i passed address then i get Error as given below in Remix ide
:status false Transaction mined but execution failed"
transact to transferEther.payBill 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.

Related

hello first of all I'm not very expert in solidity, I would like to understand what I have to correct in this contract [duplicate]

function finalizeRequest(uint index) public restricted {
Request storage request = requests[index];
require(request.approvalCount > (approversCount / 2));
require(!request.complete);
request.recipient.transfer(request.value);
request.complete = true;
}
error line ---> request.recipient.transfer(request.value);
can someone help me with this? Thank you.
solidity version I'm using:
pragma solidity >0.4.17 <0.8.0;
You need to mark the request.recipient as payable
payable(request.recipient).transfer(request.value);
From the docs page Solidity v0.8.0 Breaking Changes:
The global variables tx.origin and msg.sender have the type address instead of address payable. One can convert them into address payable by using an explicit conversion, i.e., payable(tx.origin) or payable(msg.sender).
If you are using a complier older than 0.6, you can declare recipient as address payable instead of address.
If you are using a compiler more or equal to 0.6, you can use the solution provided by #Petr Hejda.
There is no error in code its fine but upon execution i passed address then i get Error as given below in Remix ide
:status false Transaction mined but execution failed"
transact to transferEther.payBill 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.

Chainlink VRF v2 Fail

I am running script from official instruction
https://docs.chain.link/docs/chainlink-vrf/example-contracts/
when I run topUpSubscription(10000000)
but keep receiving error here
https://rinkeby.etherscan.io/tx/0xceef45073fc882c19c5be5242ee9777ea19b578193d65519fe9bfeed6c2469fc
You're trying to invoke the function topUpSubscription() that transfers LINK tokens from your contract to the COORDINATOR address.
// Assumes this contract owns link.
// 1000000000000000000 = 1 LINK
function topUpSubscription(uint256 amount) external onlyOwner {
LINKTOKEN.transferAndCall(address(COORDINATOR), amount, abi.encode(s_subscriptionId));
}
However, your contract doesn't have any LINK tokens. So the transfer fails, causing the main transaction to revert.
You can get testing LINK tokens on their faucet https://faucets.chain.link/rinkeby.

What is the input data on bsc scan?

I am developing NFT marketplace.
I have written a smart contract and passed tests using test scripts without any issue.
But when I tried to interact with my smart contract in Frontend code, I have met the error.
Here is my transaction on testnet.
https://testnet.bscscan.com/tx/0x7876b914f4417d89633a5a491bc3526e8d13a7595bb8679944b060f5b22e4a07
I have found some input data there.
Here is my contract.
function updatePrice(uint256 _elpisHeroId, uint256 _newPrice)
public
isApproved(_elpisHeroId)
{
require(_newPrice > 0, "Price should be greater than zero");
/// Identify elpisHero's index. It is the same as tokenId
uint256 elpisHeroIndex = _elpisHeroId;
/// Update metadata of a elpisHero
ElpisHeroData storage elpisHeroData = elpisHeroesData[elpisHeroIndex];
elpisHeroData.heroPrice = _newPrice;
}
As you can see in my contract, there are two parameters, _elpisHeroId, _newPrice, not _bnbPrice, _tokenPrice.
I wonder why this happens. Where do those parameters come from?

Could ChainLink facilitate getting the current Ask/Bid price from DEX?

Could ChainLink facilitate getting the current Ask/Bid price from DEX
like Binance and PancakeSwap?
"bidPrice" and "askPrice" on Binance
https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#new-order--trade
"price" on PancakeSwap
https://github.com/pancakeswap/pancake-info-api/blob/develop/v2-documentation.md
Could you show an example of how to do this?
Thank you!
If the data is accessible via an API then you can use Chainlink Any-API calls to bring it into your smart contract
To do so, you need to know 3 things
The API endpoint that contains the data, and the inputs required
The outputs that the API returns, including their types (integer, string etc), as well as the path in the resulting JSON that contains the data you want
A Chainlink oracle on the network you're contract is on that has a compatible job that you can use (whether one you run yourself or someone elses)
Once you have these things, you can use the example consumer contract in the docs linked above, and then change the values to suit. ie here is an example contract that will make an API call to PancakeSwap to get the price of PancakeSwap token on BSC testnet:
1 - API address and inputs. In this case, according to your linked docs, the URL of the API call is https://api.pancakeswap.info/api/v2/tokens/0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82. The only input required is the token address in the URL
2 - We want the price, which is an integer and in the 'price' JSON element. We will multiply the price by 10**8 when we bring it on-chain because Solidity can't handle decimals
3 - Because this is a simple API call, we can use a community run CL node that takes a HTTP GET request, parses the JSON to find an element we specify, then multiplies the result and converts it to the type we want before returning it on-chain. Taking a look at the BSC testnet jobs on market.link, I found a suitable one here (GET, multiples result, returns a uint). From here we take the job ID and the oracle address, and note the cost in LINK required to use it
Now that we have all these details, we can modify the standard API consumer contract and put them all in, as follows. Changes I made include updating variables to reflect price instead of volume, also i changed the variables for job, oracle contract and fee, and i changed the setPublicChainlinkToken() method in the contructor to setChainlinkToken, specifically passing in the address of the LINK token on BSC testnet
pragma solidity ^0.8.7;
import "#chainlink/contracts/src/v0.8/ChainlinkClient.sol";
contract APIConsumer is ChainlinkClient {
using Chainlink for Chainlink.Request;
uint256 public price;
address private oracle;
bytes32 private jobId;
uint256 private fee;
constructor() {
setChainlinkToken(0x84b9B910527Ad5C03A9Ca831909E21e236EA7b06);
oracle = 0x19f7f3bF88CB208B0C422CC2b8E2bd23ee461DD1;
jobId = "9b32442f55d74362b26c608c6e9bb80c";
fee = 0.0001 * 10 ** 18; // (Varies by network and job)
}
function requestPriceData() public returns (bytes32 requestId)
{
Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
request.add("get", "https://api.pancakeswap.info/api/v2/tokens/0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82");
request.add("path", "price");
// Multiply the result by 1000000000000000000 to remove decimals
int timesAmount = 10**18;
request.addInt("times", timesAmount);
// Sends the request
return sendChainlinkRequestTo(oracle, request, fee);
}
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId)
{
price = _price;
}
}
Once you compile and deploy, you then need to fund the contract with enough link to perform the request. You can get some testnet BSC LINK from the faucet, then transfer enough from your wallet to the deployed contract (in this case 0.001 LINK)
Once that's done you can execute the requestPriceData function, wait 30 secs then check the price getter function to see if you have a result. If you don't have a result after a while (1 min), it could mean the BSC node isn't up still. You can either run your own node, or use another network like Ethereum Kovan or Polygon Mumbai, which has many more active jobs

ERROR send and transfer are only available for objects of type address payable , not address

function finalizeRequest(uint index) public restricted {
Request storage request = requests[index];
require(request.approvalCount > (approversCount / 2));
require(!request.complete);
request.recipient.transfer(request.value);
request.complete = true;
}
error line ---> request.recipient.transfer(request.value);
can someone help me with this? Thank you.
solidity version I'm using:
pragma solidity >0.4.17 <0.8.0;
You need to mark the request.recipient as payable
payable(request.recipient).transfer(request.value);
From the docs page Solidity v0.8.0 Breaking Changes:
The global variables tx.origin and msg.sender have the type address instead of address payable. One can convert them into address payable by using an explicit conversion, i.e., payable(tx.origin) or payable(msg.sender).
If you are using a complier older than 0.6, you can declare recipient as address payable instead of address.
If you are using a compiler more or equal to 0.6, you can use the solution provided by #Petr Hejda.
There is no error in code its fine but upon execution i passed address then i get Error as given below in Remix ide
:status false Transaction mined but execution failed"
transact to transferEther.payBill 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.