0

There are 2 smart contract

contract A {
function abc(string _a) public returns (address) {
    return new B(_a);
 }
}
contract B {
  function xyz(string _a) {
  A a = A(contact address); // interface
  a.abc(_a); 
  }
}

How can i get the value of function abc() when i am making a call from function xyz() of contract B which DOES NOT have a return. Especially in Remix and also through web3.js please guide.

8
  • Possible duplicate of how to call a function from deployed contract to another contract
    – sp4c3
    Commented Feb 5, 2019 at 9:36
  • Your code is full of syntax errors. Please provide something that can be compiled and tested, and then explain what it is exactly that you are unable to achieve in it. Commented Feb 5, 2019 at 11:07
  • @sp4c3 it is slightly opposite of the question i am trying to call FROM a function which DOES NOT have a return TO a function which have a return. So how can i get the return value of the function that i am calling to from the function that does not have a return ? Commented Feb 5, 2019 at 12:59
  • @goodvibration this is example code real code is v big Commented Feb 5, 2019 at 13:06
  • @DAOdAppDev what are you gonna do to the returned value from A.abc(), you either have to return it, make xyz a return function, Or use it in xyz, for that declare an address variable and store the return of abc in that.
    – sp4c3
    Commented Feb 5, 2019 at 13:15

1 Answer 1

0

This should work

contract A {
function abc(string _a) public returns (address) {
    return new B(_a);
 }
}
contract B {
  function xyz(string _a) {
  A a = A(contact address);
  address addr = a.abc(_a);
  //do something with addr; 
  }
}
2
  • how do i get the value of address when there is no return ? Commented Feb 5, 2019 at 20:06
  • If you want the value you have to return it from xyz(), or save it to state to access it with another call. Since that variable is only in memory, it disappears as soon as the call to xyz() completes. Commented Feb 5, 2019 at 20:37

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.