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.

  • 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. – goodvibration Feb 5 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 ? – DAOdAppDev Feb 5 at 12:59
  • @goodvibration this is example code real code is v big – DAOdAppDev Feb 5 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 Feb 5 at 13:15
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; 
  }
}
  • how do i get the value of address when there is no return ? – DAOdAppDev Feb 5 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. – ruby_newbie Feb 5 at 20:37

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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