How can we connect two truffle applications with each other? E.g., if we have two metacoin applications, how can these two communicate with each other?
2 Answers
By using the same blockchain you can interact with a single contract. Make sure that the applications use the same contract address by using for example var meta = MetaCoin.at("0x1234...")
. You can find out where the contract is deployed with MetaCoin.deployed_address
.
The only challenge is to tell the second application where the deployed address of the starting application is. Simplest is to write it into a file.
To establish the connection between two applications, you need a smart contract. This smart contract will be deployed at one end .
The deploying application will use it as contractname.deployed()
to create an instance of contract.
As we know that to access any contract on the blockchain, we need :
- Contract's AbiDefinition
- Contract Address
contractname.at(contractaddress)
in the application.Thus your both applications can communicate.Let me know any further query.