after fallback active , how to continue - ethereum

I read on internet ,after call a nonfounction in contract , that fallback will be active.
address app is a empty contract .
address token is busd contract .
address app = 0x85a389C274c62F5108E662F017C04FE22d574483 ;
address token= 0x55d398326f99059fF775485246999027B3197955;
address sender appoved 1 busd to empty contract app already
now i call from
app.call(abi.encodeWithSignature("transferFrom(address sender, address recipient, uint256 amount)", sender, recipient,amount));
due to app is empty , so the fallback will be actived , and msg.sender is contract app. and msg.data istransferFrom(address sender, address recipient, uint256 amount)
then going to call another
token.call(abi.encodeWithSignature("transferFrom(address sender, address recipient, uint256 amount)", sender, recipient,amount));
at this monment : msg.sender should be address app, msg.data is still "transferFrom(address sender, address recipient, uint256 amount)" and sender already appoved 1 busd to the address app. so it should be working well
here is the full cold .
pragma solidity ^0.8;
interface IERC20 {
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 callnmblq {
address app = 0x85a389C274c62F5108E662F017C04FE22d574437 ;
address token= 0x55d398326f99059fF775485246999027B3197955;
function transferFrom( address sender, address recipient, uint256 amount) external {
bool success;
(success, ) =app.call(abi.encodeWithSignature("transferFrom(address sender, address recipient, uint256 amount)", sender, recipient,amount));
require(success,"fall to transferFrom");
(success, ) =token.call(abi.encodeWithSignature("transferFrom(address sender, address recipient, uint256 amount)", sender, recipient,amount));
require(success,"fall to transferFrom");
}
}
help to check the logic.if i understand well at the seconder call msg.sender and msg.data.
help to understand after fallback active , how to continue contract.
help how to make this transferFrom working .
by the way the feedback is
transact to callnmblq.transferFrom errored: Internal JSON-RPC error.
{
"code": 3,
"message": "execution reverted: fall to transferFrom",
"data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001466616c6c20746f207472616e7366657246726f6d000000000000000000000000"
}
gaslimited

Related

should I emit Transfer event in this balance change (ERC20)?

function _transferStandard(
address sender,
address recipient,
uint256 tAmount
) private {
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tTeam
) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
_takeTeam(tTeam);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
function _takeTeam(uint256 tTeam) private {
uint256 currentRate = _getRate();
uint256 rTeam = tTeam.mul(currentRate);
_rOwned[address(this)] = _rOwned[address(this)].add(rTeam);
}
For this line, _rOwned[address(this)] = _rOwned[address(this)].add(rTeam);
This code snippet is quite common among many ERC20 implementation (Does anyone know where it came from?), is this expected behavior or not?
According to the doc: https://eips.ethereum.org/EIPS/eip-20,
The transfer event MUST trigger when tokens are transferred. I assumed that this line of code represents the balance transfer from sender to the address(this). But it does not emit a Transfer event.

Swapping using Uniswap

Here is my code:
// SPDX-License-Identifier: UNLICENCED
pragma solidity <0.9.0;
interface UniswapInterface{
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
}
interface IERC20{
function balanceOf(address account) external view returns (uint256);
function decimals() external view returns (uint8);
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);
}
contract swapContract{
address public UniSwapRouterAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
address public USDCAddress = 0x2fB298BDbeF468638AD6653FF8376575ea41e768;
address public BTCAddress = 0x577D296678535e4903D59A4C929B718e1D575e0A;
IERC20 USDC = IERC20(0x2fB298BDbeF468638AD6653FF8376575ea41e768);
IERC20 BTC = IERC20(0x577D296678535e4903D59A4C929B718e1D575e0A);
UniswapInterface UniSwapRouter = UniswapInterface(UniSwapRouterAddress);
function approveUSDC() public{
USDC.approve(UniSwapRouterAddress, 999**9);
}
function approveBTC() public{
BTC.approve(UniSwapRouterAddress, 999**9);
}
function deposit(uint256 amount) public{
require(amount > 0, "0 is not accepted!");
uint256 allowance = USDC.allowance(msg.sender, address(this));
require(allowance >= amount, "Check USDC allowance");
USDC.transferFrom(msg.sender, address(this), amount);
}
function withdraw() public {
USDC.transfer(msg.sender, USDC.balanceOf(address(this)));
}
function swapUSDC() public {
address[] memory Path = new address[](2);
Path[0] = USDCAddress;
Path[1] = BTCAddress;
UniSwapRouter.swapExactTokensForTokens(
100000000,
0,
Path,
address(this),
block.timestamp + 240
);
}
}
I simply want to swap 1 USDC (its decimal is 8) to BTC on Rinkeby testnetwork.
I tried so many changes like increasing deadline, change in amountIn and amountOutMin but no gain. Also the pool on Uniswap has liquidity.
The error just says:
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
execution reverted
I have checked the stackoverflow for answer but could not find a solution
I tried to figure out what the problem might be and realized that most likely there is no such pool.
If you go to the Uniswap UI, you will see that the pool was created only for V3, and you are trying to use the V2 address of router.
There are two ways to solve the problem, the first is to create a liquidity pool in V2 or to make an exchange through V3.

Custom token showing balance of 0 in MyEtherWallet

