smart contract A invoking function from smart contract B #fabric-chaincode


montassar.naghmouchi@...
 

Hi,
I currently have a chaincode with 3 seperate smart contracts [A,B,C] inside it.
I use different smart contracts for different fucntionality and different transaction contexts.
Now I want to invoke a function defined in lets say smart contract B, from a function defined in lets say A.
In Example :
File 1
.........................................................
class B extends Contract {
                   constructor ..
                   async F ..
}
module.exports = B;
..........................................................
File 2
..........................................................
class A extends Contract{
                    constructor ..
                    async G {
                               invoke (F) from A
                    }
}
..........................................................

Any help on how to correctly call and invoke ?
Thanks


satheesh
 

for cross chaincode access

Regards,
Satheesh

On Monday, November 15, 2021, 08:22:28 PM GMT+5:30, montassar.naghmouchi@... <montassar.naghmouchi@...> wrote:


Hi,
I currently have a chaincode with 3 seperate smart contracts [A,B,C] inside it.
I use different smart contracts for different fucntionality and different transaction contexts.
Now I want to invoke a function defined in lets say smart contract B, from a function defined in lets say A.
In Example :
File 1
.........................................................
class B extends Contract {
                   constructor ..
                   async F ..
}
module.exports = B;
..........................................................
File 2
..........................................................
class A extends Contract{
                    constructor ..
                    async G {
                               invoke (F) from A
                    }
}
..........................................................

Any help on how to correctly call and invoke ?
Thanks


Mark Lewis
 

There is an invokeChaincode() function available on the chaincode stub that can be used to make chaincode-to-chaincode calls:

https://hyperledger.github.io/fabric-chaincode-node/release-2.2/api/fabric-shim.ChaincodeStub.html#invokeChaincode

But your smart contracts are both within the same chaincode so you don't need to use that. Instead, you might want to define a function that implements the transaction behaviour you want to invoke from both smart contracts, and call that implementation function from both transaction functions. So you would have two separate transaction functions (on separate smart contracts) that share some or all of their implementation.