将 solana 代币从我的钱包转移到 python 中的另一个钱包

问题描述 投票:0回答:2

所以我正在编写一个脚本,使用

transfers tokens
(不属于我的定制代币)从我的钱包到Python中的另一个钱包。我该如何去做呢? (我所说的代币是指像 Dust、Luv 或任何其他 solana 代币这样的代币)
我从哪里可以获得有关代币所需的信息,例如代币铸造、代币账户地址等?
这些信息意味着什么?

我找到了这个代码片段,用于将代币从一个钱包转移到另一个钱包,但我不确定这里有什么以及从哪里获取它们,例如代币帐户、所有者等。

我认为这个代码片段是针对代币所有者的,但我不是代币所有者,我必须在我的钱包中代币我只想将其转移到另一个钱包

solana.py


python blockchain solana solana-program-library solana-py
2个回答
0
投票
this

。 您使用的代码片段来自旧版本的 solana py。

先决条件: pip 安装 solana

示例代码:

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.



0
投票
© www.soinside.com 2019 - 2024. All rights reserved.