0
contract xyz { mapping(address => bool) Users; function add(address userAddress) { require(userAddress != 0x0 && !Users[userAddress]); Users[userAddress] = true; } function pass(address passAddress) returns (bool) { return Users[passAddress]; } } contract SaveData { address[] addrs; string[] hashSet; xyz asd = xyz(); function Save(address PubAddress) { require(asd.pass(PubAddress)==true); addrs.push(PubAddress); //saving public addresses } //function to save hash function saveHash(string hashStr) { hashSet.push(hashStr); } } 

I am new to solidity, i am creating a simple user reg and checking and saving it using another contract. Contract xyz is working fine, but now i want to call it into SaveData Contract and check address using pass function that if address is whitelisted then only it will save the address.

thanks in advance

3
  • 1
    Possible duplicate of Call function on another contract Commented Dec 19, 2017 at 6:40
  • @MichaelKohl what i need is that i have deployed my xyz contract and it generating an address. Now i need to send the same address in savedata contract and save it using save function. Commented Dec 19, 2017 at 6:56
  • This looks fine, except you are never calling asd.add() to whitelist your addresses. What are you finding is not working? (also, no need for "==true" in your require.) Commented Dec 19, 2017 at 13:27

1 Answer 1

2

The main thing is you cast a variable as an instance of your contract, then you instantiate it at the address where you expect it to be.

Something like

MyContract myContract; myContract = MyContract(contractAddress); 

I couldn't help myself and adjusted the names of some things.

pragma solidity 0.4.21; contract UserReg { mapping(address => bool) public isUser; function add(address userAddress) public { require(userAddress != 0x0 && !isUser[userAddress]); isUser[userAddress] = true; } function pass(address passAddress) public view returns(bool) { return isUser[passAddress]; } // Added this for safety check near 31 function isUserReg() public pure returns(bool isIndeed) { return true; } } contract SaveData { address[] public addrs; UserReg userReg; function instantiateXyz(address userRegAddr) public returns(bool success) { userReg = UserReg(userRegAddr); // instantiate asd instance of Zyz require(userReg.isUserReg()); // should return true, right? return true; } function saveAddress(address pubAddress) public returns(bool success) { require(userReg.pass(pubAddress)==true); addrs.push(pubAddress); //saving public addresses return true; } } 

Hope it helps.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.