Unable to view the token balances of the smart contract on remix while executing the seeBalance function

pragma solidity =0.7.6; pragma abicoder v2;

import "https://github.com/Uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";

interface IERC20 { function balanceOf(address account) external view returns (uint256);

function transfer(address recipient, uint256 amount)
    external
    returns (bool);

function approve(address spender, uint256 amount) external returns (bool);

}

contract MultiSwap {

address public owner;
address public balance;

constructor() {
    owner == msg.sender;
}

address public constant routerAddress =
    0xE592427A0AEce92De3Edee1F18E0157C05861564;
ISwapRouter public immutable swapRouter = ISwapRouter(routerAddress);

address public constant SHUBYDAI = 0xe742A911ffFAEc86786bd2246Dd035F6Aa55aE2B;
address public constant SHUBYUSDC = 0xA61C9829209b75741bBB9f682483B3A4C3e4E924;

IERC20 public shubyToken = IERC20(SHUBYDAI);

function swapExactInputMultihop(uint amountIn) 
    external
    returns (uint amountOut)
{
    shubyToken.transfer(
        address(this),
        amountIn
    );
    shubyToken.approve(address(swapRouter), amountIn);

    ISwapRouter.ExactInputParams memory params = ISwapRouter
    .ExactInputParams({
        path: abi.encodePacked(
            SHUBYDAI,
            uint24(3000),
            SHUBYUSDC,
            uint24(3000),
            SHUBYDAI
        ),
        recipient: msg.sender,
        deadline: block.timestamp,
        amountIn: amountIn,
        amountOutMinimum: 0
    });
    amountOut = swapRouter.exactInput(params);
}

function transferIERC20(IERC20 token, address to, uint256 amount) public {
    require(msg.sender == owner, "Only the owner can use this function");
    uint256 erc20Balance = token.balanceOf(address(this));
    require(amount <= erc20Balance, "balance is low");
    token.transfer(to, amount);
}

function SeeBalance(IERC20 token) public view {
   IERC20(token).balanceOf(address(this));
   
}

}

when i try to interact with this contract on remix and i try to run the seeBalance function it doesn't work, the message i get is.

[block: txIndex:]from: 0x241...8Be5fto: 0xFC4c5cE47f2E9361B28E8f6B486668dB61730A81 0xFC4...30A81value: 0 weidata: 0xbbb...5ae2blogs: 0hash:

decoded output -

i have transfered 4000 ShubyDAI which is the token i want to see the token for but i dont get a value.

Could someone help please.

Answer №1

I believe the correct code should look something like this.

