in

How to interact with smart contract deployed by another smart contract, in web3?

How would you interface with ‘Basic’ contract from a web3 application?

I’m building a webapp with truffle, and only ‘Dex’ contract is able to interact with ‘Basic’. I couldn’t call ‘Basic’s functions from web3. Would it be possible to configure truffle to generate the ABI for Basic in this scenario?

contract Basic {
uint8 value = 8;

function lame() public view returns(uint8){
return value;
}
}

contract Dex {
Basic public token;
constructor(){
token = new Basic();
}
}

—–

I also tried deploying the Basic contract before and supplying the address to Dex, but truffle didn’t seem to like it. (Gives some cryptic error messages when calling methods of Dex. Migration is succesful though and shows no error messages.)

contract Basic {
uint8 value = 8;

function lame() public view returns(uint8){
return value;
}
}

contract Dex {
Basic public token;
constructor(address basic){
token = Basic(basic);
}
}

// truffle migrations file:
module.exports = function(deployer) {
deployer.deploy(Basic);
deployer.deploy(Dex, Basic.address);

};

What do you think?

10 Points
Upvote Downvote

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

One Comment

Trade Crypto for Free with ShapeShift | by Erik Voorhees | ShapeShift Stories

TSLA: The Bearish Case