Basic Transaction
- Rust
- TypeScript
Copy
let signature = privora
.transaction()
.instruction(instruction)
.sign(&payer)
.send()
.await?;
Copy
const signature = await privora
.transaction()
.add(instruction)
.sign(payer)
.send();
With FHE Data
When your transaction references encrypted data, include the hashes:- Rust
- TypeScript
Copy
let hash = privora.submit(&encrypted).await?;
let signature = privora
.transaction()
.instruction(instruction)
.with_fhe_data(&[hash])
.sign(&payer)
.send()
.await?;
Copy
const hash = await privora.submit(encrypted);
const signature = await privora
.transaction()
.add(instruction)
.withFheData([hash])
.sign(payer)
.send();
Multiple Instructions
- Rust
- TypeScript
Copy
let signature = privora
.transaction()
.instruction(create_account_ix)
.instruction(initialize_ix)
.instruction(process_ix)
.with_fhe_data(&[hash1, hash2])
.sign(&payer)
.send()
.await?;
Copy
const signature = await privora
.transaction()
.add(createAccountIx)
.add(initializeIx)
.add(processIx)
.withFheData([hash1, hash2])
.sign(payer)
.send();
Building Instruction Data
Include hash references in your instruction data:- Rust
- TypeScript
Copy
let mut data = vec![0u8]; // instruction discriminator
data.extend_from_slice(&hash);
let instruction = Instruction {
program_id: PROGRAM_ID,
accounts: vec![AccountMeta::new(account, false)],
data,
};
Copy
const data = Buffer.concat([
Buffer.from([0]), // instruction discriminator
Buffer.from(hash, 'hex'),
]);
const instruction = new TransactionInstruction({
programId: PROGRAM_ID,
keys: [{ pubkey: account, isSigner: false, isWritable: true }],
data,
});
Complete Example
- Rust
- TypeScript
Copy
use privora_sdk_client::prelude::*;
async fn submit_order(price: u8, quantity: u8) -> Result<String> {
let privora = PrivoraClient::new("http://localhost:8899").await?;
let payer = Keypair::new();
privora.request_airdrop(&payer.pubkey(), 1_000_000_000).await?;
// Encrypt
let enc_price = privora.encryptor().encrypt(price)?;
let enc_qty = privora.encryptor().encrypt(quantity)?;
// Submit
let price_hash = privora.submit(&enc_price).await?;
let qty_hash = privora.submit(&enc_qty).await?;
// Build instruction
let mut data = vec![1u8];
data.extend_from_slice(&price_hash);
data.extend_from_slice(&qty_hash);
let instruction = Instruction {
program_id: PROGRAM_ID,
accounts: vec![
AccountMeta::new(payer.pubkey(), true),
],
data,
};
// Send
let signature = privora
.transaction()
.instruction(instruction)
.with_fhe_data(&[price_hash, qty_hash])
.sign(&payer)
.send()
.await?;
Ok(signature)
}
Copy
async function submitOrder(price: number, quantity: number) {
const privora = await Privora.connect('http://localhost:8899');
const payer = Keypair.generate();
await privora.requestAirdrop(payer.publicKey, 1_000_000_000);
// Encrypt
const encPrice = privora.encrypt(price, 'u8');
const encQty = privora.encrypt(quantity, 'u8');
// Submit
const priceHash = await privora.submit(encPrice);
const qtyHash = await privora.submit(encQty);
// Build instruction
const data = Buffer.concat([
Buffer.from([1]),
Buffer.from(priceHash, 'hex'),
Buffer.from(qtyHash, 'hex'),
]);
const instruction = new TransactionInstruction({
programId: PROGRAM_ID,
keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: true }],
data,
});
// Send
return privora
.transaction()
.add(instruction)
.withFheData([priceHash, qtyHash])
.sign(payer)
.send();
}