0

Is it possible too return value in this way? This is for an understanding of the mechanism of using a method from github Thank you!

// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol"; abstract contract Token is ERC20 { uint8 returnValueFromExt; ERC20 extBase; function testCall() public view returns(uint){ return extBase.decimals(); // returnValueFromExt = extBase.decimals(); } } 

After deploying, I receive this error.

This contract may be abstract, it may not implement an abstract parent's methods completely or it may not invoke an inherited contract's constructor correctly.

1 Answer 1

1

Your Token contract is an ERC20 token and can directly call the decimals() function You can remove the abstract keyword from the contract declaration as is not necessary

If you want to call an external decimals() function, your extBase variable, which is an address should be equal to an existing ERC20 token.

For example, if extBase is set to the address of Token B and your current contract is Token A, you can call the decimals() function as follows:

function testCall() public view returns (uint) { return extBase.decimals(); } 

If you want to test with any ERC20 token address, you can use the following function:

function testCall(address extToken) public view returns (uint) { return ERC20(extToken).decimals(); } 
5
  • unfortunately it still doest work Commented Apr 9, 2023 at 22:01
  • it ask me for abstract Commented Apr 9, 2023 at 22:02
  • during deploy throw this error -> This contract may be abstract, it may not implement an abstract parent's methods completely or it may not invoke an inherited contract's constructor correctly. Commented Apr 9, 2023 at 22:02
  • error without abstract -> from solidity: TypeError: Contract "Token" should be marked as abstract. Commented Apr 9, 2023 at 22:04
  • you need a constructor Commented Apr 9, 2023 at 22:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.