I made a new token on the Ropsten test network. Here's the contract address: 0x801fd9c17087ec868dc8540055b7ea3cb6dbbe34.
When I followed the instructions to add this custom token to MyEtherWallet (by specifying the contract address, symbol and correct number of decimals), I see that my ICICB token is added to the token list. However, the balance says 0, even though I have sent some tokens to my address. Also, when I try to select the ICICB token from the dropdown menu to send it, it doesn't show up (just Eth shows up).
When you look at https://ropsten.etherscan.io/address/0x411724F571e83D5fa74d42462F0cAFBddDfed5fc which is my MyEtherWallet address, you can see that is has 2,000,000 ICICB tokens.
Could you please explain to me what's going on? Maybe I'm missing something.
I also, looked at this thread, but it seems to me that my token is ERC20 compliant, as I have all of the necessary functions.
Here's my contract:
pragma solidity ^0.4.24;
// ----------------------------------------------------------------------------
// 'ICICB' token contract
//
// Deployed to : 0x9f7bb2e565F94C3FF3e365eb95cAF73b458b2149
// Symbol : ICICB
// Name : ICICB Token
// Total supply: 100000000
// Decimals : 18
//
// Enjoy.
// (c) by Moritz Neto with BokkyPooBah / Bok Consulting Pty Ltd Au 2017. The MIT Licence.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a);
c = a - b;
}
function safeMul(uint a, uint b) public pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint a, uint b) public pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// Contract function to receive approval and execute function in one call
//
// Borrowed from MiniMeToken
// ----------------------------------------------------------------------------
contract ApproveAndCallFallBack {
function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
address public newOwner;
event OwnershipTransferred(address indexed _from, address indexed _to);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) public onlyOwner {
newOwner = _newOwner;
}
function acceptOwnership() public {
require(msg.sender == newOwner);
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ----------------------------------------------------------------------------
contract ICICBToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "ICICB";
name = "ICICB Token";
decimals = 18;
_totalSupply = 100000000000000000000000000;
balances[0x9f7bb2e565F94C3FF3e365eb95cAF73b458b2149] = _totalSupply;
emit Transfer(address(0), 0x9f7bb2e565F94C3FF3e365eb95cAF73b458b2149, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
}
I looked at all the other relevant threads and I didn't find the answer
The problem was that I used MEW on desktop, and even though I selected the Ropsten testnet on my phone, I needed to select it on my desktop also. This is kinda confusing because the ETH address that was displayed on my desktop version was the Ropsten address (because I switched to it on my phone before scanning the QR code to connect), but for some reason I had to manually set the network on desktop too.
Having the same issue. Ethplorer says I have XYO tokens but it wont show in MEW. I have tried all the different nodes with no luck. I have tried to install the custom token but it says already there. This wallet is a new design from the old style which worked better. Where can I find these tokens which are there hiding in cyberspace.
OK just solved my issue. I am out of the UK at the moment. I used my VPN to connect to the uk. Opened my wallet and there they were. So try using VPN to connect to a different country.

How to send ether to erc721 token owner?

I want to send ether to token owner.
ownerOf returns address, so I set payable address inside of sendEther function.
However, error says 'Type address is not implicitly convertible to expected type address payable'.
Is there any way to set payable address inside function?
Could you give me any advise?
function sendEther(uint256 _tokenId) public payable {
address payable _tokenOwner = ownerOf(_tokenId);
_tokenOwner.transfer(msg.value);
}
ERC721.sol
function ownerOf(uint256 tokenId) public view returns (address) {
address owner = _tokenOwner[tokenId];
return owner;
}
You can't directly cast from address to address payable, but you can cast in two steps, through uint160:
address payable _tokenOwner = address(uint160(ownerOf(_tokenId)));

Interacting with a Contract from Another Contract Ethereum

I have a problem which I'm trying to figure out for a week I think I'm 90% there.
If I deploy a contract MerchantA on a private blockchain and retrieve it's contract address and ABI through the solidity command line solc --abi MerchantA.sol and store it.
Where do I enter this ABI & Address in a brand new contract say inside SendMoneyContract method where calls one of the function of AnimalContract deployed at address 0xrandom.
The material I'm finding online has been to include both solidity source code in the same file but for my case, I can't do it. Reason being MerchantAContract is unique for each deployment [each merchant added gets a unique contract`.
So far, from my understanding, I need to include the MerchantA contract address and ABI. I have no idea how to do it inside the solidity function.
You do not do anything with the ABI.
Let's say you want to call the functionA function on MerchantA FROM MerchantB, all you do is take the interface from MerchantA, an example of an interface of an ERC20 token is:
contract Token {
function totalSupply() constant returns (uint256 supply) {}
function balanceOf(address _owner) constant returns (uint256 balance) {}
function transfer(address _to, uint256 _value) returns (bool success) {}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
function approve(address _spender, uint256 _value) returns (bool success) {}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
uint public decimals;
string public name;
}
On MerchantB, wherever you want to call functionA, you put the following code:
MerchantA merchantA = MerchantA(0x0000000000000000000000000000000000000000); //Replace 0x000000000000000000000000000000000000000 with the address of MerchantA
merchantA.functionA();
You will need to swap out the interface of MerchantA because you are not using an ERC20 token as well as what function you want to call.