You can pass more than one arugment to a predicate. For example, this is a predicate that evaluates to true
if the two arguments are not equal:
predicate;
fn main(arg1: u64, arg2: u64) -> bool {
return arg1 != arg2;
}
You can pass the two arguments to this predicate like this:
const predicate = new Predicate(bytecode, chainId, abi);
predicate.setData(20, 30);
const tx = await predicate.transfer(receiver.address, amountToReceiver);
await tx.waitForResult();
You can also pass a struct as an argument to a predicate. This is one such predicate that expects a struct as an argument:
predicate;
struct Validation {
has_account: bool,
total_complete: u64,
}
fn main(received: Validation) -> bool {
let expected_has_account: bool = true;
let expected_total_complete: u64 = 100;
received.has_account == expected_has_account && received.total_complete == expected_total_complete
}
You can pass a struct as an argument to this predicate like this:
const predicate = new Predicate(bytecode, chainId, abi);
const tx = await predicate
.setData({
has_account: true,
total_complete: 100,
})
.transfer(receiver.address, amountToReceiver);
await tx.waitForResult();
Was this page helpful?