首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python的Solana事务

使用python的Solana事务
EN

Stack Overflow用户
提问于 2022-06-17 22:29:01
回答 1查看 652关注 0票数 1

我试图在Solana网络中使用python进行事务处理,我使用的是solana.py python库和anchor.py,但是我无法确定如何打开用于签署事务的钱包。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-07 04:13:23

答复:2022年8月

我花了很长时间才弄明白。我只走了一段路。接下来的步骤是你自己去做。

你需要的是:

  1. 带有SOL (devnet)和秘密密钥
  2. 的钱包地址令牌
  3. 您将要发送的令牌帐户。
  4. 是一个空令牌帐户,用于将令牌发送到

最简单的方法是通过solana-cli和tokens命令行学习如何创建和发送令牌。(请使用ubuntu容器,这样你就不用担心你的电脑了)我推荐网络卡solana教程。

先在Shell中尝试这样做,然后按您的意愿来做。

代码语言:javascript
复制
from spl.token.constants import TOKEN_PROGRAM_ID
from spl.token.instructions import transfer_checked, TransferCheckedParams

from solana.rpc.commitment import Confirmed
from solana.rpc.api import Client
from solana.rpc.types import TxOpts
from solana.keypair import Keypair
from solana.publickey import PublicKey
from solana.transaction import Transaction


from_token_account = PublicKey("Brnvzh...bGPED")
to_token_account = PublicKey("6Uij3...Ahmtp")
from_wallet_address = PublicKey("rjPKeL...wedQp")
mint_public_id = PublicKey("4qYnL....Pt4taGk")
SECRET_KEY = bytes([43,124,...,3,226,229,189]) #from the account you are sending from. AKA owner account. You will find this in id.json 

transaction = Transaction()
transaction.add(
    transfer_checked(
        TransferCheckedParams(
            TOKEN_PROGRAM_ID, #DON'T WORRY ABOUT THIS! DON'T TOUCH IT!
            from_token_account, #Its not your wallet address! Its the token account address!
            mint_public_id, # token address 
            to_token_account, # to the receiving token account.
            from_wallet_address, # wallet address connected to the from_token_account. needs to have SOL
            1, #amount of tokens to send.
            9, #default decimal places. Don't touch in it most cases
            [] #default. Don't touch it in most cases

        )
    )
)
client = Client(endpoint="https://api.devnet.solana.com", commitment=Confirmed) #devnet you can change it to the main net if you want
owner = Keypair.from_secret_key(SECRET_KEY) # <-- need the keypair for the token owner here! [20,103,349, ... 230,239,239]
client.send_transaction(
    transaction, owner, opts=TxOpts(skip_confirmation=False, preflight_commitment=Confirmed)) #don't touch it in most cases.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72665347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档