solders.pubkey.Pubkey.find_program_address

程序派生地址在第一部分概念篇讲过,它是由公钥和种子和一个 bump 值从 255 递减,找到第一个跳出椭圆曲线的公钥,以确保其没有关联的私钥。所以与其说是生成,不如说是找出,所以这个方法名为 find_program_address.

from solders.pubkey import Pubkey

demo_pubkey = Pubkey.default()
print(demo_pubkey)  # 11111111111111111111111111111111
print(len(str(demo_pubkey)))  # 32
derive_pubkey = Pubkey.find_program_address(b'', demo_pubkey)
print(derive_pubkey)
# (Pubkey(
#     Cu7NwqCXSmsR5vgGA3Vw9uYVViPi3kQvkbKByVQ8nPY9,
# ), 255)  # 255 为 bump 值

results matching ""

    No results matching ""