I got a thirty program which only IDL and programID are available. Let call it HelloWorld program.
If we call HelloWorld directly, it is simple, just as :
const idl = require(<PATH_TO_IDL>);
const programId = new PublicKey(<HELLO_WORLD_PROGRAM_ID>)
// Create program
const helloworldProgram = new Program(idl, programId, provider);
// create transaction
const transaction = await helloworldProgram.methods
.helloWorld({greetTo: "xxx"})
.accounts({
authority: wallet.publicKey,
...,
})
.transaction()
// ... send Tx ...
But,
now , I need to call it from my own program, assume it is RelayProgram
#[program]
pub mod relay_program {
use super::*;
pub fn to_call_helloworld(
ctx: Context<...>,
dataOfHelloWorldCall: &[u8]
) -> Result<()> {
...
let helloIX = Instruction::new_with_bytes(
ctx.accounts.hello_program_account.key, // HelloWorld program's ID
dataOfHelloWorldCall, // <== This is the data that we crafted in client JS
vec![ctx.accounts...], // accounts
);
invoke(&helloIX, &[...])
}
}
Now the client code would be:
const idl_1 = require(<PATH_TO_HELLO_WORLD_IDL>);
const programId_1 = new PublicKey(<HELLO_WORLD_PROGRAM_ID>)
...
// Create program
const helloworldProgram = new Program(idl_1, programId_1, provider);
...
// Create program
const relayProgram = new Program(idl_2, programId_2, provider);
// Question: how to build data that passed to relayProgram and then apply on HelloWorld program ?
let _dataOfHelloWorldCall = ? // [u8] array of data
// create transaction
const transaction = await relayProgram.methods
.to_call_helloworld({dataOfHelloWorldCall: _dataOfHelloWorldCall})
.accounts({
authority: wallet.publicKey,
programB: PROGRAM_B_ID,
// rest is the same as those as call 'helloWorld' directory
})
.transaction()
// ... send Tx ...
Now, the questions are:
does this idea feasible? If not, please share workable idea.
how can I build the IX data ?
Thanks