How to properly pass the contractId list to the contract call chain?

Let’s say I have 2 contracts: contract A and contract B. Contract A calls the function func_a in function func_b of contract B, and function func_b requests the price from the Pyth Oracle

// Contract A
impl ContractA for Contract  {
    fn func_a(){
         let contract_b = abi(ContractB, CONTRACT_B_ADDRESS);
         let price  = contract_b.func_b();
    }
}

//Contract B
impl ContractB for Contract  {
    fn func_b() -> u64{
         let pyth_contract = abi(PythCore, spark_contracts.pyth_address.into());
         pyth_contract.price(PRICE_FEED).price
    }
}

rust and ts sdks request an array of contracts when calling func_a, can you please tell me if the call will work correctly if I pass 2 addresses into the call of contract A: the address of contract B and the address of Pyth Oracle

1 Like

Hi there!

Can you provide an example of the sdk function you are trying to execute?

Thanks! :palm_tree:

let tx_params = TxParameters::default().with_gas_price(1);
contract_a
.methods()
.func_a()
.tx_params(tx_params)
// .with_contracts() <- here is my question
.call()

Hi there!

The addContracts method expects an argument with type Array< AbstractContract> as seen here.

Invoking the addContracts method with an Array of addresses will throw a type error.

I think you should try something like this:

const contract_a = new Contract(contract_a_Id, abi_a, wallet);
const contract_b = new Contract(contract_b_Id, abi_b, wallet);

let tx_params = TxParameters::default().with_gas_price(1);
contract_a
.methods()
.func_a()
.tx_params(tx_params)
addContracts([contract_b])
.call()

Let me know if this helps c: :palm_tree:

1 Like

but we’re not pedaling the Pyth contract here.

Hello c:

You must include and instance of the Pyth contract and add it to the call context, otherwise it won’t work.

let tx_params = TxParameters::default().with_gas_price(1);
contract_a
.methods()
.func_a()
.tx_params(tx_params)
addContracts([contract_b, pyth_oracle_instance])
.call()