function CheckBalance(IERC20 token) public view returns (uint256) {
   return IERC20(token).balanceOf(address(this));
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Information is not transferring to Bootstrap modal

I attempted to send a value to a modal by following the instructions on the Bootstrap documentation here. However, I am facing an issue where the data is not being successfully passed. To trigger the modal, use the following button: <button type=" ...

Electron / Atom Shell unable to locate specified module

I am completely new to npm, node, and Electron. Here is the structure of my folder: -package.json -index.html -main.js -js/myStuff.js -node_modules In the file myStuff.js, I have a line that says var chokidar = require('chokidar'); but it keep ...

Tips for leveraging a button to trigger server-side actions

Being a novice in web development, I'm currently working on a straightforward website that enables users to download files from the server side. These files are not pre-created; instead, there will be a button on the HTML page. When a user clicks this ...

Using the symbol for pi in a JavaScript program rather than its numerical value, while still performing calculations with the numerical value behind the scenes

I am working on a calculator project where I want the symbol for pi to be displayed instead of the numerical value. Here is the relevant function: function Pi(pi) { document.getElementById('resultArea').innerHTML += pi; eval(document.ge ...

What's the best approach for implementing TimeInput exclusively in React-Admin?

I discovered this helpful code snippet on the React-Admin documentation that allows me to input both a date and time: import { DateTimeInput } from 'react-admin'; <DateTimeInput source="published_at" /> But now I'm wonderin ...

The transition effect of changing opacity from 0 to 1 is not functioning properly in Firefox

Having some trouble with this animation not working in Firefox. I'm triggering the animation using JavaScript after a delay like so: document.getElementById('my_id').style.webkitAnimationPlayState = "running"; I've also attempted: s ...

Utilize the dynamic duo of GridLayout and ScrollView within the Famo.us JS framework

I'm attempting to incorporate a grid layout into a scroll view using famo.us (with angular), and the most straightforward approach seems to be working. <fa-view> <fa-scroll-view fa-pipe-from="eventHandler" fa-options="scrollView"> ...

Guide to dynamically loading customer data into an HTML table using JavaScript

I'm looking to populate a table with data on customers including their name, customer ID, and rental cost. Can anyone help me with the JavaScript code needed to insert this data into rows of the table? Your assistance is greatly appreciated. Below is ...

Is there a way to dynamically adjust the height of a DIV block?

I have a situation where I need the height of one div to automatically adjust based on changes in the height of another div. var height = jQuery('#leftcol').height(); height += 20; jQuery('.rightcol-botbg').height(height); Unfortun ...

Ways to avoid losing data when a page is refreshed

After encountering a frustrating issue with my form, I turned to research in hopes of finding a solution. However, each attempt has resulted in disappointment as the data is lost every time the page is refreshed. If anyone has advice on how to prevent th ...

Search field in DataTables appears to be misaligned

I'm in the process of developing a small website using JSP and DataTables (currently only for the first table). Here's what I have so far: As you can observe, there seems to be an alignment issue with the search field position. I'm n ...

Signal for a complete 360 degree rotation of an image

Looking to enhance my 360 image rotator with an indicator that fades out after the first image. I added this function to the end of my 360.js: (function(){ if( $('#first').css('visibility','hidden')) { $('#rotat ...

Issue with height in self-invoking function not functioning correctly

Issue with height not functioning correctly inside self-invoking function, but works fine within (document).ready(function() (function($){ var clientHeight = document.getElementById('home').clientHeight; alert(clientHeight); })(jQuery); <di ...

Utilizing Node.js with Graphics Magick to generate high-quality cropped thumbnails without sacrificing image resolution

Is there a solution to maintain image quality when cropping and centering an image using Graphics Magick? The code I currently have reduces the fidelity of the resulting image. gm(imagePath) .thumbnail(25, 25 + '^') .gravity('Cent ...

Issues with updating the style in Internet Explorer and Firefox using JavaScript are currently unresolved

I am facing an issue with my program where a name from an auto-complete is sent to a JavaScript function that dynamically creates a label with a button inside. Surprisingly, the DOM methods used to set style properties do not work in Firefox and IE 7, but ...

Using JavaScript regex to match repeating subgroups

Can a regular expression capture all repeating and matching subgroups in one call? Consider a string like this: {{token id=foo1 class=foo2 attr1=foo3}} Where the number of attributes (e.g. id, class, attr1) are variable and can be any key=value pair. C ...

Turning JavaScript Object into a Decimal Value

I've been working on an application where I want to be able to add up the columns of an HTML table. I managed to add inputs to the table successfully, but when trying to sum up the columns, I keep getting a "NaN" error. /* Function for calculating ...

Angular-material's Md-dialog popup box is displayed as a separate view within the Yeoman framework

I have recently created a project using Yeoman (angular-fullstack, angular-material) and encountered an issue with triggering the md-dialog box. When clicking on a div element, the dialog box is supposed to appear. However, instead of showing the popup the ...

Angular 12 app does not have Express server searching for static files

Context I am in the process of transferring an Angular application to a GKE cluster. Unfortunately, due to company policy, the base docker image I am required to use does not support the installation of new software such as shell or Angular CLI commands l ...

Make sure the division remains fixed even when the window is resized

Having a fixed position and bottom set to 0, I want my div to display at the bottom of the window. The issue arises when the window is resized, causing the div to move up and into other elements. For instance, when opening the console box in Chrome, the f ...