Overview
This crate provides two convenience macros to resolve Pubkeys at compile time:
pubkey!: takes a pubkey value as a base58&strand generates its correspondentPubkey(byte array)declare_id!: takes a pubkey value as a base58&str(usually representing a program address) and generates anIDconstant,check_id()andid()helpers
It also defines a from_str helper that takes a &str and returns the correspondent Pubkey value.
Examples
Once the project is built the first time with cargo build-sbf, a new keypair is automatically generated. A public key can be retrieved with:
Instead of the autogenerated keypair, a vanity key can be used. You can move the vanity keypair to ./target/deploy/your_program-keypair.json.
Remember to back up the keypair file securely, it is necessary for deploy the program.
Public keys can be embedded into the program code in the following ways.
- Creating a
Pubkeyconstant value from a static&str:
use Pubkey;
pub const AUTHORITY: Pubkey = pubkey!;
- Declaring the program address of a program (usually on your
lib.rs):
declare_id!;
- Creating a
Pubkeyfrom a&str:
let address = Stringfrom;
let owner = from_str;
License
The code is licensed under the Apache License Version 2.0