首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >直接与solana程序交互

直接与solana程序交互
EN

Stack Overflow用户
提问于 2022-03-27 20:55:14
回答 2查看 1.7K关注 0票数 0

我试图使用索拉娜-比与没有文档的solana程序进行交互。

这个程序是Solana 神奇伊甸园NFT市场。我已经尝试从锚点获得有关它的信息,但是它没有可用的数据。

我的目标:我想列出一个NFT直接没有网络接口.

我的测试:作为一个例子,我想列出我拥有的这个NFT:Robber#04977

由于我对该程序一无所知,因为它们没有可用的文档,所以我查看了其他事务,并找到了我试图重新创建的事务,但使用的是nft:成功交易

我更改了帐户,使用了我的私钥并使用solana-py:我的交易失败了创建了事务。

有关当前状态,请参见下面的编辑。

原始代码:

代码语言:javascript
复制
from solana.transaction import AccountMeta, Transaction, TransactionInstruction
from solana.rpc.types import TxOpts
from solana.account import Account
from solana.rpc.api import Client
from solana.publickey import PublicKey
from solana.keypair import Keypair

from getpass import getpass
import base58

# setup client
url = 'https://api.mainnet-beta.solana.com'
client = Client(url)

program = 'MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8'

# get account from private key
pwd = getpass('Chrome -> Phantom -> Settings -> Export private Key')
byte_array = base58.b58decode(pwd)
keypair = list(map(lambda b: int(str(b)), byte_array))[:]
initializer_account = Keypair(keypair[0:32])

# create transaction and sign it
txn = Transaction(recent_blockhash=client.get_recent_blockhash()['result']['value']['blockhash'], fee_payer=initializer_account.public_key)
txn.add(
    TransactionInstruction(
        keys=[
            AccountMeta(pubkey=PublicKey(initializer_account.public_key), is_signer=True, is_writable=True),
            AccountMeta(pubkey=PublicKey('GG24iCpytsz2nxei81FHyEyduQAxCAJHWkDLitwr9MxQ'), is_signer=False, is_writable=True),
            AccountMeta(pubkey=PublicKey('3gS9AqTJ9adw23tZ87Hn1ccyYJ5KZ5tcoNQfYhCFu2e3'), is_signer=False, is_writable=True),
            AccountMeta(pubkey=PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), is_signer=False, is_writable=False),
            AccountMeta(pubkey=PublicKey('11111111111111111111111111111111'), is_signer=False, is_writable=False),
            
        ],
        program_id=PublicKey('MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8'),
        data=bytes.fromhex('96d480ba740183710094357700000000ff') # sell für 2 Solana
    )
)
txn.sign(initializer_account)

rpc_response = client.send_transaction(
    txn,
    initializer_account,
    opts=TxOpts(skip_preflight=True, skip_confirmation=False)
)

响应包含对失败事务的事务id。

代码语言:javascript
复制
{'jsonrpc': '2.0',
 'result': 'NytmsBK59kckV3nGBsw6Vi9XAw8jkpkQGgHKCMYNFPYXLy57caNN7icNpMepofNsdncJ2BVziFJ82e8PKpH1EnV',
 'id': 3}

solscan的程序日志如下所示:

代码语言:javascript
复制
#1 Magic Eden NFT Marketplace instruction
> Program Magic Eden NFT Marketplace  consumed 5829 of 200000 compute units
> Program returned error: Could not create program address with signer seeds: Provided seeds do not result in a valid address

也许这是一些错误的数据,我要发送给程序。我只是在寻找成功的历史交易,并将其用于我的交易。

编辑:越来越近,但还没有完成。我现在还创建了创建帐户和设置权限的指令。但这些都是连续的,而不是作为一个内在的指导。

代码语言:javascript
复制
from solana.transaction import AccountMeta, Transaction, TransactionInstruction
from solana.rpc.types import TxOpts
from solana.account import Account
from solana.rpc.api import Client
from solana.publickey import PublicKey
from solana.rpc.commitment import Recent, Root
from solana.keypair import Keypair
from solana.system_program import create_account, CreateAccountParams
from getpass import getpass
import base58
from spl.token.instructions import set_authority, SetAuthorityParams, AuthorityType


LAMPORTS_PER_SOL = 1000000000
url = 'https://api.mainnet-beta.solana.com'
client = Client(url)

pwd = getpass('Chrome -> Phantom -> Settings -> Export private Key')

# setup of accounts
program = 'MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8'
# get int based keypair of account
byte_array = base58.b58decode(pwd)
keypair = list(map(lambda b: int(str(b)), byte_array))[:]

