I have two different smart contracts interaction_1 and interaction_2
I input the data(team) from remix ide.
What I want to accomplish is when user input team in user_input function at interaction_1, teamAcceptedEvent.watch in interaction_test.js will start working, and then to put interaction_1 contract address into interaction_2 getValue function, and interaction_2 contract will receive the user input from interaction_1.
It works fine when I tested it in remix, but when I use web3.js to do it, everything goes smoothly, but interaction_2 didn't get the data from interaction_1.
I'm not sure is there any problem with sendTransaction or the gas price? I'm just trying to test two smart contract interact using web3.js. thanks
interaction_1
pragma solidity ^0.5.1;
contract interaction_1 {
string public description;
string public user_prediction;
uint public amount;
event teamAccepted(string team_1);
function user_input (string memory team) public payable {
user_prediction = team;
emit teamAccepted(user_prediction);
}
function get_user_input()view public returns(string memory) {
return user_prediction;
}
}
contract interaction_2 {
function getValue (address addr)public returns (string memory);
}
interaction_2
pragma solidity ^0.5.1;
contract interaction_2{
string public get_user_prediction;
function getValue (address addr)public returns (string memory){
interaction_1 b = interaction_1(addr);
return get_user_prediction = b.get_user_input();
}
}
contract interaction_1 {
function user_input (string memory team_1)public payable;
function get_user_input()public returns(string memory);
}
interaction_test.js
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
var abi_1=[...];
var abi_2=[...];
var contractAddress_1 = "0xa4349e4081b28acb426a3332a17a7333bcf3e640";
var contractAddress_2 = "0x0d2c978af4fdeec4070a6147a352235d0c01ca26";
var interaction_1 = web3.eth.contract(abi_1).at(contractAddress_1);
var interaction_2 = web3.eth.contract(abi_2).at(contractAddress_2);
var teamAcceptedEvent = interaction_1.teamAccepted();
teamAcceptedEvent.watch(function(error, result){
if (!error)
{
if(result.args.team_1 != null && result.args.team_1 != '')
{
console.log("get user input");
interaction_2.getValue.sendTransaction("0xa4349e4081b28acb426a3332a17a7333bcf3e640",{
from:web3.eth.accounts[0],
gas:2000000},function (error, result){
if(!error){
console.log(result);
} else{
console.log(error);
}
});
}
} else {
console.log(error);
}
});
interaction_1
and two different contracts namedinteraction_2
. Please clear that up!