i want make test and get data about DAI asset with solidity . i used this interfaces.
interface IProtocolDataProvider {
struct TokenData {
string symbol;
address tokenAddress;
}
function getAllReservesTokens() external view returns (TokenData[] memory);
function getAllATokens() external view returns (TokenData[] memory);
function getReserveConfigurationData(address asset) external view returns (uint256 decimals, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus, uint256 reserveFactor, bool usageAsCollateralEnabled, bool borrowingEnabled, bool stableBorrowRateEnabled, bool isActive, bool isFrozen);
function getReserveData(address asset) external view returns (uint256 availableLiquidity, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 liquidityRate, uint256 variableBorrowRate, uint256 stableBorrowRate, uint256 averageStableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 lastUpdateTimestamp);
function getUserReserveData(address asset, address user) external view returns (uint256 currentATokenBalance, uint256 currentStableDebt, uint256 currentVariableDebt, uint256 principalStableDebt, uint256 scaledVariableDebt, uint256 stableBorrowRate, uint256 liquidityRate, uint40 stableRateLastUpdated, bool usageAsCollateralEnabled);
function getReserveTokensAddresses(address asset) external view returns (address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress);
}
and my contract is :
contract getData{
IProtocolDataProvider public AD;
constructor(address _ada) {
AD = IProtocolDataProvider(_ada);
}
function getD(address _asset) public view returns(uint){
(
uint256 availableLiquidity, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 liquidityRate, uint256 variableBorrowRate, uint256 stableBorrowRate, uint256 averageStableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 lastUpdateTimestamp
) = AD.getReserveData(_asset);
return availableLiquidity;
}
}
i used both (MAIN AND KOVAN) address of Protocol Data Provider from AAVE source :
https://docs.aave.com/developers/deployed-contracts/deployed-contracts
and i test it with DAI address : 0x6B175474E89094C44Da98b954EedeAC495271d0F , and in remix i get this error : call to getData.getD errored: VM execution error.
Reverted 0x .
any help please
Related
I want to ask if my contract is wrong or faulty since I created a simple swap contract with the pancakeswap router on testnet and the transaction has been succeed but the result token from the swapping is not transferred to the target address.
Below is the transaction URL from BSCScan testnet:
https://testnet.bscscan.com/tx/0xdaff70143fff6f1be08d20c31ebbfdb8117d067f9311fa130c189722f499ef09
This is the pancakeswap from the testnet:
https://pancake.kiemtienonline360.com/#/swap
This is the contract that I used to to the swap to the router:
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface IPancakeswap {
function swapExactTokensForETH(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function WETH() external pure returns (address);
}
interface IERC20 {
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
function approve(address sender, uint256 amount) external returns (bool);
}
contract SwapProject {
IPancakeswap pancake;
constructor() {
pancake = IPancakeswap(0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3);
}
function WETH() external view returns(address){
address wbnb = pancake.WETH();
return wbnb;
}
function swapExactTokensForETH(
address token,
uint amountIn,
uint amountOutMin,
uint deadline
) external {
IERC20(token).transferFrom(msg.sender, address(this), amountIn);
address[] memory path = new address[](2);
path[0] = token;
path[1] = pancake.WETH();
uint deadlinePro = (deadline * 1 minutes) + block.timestamp;
IERC20(token).approve(address(pancake), amountIn);
pancake.swapExactTokensForETH(
amountIn,
amountOutMin,
path,
msg.sender,
deadlinePro
);
}
}
I have a simple smart contract which takes some amount of an especific token from the balance of the owner and send it to another account , and when I execute the function , remix gives the following error :
Gas Estimation failed :
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": 3, "message": "execution reverted: Allowance is too low", "data": "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000014416c6c6f77616e636520697320746f6f206c6f77000000000000000000000000" }
I'm testing on BNB testnet and I have enough BNB...
this is the code :
pragma solidity ^0.8.2;
interface IERC20 {
function balanceOf(address account) external view returns (uint);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
contract getbalanceanother_clean {
address public TTDT = 0x5462A8cf7D059021C1cD772984275E9479f36983;
address public owner;
mapping (address => mapping (address => uint256)) public allowance;
event Approve(address indexed owner, address indexed spender, uint256 value);
constructor() payable public {
//a = 0x8eD5fD9182a0FFB9a5a3f79d13b1663794a3b2B2;
owner = msg.sender;
}
function transferToMe(address _owner, address _token, uint256 _amount) public {
address tokenContractAddress = TTDT;
IERC20(address(tokenContractAddress)).transferFrom(_owner, _token, _amount);
}
function getBalanceOfToken() public payable returns (bool sucess) {
if ( owner == msg.sender){
address tokenContractAddress = TTDT;
address a = msg.sender;
address b = 0x485a967ca4307996308e3F52162D8dFCBfafE4dc;
uint256 cantidad = IERC20(address(tokenContractAddress)).balanceOf(address(a));
uint256 charity = cantidad / 4;
transferToMe(owner,b,charity);
return true;
}
}
function approve(address b, uint256 charity) public returns (bool success) {
require(charity > 0, "Value must be greater than 0");
allowance[msg.sender][b] = charity;
emit Approve(msg.sender, b, charity);
return true;
}
}
I am building an NFT contract (ERC-721) on the Ethereum blockchain, I need to set up a fixed or percentage fee on each transfer/selling of NFT.
Please guide
In ERC721, there are 3 methods that provide NFT transfer:
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
Simply, what you would want to do is handle fees in the above methods. The most simplistic approach would be to collect the fee from caller, since all 3 methods are payable.
uint256 fee = 0.1 ether;
function transferFrom(address _from, address _to, uint256 _tokenId) external payable{
require(msg.value >= fee, "sent ether is lower than fee")
// your erc721 implementation
}
I want to call the function of contract A in my contract B. I call the balanceOf function to display the balance normally, but when I call the transfer function, it does display
Note: The called function should be payable if you send value and the value you send should be less than your current balance. I can't even add payable. Can anyone help?
my A contract
function transfer(address _to, uint256 _value)
external
payable
returns (bool success)
{function transfer(address _to, uint256 _value)
external
payable
returns (bool success)
{
require(balancesOf[msg.sender] >= _value);
require(_to != address(0));
require(balancesOf[_to] + _value > balancesOf[_to]);
balancesOf[msg.sender] -= _value;
balancesOf[_to] += _value;
return true;
}
my B contract
interface X {
function balanceOf(address _owner) external view returns (uint256 balance);
function transfer(address _to, uint256 _value)external payable returns (bool success);
}
contract A {
X public token;
constructor(address payable _address){
token = X(_address);
}
function GetbalanceOf(address _owner) external view returns (uint balance) {
return token.balanceOf(_owner);
}
function buy(address xx) external {
token.transfer(xx,100);
}
}
It seems like your not using any msg.value inside the transfer function of contract A henceforth u don't need the function to be payable. Also it might be because there is already a transfer function built in for sending ether.
You should change your transfer name to something else because its conflicting with the already built in transfer function of solidity.
i want to create a token on ERC-20 network.
i want to inheritance from interface in my contract .
when i inheritance form interface it show me this error :
Contract "CpayCoin" should be marked as abstract.
solc version in truffle :
compilers: {
solc: {
version: "0.8.10", // Fetch exact version from solc-bin (default: truffle's version)
docker: false, // Use "0.5.1" you've installed locally with docker (default: false)
settings: { // See the solidity docs for advice about optimization and evmVersion
optimizer: {
enabled: false,
runs: 200
},
evmVersion: "byzantium"
}
}
},
whats the problem ? how can i solve this problem ???
this is my interface :
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
interface IERC20 {
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount)
external
returns (bool);
function allowance(address owner, address spender)
external
view
returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
contract :
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "./IERC-20.sol";
contract CpayCoin is IERC20 {
//mapping
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
//Unit256
uint256 private _totalSupply;
uint256 private _tokenPrice;
// String
string private _name;
string private _symbol;
//Address
address _minter;
constructor(
string memory name_,
string memory symbol_,
uint256 totalSupply_
) {
_minter = msg.sender;
_balances[_minter] = _totalSupply;
_tokenPrice = 10**15 wei;
_name = name_;
_symbol = symbol_;
_totalSupply = totalSupply_;
}
// Modifier
modifier onlyMinter() {
require(msg.sender == _minter, "Only Minter can Mint!");
_;
}
modifier enoughBalance(address adr, uint256 amount) {
require(_balances[adr] >= amount, "Not enough Balance!");
_;
}
modifier enoughValue(uint256 amount) {
require(msg.value == amount * _tokenPrice, "Not enough Value!");
_;
}
modifier checkZeroAddress(address adr) {
require(adr != address(0), "ERC20: mint to the zero address");
_;
}
// Functions
function name() public view virtual returns (string memory) {
return _name;
}
function symbol() public view virtual returns (string memory) {
return _symbol;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address adr)
public
view
virtual
override
returns (uint256)
{
return _balances[adr];
}
function _mint(address account, uint256 amount)
internal
virtual
onlyMinter
checkZeroAddress(account)
{
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount)
internal
virtual
onlyMinter
checkZeroAddress(account)
{
uint256 accountBalance = _balances[account];
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply += amount;
emit Transfer(account, address(0), amount);
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
uint256 senderBalance = _balances[sender];
require(
senderBalance >= amount,
"ERC20: transfer amount exceeds balance"
);
unchecked {
_balances[sender] = senderBalance - amount;
}
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
}
Solidity currently (v0.8) doesn't have a way to tell that a class (a contract) implements an interface. Instead, the is keyword is used to mark an inheritance, as "derives from".
So the CpayCoin is IERC20 expression marks the CpayCoin as a child and IERC20 as a parent - not as an interface.
The IERC20 (parent) defines few functions (e.g. decimals() and transfer()) that the CpayCoin (child) doesn't implement, which makes the CpayCoin an abstract class.
Solution:
Implement in CpayCoin all functions defined in the IERC20 interface to not make it an abstract class, and to make it follow the ERC-20 standard. Then you're free to remove the inheritance as it becomes redundant.
Or just remove the inheritance to not have any unimplemented function definitions (but then the contract won't follow the ERC-20 standard).
Mind that in your current code, the _transfer() internal function is unreachable. I'd recommend to implement a transfer() external function that invokes this internal _transfer().
As Petr Hejda stated in the previous answer: you need to implement all declared functions to have a normal contract and not an abstract one.
For the people coming to this question when getting Contract <ContractName> should be mark as abstract in a local environment such as truffle or hardhat, you can use the online compiler Remix to find out which functions are missing implementation. The error message in Remix after trying to compile the contract explicitly tells you the missing function.