0

I wanna call 3 functions of 3 different smart contracts which swap, buy and sell some ERC20/ERC721 tokens. all 3 functions are of 3 different smart contracts owned by 3 different websites.

I wanna do it with of function of solidity, not by making web3 function which interact with the three contracts.

can we do it ?

2
  • You can do this with PRBProxy. Jul 10, 2022 at 9:59
  • yep. it's pretty standard to call functions on other contracts, and assuming functions on the other contracts don't have protections to prevent it
    – sola24
    Jul 10, 2022 at 10:00

1 Answer 1

0

if you want to use functions from a deployed smart contract, you can make an interface of the deployed contract inside your contract and make an instance of it. here is the example code-

pragma solidity ^0.5.17;

interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);

function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);

function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
}

interface IWETH  {
function deposit() external payable;
function withdraw(uint) external;
}

contract demo {

address weth=0xc778417E063141139Fce010982780140Aa0cD5Ab;



function getWETH() public payable {
   //IWETH(weth).deposit{value: msg.value}();
  IWETH(weth).deposit.value(msg.value)();

}
}

here I have made an interface of WETH contract deployed on testnet. Then in contract demo, I have made an instance of smart contract by it's contract address and called the smart contract function using its instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.