Contract interoperability
One of the key feature of yallo is the ability for contract to interact with other contracts easily. We provide a syntax for calling other contracts or deploy new one.
Calling other contracts
The first way to call another contract is using their interface abstraction as follow; we first get the instance of an IToken (see Contract structure page) at a given tokenContractAddress. We then point to the getBalance entrypoint passing an address to investigate and the reference to a nat entrypoint from this contract.
let op: operation = IToken.of(tokenContractAddress).getBalance(addrToInvestigate, this.checkBalanceCallback);
The previous code creates a operation with 0mtz inside; if we want to call another contract passing an amount, we do:
let op: operation = Tezos.transfer (IToken.of(tokenContractAddress).getBalance, (addrToInvestigate, this.checkBalanceCallback), 12mtz);
We can also get getBalance without using the interface IToken:
let getBalance: (address, nat contract) contract = Tezos.contract(tokenContractAddress, "getBalance") in
let op = getBalance(addrToInvestigate, this.checkBalanceCallback);
Deploy a contract
Yallo also allow deploying a contract from another contract. For instance, we can deploy the Token contract from another contract:
import "test/contract/token.yallo";
contract deployAToken {
field tokenAddress: address;
entry deployToken() {
let (op: operation, a: address) = Tezos.createContract (Token(100, "ourToken"), None, 0mtz);
this.tokenAddress = a;
[op]
}
}
We use the constructor of Token to produce the initial storage.
Last updated
Was this helpful?