跳转到主要内容
使用我们的 SWQoS,您可以使用默认的优先费用(无需特别设置),使用小费作为优先选项。在构建交易时,您需要向交易中添加一个小费转账指令,以加速交易打包进区块。 示例代码生成的 base64 编码交易数据可以直接通过 SDK 方法调用,例如传递给 send_transaction
pub const MEMO_PROGRAM_ID: &str = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
pub const BLOCKRUSH_TIP_WALLET: &str = "AhMVT9KWLGjBbzvdqQkTt4vHwpawnGNoGSqaqXYftNDR";
pub const DEFAULT_TIP_AMOUNT: u64 = 1_000_000; // 0.001 SOL

pub fn create_blockrush_tip_ix(pubkey: Pubkey, tip_amount:u64) -> Instruction {
    let tip_ix =
        instruction::transfer(
            &pubkey,
            &Pubkey::from_str(BLOCKRUSH_TIP_WALLET).unwrap(),
            tip_amount,
        );
    tip_ix
}

fn create_memo_tx_with_tip(msg: &[u8], payer: &Keypair, blockhash: Hash) -> Transaction {
    let memo = Pubkey::from_str(MEMO_PROGRAM_ID).unwrap();
    let instruction = Instruction::new_with_bytes(memo, msg, vec![]);
    let mut instructions = vec![instruction];
    let tip_ix = create_blockrush_tip_ix(payer.pubkey(), TIP_AMOUNT);
    instructions.push(tip_ix);
    let message = Message::new(&instructions, Some(&payer.pubkey()));
    Transaction::new(&[payer], message, blockhash)
}

let test_tx = create_memo_tx_with_tip(b"this is a demo tx", &keypair, latest_hash);
let serialized_test_tx = bincode::serialize(&test_tx)?;
let base64_test_tx = BASE64_STANDARD.encode(&serialized_test_tx);