0

I am trying to call the other contract which is already deployed on the blockchain. But when I try compiling it with remix , it doesn't compile

contract Othersurround {

 function getDetailsFromSurroundContract(address _contractAddress)public view returns(address,string memory,string memory,string memory,string memory,string memory){
   // surround is the name of the deployed contract 
  surround other = surround(_contractAddress);// ***Here is the error - DeclarationError: Identifier not found or not unique.
                                         surround other = surround(_contractAddress);***//
                                         ^-------^ 
    address  wallet_address = other.getUser();  
    string  userId = other.getUser();
    string  first_name = other.getUser();
    string  last_name = other.getUser();
    string  email_id = other.getUser();
    bool set = other.getUser();
    string private_key = other.getUser();
    
    return(wallet_address,userId,first_name,last_name,email_id,private_key);
    
 }
}
3
  • U need to import the interface of that contract
    – Majd TL
    Sep 30, 2021 at 11:10
  • do you have its interface? is it another contract of you?
    – Majd TL
    Sep 30, 2021 at 12:13
  • Yes its the other contract of me how do I convert my other contract to an interface as it contains modifier as well as functions. Sep 30, 2021 at 15:38

1 Answer 1

0

You need to import the contract. Contracts name start always with capital letter

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0; // or your solidity version

import "./Surround.sol"; // the path to the other contract

contract Othersurround {

   function getDetailsFromSurroundContract(address _contractAddress) public view returns(address, string memory, string memory, string memory, string memory, string memory) {
     // surround is the name of the deployed contract 
     Surround other = Surround(_contractAddress); // correct
     address  wallet_address = other.getUser(); // wrong
     string  userId = other.getUser(); // wrong
     string  first_name = other.getUser(); // wrong
     string  last_name = other.getUser(); // wrong
     string  email_id = other.getUser(); // wrong
     bool set = other.getUser(); // wrong
     string private_key = other.getUser(); // wrong
     return(wallet_address,userId,first_name,last_name,email_id,private_key);
   }
}

Now to the other problems :-) ->

  • don't save private key on the blockchain
  • don't save first name and last name and email on the blockchain
  • the "other.getUser()" is not correct or the usage of it is wrong

if the getUser method in the "Surround.sol" smart contract returns a list of values, then you need to do something like this:

function getDetailsFromSurroundContract(address _contractAddress) public view returns(address, string memory, string memory, string memory, string memory, string memory){
  address wallet_address;
  string userId;
  string first_name;
  string last_name;
  string email_id;
  boolean set;
  string private_key;
  (wallet_address, userId, first_name, last_name, email_id, set, private_key);
  return(wallet_address,userId,first_name,last_name,email_id,private_key);
}
2
  • sorry but this is wrong as I am trying to access my other contract which is already deployed on the blockchain and you cant just by using import. Sep 30, 2021 at 20:56
  • Copy the code of the already deployed contract and place it in a file in the same directory. U will not deploy it again, u only need to make the code visible to ur contract @georgesingh
    – Majd TL
    Sep 30, 2021 at 21:17

Your Answer

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

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