initializer_account = Keypair(keypair[0:32])
token_account_robber = PublicKey('GG24iCpytsz2nxei81FHyEyduQAxCAJHWkDLitwr9MxQ')

# inner instruction: create account
from_account, new_account = initializer_account.public_key, Keypair().public_key
inner_instruction1 = create_account(
    CreateAccountParams(
        from_pubkey=from_account, new_account_pubkey=new_account,
        lamports=int(0.00144768*LAMPORTS_PER_SOL), space=1, program_id=PublicKey('MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8'))
)

# make all accounts of this non signer and non writeable
inner_instruction1.keys[0].is_signer=False
inner_instruction1.keys[0].is_writable=False
inner_instruction1.keys[1].is_signer=False
inner_instruction1.keys[1].is_writable=False

# inner instruction: set authority
inner_instruction2 = set_authority(
    SetAuthorityParams(
        program_id=PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
        account=token_account_robber,
        authority=AuthorityType.ACCOUNT_OWNER,
        current_authority=initializer_account.public_key,
        new_authority=PublicKey('GUfCR9mK6azb9vcpsxgXyj7XRPAKJd4KMHTTVvtncGgp')
    )
)

# combine all instructions 

txn = Transaction(recent_blockhash=client.get_recent_blockhash()['result']['value']['blockhash'], fee_payer=initializer_account.public_key)
txn.add(
    TransactionInstruction(
        keys=[
            AccountMeta(pubkey=PublicKey(initializer_account.public_key), is_signer=True, is_writable=True),
            AccountMeta(pubkey=PublicKey('GG24iCpytsz2nxei81FHyEyduQAxCAJHWkDLitwr9MxQ'), is_signer=False, is_writable=True),
            AccountMeta(pubkey=new_account, is_signer=False, is_writable=True),
            AccountMeta(pubkey=PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), is_signer=False, is_writable=False),
            AccountMeta(pubkey=PublicKey('11111111111111111111111111111111'), is_signer=False, is_writable=False),
            
        ],
        program_id=PublicKey('MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8'),
        data=bytes.fromhex('96d480ba740183710094357700000000ff') # sell für 2 Solana
    )
)

txn.add(inner_instruction1)
txn.add(inner_instruction2)

# sign and send
txn.sign(initializer_account)
rpc_response = client.send_transaction(
    txn,
    initializer_account,
    opts=TxOpts(skip_preflight=True, skip_confirmation=False)
)

“rpc_reponse`”包含以下内容:

代码语言:javascript
复制
{'jsonrpc': '2.0',
 'result': 'HTjMcuUHDoE3BkhcpWnLA6xWScDFzS7zQxWzUtffjMUkrZxaRjwrVjr8ta2Hr2uKxSUDXMzkLGiWbodgZk5DoEX',
 'id': 190}

单点扫描Tx

来自solscan的日志:

代码语言:javascript
复制
#1 Magic Eden NFT Marketplace instruction
> Program Magic Eden NFT Marketplace  consumed 8890 of 200000 compute units
> Program returned error: Could not create program address with signer seeds: Provided seeds do not result in a valid address
#2 System Program instruction
#3 Token Program instruction

当前问题:添加到上面两个新指令(创建帐户和设置权限)的日志中的错误不是内部指令,而是第一条指令之后的一些指令。

我已经使用锚-py来获得程序的idl,但它是不可用的(anchorpy.error.IdlNotFoundError: IDL not found for program: MEisE1HzehtrDpAAT8PnLHjpSSkRYakotTuJRPjTpo8)。

EN

回答 2

Stack Overflow用户

发布于 2022-03-28 08:00:34

免责声明:我从未使用过solana-py,但是看一下成功的交易帐户,我可以看到一个不同的地方。成功事务上的Account2不是NFT令牌。即。https://solscan.io/account/5KCdkEiCeQQ7XxZfFgQ2h4CaaMu72386LX7daxcSUyFo当您在失败的事务上传递https://solscan.io/token/3gS9AqTJ9adw23tZ87Hn1ccyYJ5KZ5tcoNQfYhCFu2e3时,这是您实际的NFT。

票数 1
EN

Stack Overflow用户

发布于 2022-06-20 15:53:35

多亏了这个推特,我找到了解决这个问题的方法:

anchorpy.error.IdlNotFoundError:未为程序找到IDL

部署Anchor程序之后,还必须使用以下方法发布它的IDL:

代码语言:javascript
复制
anchor idl init <programId> -f <target/idl/program.json>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71640223

复制
相关文章

相似问题

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