Calling functions from other contracts solidity

0 votes

I am trying to create a new instance of the Taker contract from the Maker contract and send some value to it.

Then later I would like to send a value back to the Maker contract from the Taker contract

maker.change.value(5)(y);

However it cannot find the function called "change" and throws the error.

Untitled:27:3: Error: Member "change" not found or not visible after argument-dependent lookup in address
    maker.change.value(5)(y);
    ^----------^

This is the code I am using: 

pragma solidity ^0.4.2;

contract Maker {
uint x;

function Maker() {
    x = 5;
    Taker take = new Taker(this, 2);
    bool a = take.call.gas(200000).value(10)();
}

function change(uint val) external payable {
    x = val;
}
}

contract Taker {
uint y;
address maker;

function Taker(address makerAddr, uint val) {
    y = val;
    maker = makerAddr;
}

function sendChange() {
    maker.change.value(5)(y);
}
}
Sep 17, 2018 in Blockchain by slayer
• 29,370 points
1,523 views

1 answer to this question.

0 votes

This code worked for me:

pragma solidity ^0.4.2;
contract Maker {
uint x;

function Maker() {
   x = 5;
   Taker take = new Taker(this, 2);
   bool a = take.call.gas(200000).value(10)();
}

function change(uint val) external {
   x = val;
}
}

contract Taker {
   uint y;
   Maker maker;

   function Taker(address makerAddr, uint val) {
      y = val;
      maker = Maker(makerAddr);
 }

 function sendChange() {
    maker.change(5);
 }
 }
answered Sep 17, 2018 by digger
• 26,740 points

Related Questions In Blockchain

+1 vote
0 answers

Can I change the network id in ganache GUI? Is it work for calling the functions in solidity?

Can I change the network id in ...READ MORE

Aug 16, 2019 in Blockchain by anonymous

edited Aug 19, 2019 by Omkar 1,267 views
0 votes
1 answer

Web3j v3.3.1 : Error while generating compiled solidity smart contracts which returns array of struct

Solidity does not support returning structs in ...READ MORE

answered Jun 19, 2018 in Blockchain by aryya
• 7,460 points
1,673 views
0 votes
1 answer

How to create tokens in smart contracts from node.js?

Any modification to the Ethereum Blockchain will ...READ MORE

answered Jun 27, 2018 in Blockchain by Shashank
• 10,400 points
1,670 views
0 votes
1 answer

How Hyperledger projects are different from each other?

Hyperledger includes a range of business Blockchain ...READ MORE

answered Jul 12, 2018 in Blockchain by shweta
• 440 points
801 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,928 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,227 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
891 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,435 views
0 votes
1 answer

How to access bitcoin Daemon from other services?

You don't need all these things to ...READ MORE

answered Aug 29, 2018 in Blockchain by digger
• 26,740 points
1,960 views
+1 vote
1 answer

Calling deployed smart contract from node.js

contractInstance.wakeUp.call is calling the function as constant, but ...READ MORE

answered Sep 26, 2018 in Blockchain by digger
• 26,740 points
4,006 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP