I'm trying to fund a smart contract with LINK tokens. I get an error "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." My code is simple:
// SPDX-License-Identifier: MIT
pragma solidity >=0.5 <0.9.0;
//Remix Imports
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/vendor/Ownable.sol";
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/vendor/SafeMathChainlink.sol";
import "https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/interfaces/LinkTokenInterface.sol";
import "https://github.com/smartcontractkit/chainlink/blob/master/evm-contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract SimpleStorage {
SimpleStorage2[] simpleStorage2s;
function set() public payable returns(address) {
SimpleStorage2 a = new SimpleStorage2();
simpleStorage2s.push(a);
LinkTokenInterface link = LinkTokenInterface(a.getChainlinkToken());
link.transfer(address(a), 100);
return address(a);
}
}
contract SimpleStorage2 is ChainlinkClient, Ownable {
function getChainlinkToken() public view returns (address) {
return chainlinkTokenAddress();
}
}
Solidity compiler 0.6.12. What am I doing wrong? How do I get this to work?
Get the address of the contract that you've deployed, and send it LINK.
You can read the Chainlink documentation for more information.
It looks like you're using remix.
Get the address of your contract.
Paste it into your Metamask
3. Send your contract LINK
You'll get a few notifications to confirm.
Related
Assuming I have a wallet, I want to authorize another wallet to send a transfer on my behalf, how do I implement the above using the following practice.
pragma solidity ^0.8.0;
import 'Token.sol';
contract TransferToken{
function transferFrom(address recipient, uint amount) external {
Token token = Token(0xd9145CCE52D386f254917e481eB44e9943F3555);
token.transferFrom(msg.sender, recipient, amount);
}
}
contract Owner {
function transfer(address recipient, uint amount) external {
Token token = Token(0xd9145CCE52D386f254917e481eB44e9943F39138);
token.approve(0x617F2E2fD72FD9D5503197092aC168c91465E7f2, amount);
TransferToken transferToken = TransferToken(0x617F2E2fD72FD9D5503197092aC168c91465E7f2);
transferToken.transferFrom(recipient, amount);}}
in the above example, i am using the openZappelin implementation for ERC20 on the import (Token.sol)
now my question is this ... since I want to use a real wallet with ERC20 token how do I implement the above example, I am thinking for this I don't need the import anymore, but I don't know how to implement it without too many mistakes already, I very new to solidity and I am using remix for the above implementation
will be glad if i could get a help on this
While attempting to fund me contract is tell me it encountered an error without specifying the error. I attempted to fund 0.1 eth through the fund function, and in the terminal it says:
[block:8404521 txIndex:12]
from: 0x8a9...e4303
to: FundMe.fund() 0x542...E109C
value: 100000000000000000 wei
data: 0xb60...d4288
logs: 0
hash: 0x29a...97939
and in the etherscan it says:status fail :
Contract 0x5422f3458be343e378e7a399e16fff548e7e109c
Warning! Error encountered during contract execution [execution reverted]
I tried looking for problems with my code and found none.
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.6 <0.9.0;
import "#chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
//import "#chainlink/contracts/src/v0.8/vendor/SafeMathChainlink.sol"; won't need in later complier versions.
contract FundMe {
mapping(address => uint256) public addressToAmountFunded;
function fund() public payable {
uint256 minimumUSD = 50 * 10 ** 18;
require( getConversionRate(msg.value) >= minimumUSD,"You need to send more Eth");
addressToAmountFunded[msg.sender] += msg.value;
}
function getVersion() public view returns (uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
return priceFeed.version();
}
function getPrice() public view returns (uint256){
AggregatorV3Interface priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
(,int256 answer,,,)=priceFeed.latestRoundData();
return uint256(answer * 10000000000);
}
//10000000000 = Gwei which is why we added 10 zeros to getPrice(answer) to convert it to Wei amount
function getConversionRate(uint256 ethAmount) public view returns (uint256){
uint256 ethPrice = getPrice();
uint256 ethAmountInUsd = (ethPrice * ethAmount)/ 1000000000000000000; //divide 2x because we added 10*((getPrice)answer))
return ethAmountInUsd;
}
}
Aggregator contract address "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" belongs to mainnet
From here get the ETH/USD goerli testnet address:"0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e"
Now in order to call chainlink oracle you have to have LINK token in your contract. Get some link token to your conract address from the faucet
Import the token in metamask. you will see the amount
send link token from your metamask to your contract
deploy your contract. if you are using Remix IDE chose the injected provider to connect to metamask. Because chainlink contract is on goerli, so you need to be on Goerli testnet. Once deployment goes through you can call the fund function.
Since the fund function has no argument, you need to send the value alongside the transaction. That is why inside the function you have msg.value to access to the sent amount.
In Remix ide, under "GAS LIMITinput there isVALUEinput. you need to pass the amount in there before you call thefund` function.
I want to transfer some ether form my address to the smart contract, I have tried the code below but it doesn't work. How to transfer ether through msg.sender?
pragma solidity >=0.7.0 <0.9.0;
contract Test {
function testTransfer() external payable {
bool sent = payable(address(this)).send(msg.value);
require(sent, "invalid balance");
}
}
Once I trigger the function with the value of 1 ether, the error output is as below:
I'm sure that I have enough Ether in my address. What should I do to transfer the Ether? Thanks!
The transaction fails because the smart contract is trying to transfer the ether to himself, and the smart contract doesn't have defined the receive function so it can receive ether that way, for your example you could simply remove all the code inside the function and make another function to check the contract balance and it will work
pragma solidity >=0.7.0 <0.9.0;
contract Test {
function testTransfer() external payable {}
function getBalance() external view returns (uint256) {
return address(this).balance;
}
}
I want to make a smart contract that deposits UST on the eth anchor protocol, by using the deposit function. Here you can find the docs of this function I try to call. https://docs.anchorprotocol.com/ethanchor/ethanchor-contracts/router . The function gets called trough a proxy contract. I found the implementation address by reading the proxy contract on etherscan.
TestContracts on Ropsten testnet:
proxy: 0x7537aC093cE1315BCE08bBF0bf6f9b86B7475008
etherscan: https://ropsten.etherscan.io/address/0x7537aC093cE1315BCE08bBF0bf6f9b86B7475008
implementation (ROUTERV2): 0x2ba0010394eb3e41454c7d79c0fb6e0deb67284b
etherscan: https://ropsten.etherscan.io/address/0x2ba0010394eb3e41454c7d79c0fb6e0deb67284b
I imported the ROUTERV2 contract for calling the proxy with the abi of the implementation.
my execution order is:
deploying the contract
approving the contract for spending the tokens from the sender using ethers.
approveUST function on smart contract (I am not sure if this is necessary)
calling the depositStable function.
I get the following error when calling the depositStale function UNPREDICTABLE_GAS_LIMIT;
Below You see the contract I try to make. It should take the UST of the user and deposit it on eth anchor.
Here is a github link to the hardhat repo of the contract so you can simulate the bug and hopefully help me solving this issue.
https://github.com/tijgersoftware/Terra-anchor
I thank you for taking the time to read my question!
contract Anchor {
address public proxy;
address public operator;
address public USTAddress;
constructor(
address proxy_,
address operator_,
address USTAddress_
) public {
proxy = proxy_;
operator = operator_;
USTAddress = USTAddress_;
}
function approveUST() public {
ERC20(USTAddress).approve(
address(this),
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
);
}
function initDepositStable(uint256 amount) public {
RouterV2(proxy).initDepositStable(amount);
}
function depositUST(uint256 amount) public {
// InterfaceOfImplementationContract(proxyAddress).MethodBeingCalled(
// parameter,
// parameter,
// parameter
// );
ERC20(USTAddress).approve(
address(this),
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
);
RouterV2(proxy).depositStable(operator, amount);
}
}
tags: solidity, smart contracts, ethereum, anchor protocol, terra, brdige trasfer.
I've deployed the ScoreStore contract to test RPC, and it works fine. This is ScoreStore contract:
pragma solidity ^0.4.4;
contract ScoreStore
{
mapping(string => int) PersonScores;
function SetScore(string name, int score) {
if(PersonScores[name]>0){
throw;
}
else{
PersonScores[name] = score;
}
}
function GetScore(string name) returns (int){
return PersonScores[name];
}
}
Now I want to use this contract on another contract named MyGame, the contract code is as follows:
pragma solidity ^0.4.4;
contract IScoreStore{
function GetScore(string name) returns (int);
}
contract MyGame{
function ShowScore(string name) returns (int){
// Interface takes an address of the existing contract as parameter
IScoreStore ss = IScoreStore(0x6c38cfb90e8fb1922e61ea4fbe09d29c7751bf82);
return ss.GetScore(name);
}
}
When I give this command on truffle console, mg.ShowScore.call("Anna")
it thorws this:
Error: VM Exception while processing transaction: revert
at XMLHttpRequest._onHttpResponseEnd (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:509:1)
at XMLHttpRequest._setReadyState (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:354:1)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2\lib\xhr2.js:64:1)
at XMLHttpRequest.request.onreadystatechange (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\httpprovider.
at C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\truffle-provider\wrapper.js:134:1
at C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\requestmanager.js:86:1
at Object.InvalidResponse (C:\Users\Fariha.Abbasi\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3\lib\web3\errors.js:38:1)
Any idea, what i am doing wrong?
Any help is appreciated, P.S: testrpc is already running.
I was able to compile both the contracts in remix and call the ShowScore function after setting some value from ScoreStore contract successfully.
Are you sure the address given to the interface is correct? Because I got the same revert error when I gave an invalid address.