简体   繁体   English

使用 Python/Web3.py 传输 ERC721 令牌

[英]Transferring ERC721 Tokens using Python/Web3.py

I can not for the life of me find any article on the entire interweb that talks about using web3.py to transfer ERC-721 tokens between wallets.我一生都无法在整个互联网上找到任何关于使用 web3.py 在钱包之间转移 ERC-721 代币的文章。 Minting, yes all day long, airdrop yes all day long, but wallet to wallet transfer, nope.铸币,是整天,空投是整天,但是钱包到钱包转移,不。 Am I missing something here, is it not possible?我在这里遗漏了什么,这不可能吗? Why is there such a lack of dialogue on this matter.为什么在这个问题上缺乏对话。 Anyways, if you could point me in the right direction or answer my question, that would be amazing.无论如何,如果你能指出我正确的方向或回答我的问题,那就太棒了。 I would tell you what I have tried so far, but the answer is nothing because I do not even know where to start.我会告诉你到目前为止我已经尝试过什么,但答案是什么,因为我什至不知道从哪里开始。 As far as I got was ...据我所知...

contract_call = contract.functions.transfer(destination_address, value)
unsigned_txn = contract_call.buildTransaction({'chainId': 1, 'gasPrice': 
w3.toWei(100, 'gwei')})

But this does not appear to be what I am looking for.但这似乎不是我想要的。

After way to much reading I finally got it done, I hope this helps somebody one day.经过大量阅读,我终于完成了,我希望有一天这对某人有所帮助。

The problem here is almost anywhere there is documentation it says to use transact( not buildTransaction when buildTransaction IS the correct way of doing this.这里的问题几乎在任何有文档说使用事务(而不是 buildTransaction 时 buildTransaction 是这样做的正确方法时)的任何地方。

Make sure you have your contract initialised properly确保您的合同已正确初始化

transferFrom arguments FROM, TO, TOKEN_ID transferFrom 参数 FROM、TO、TOKEN_ID

FROM being the wallet that owns the NFT.从成为拥有 NFT 的钱包。 TO who you are transferring the NFT to.将 NFT 转移给谁。 PRIVATE_KEY being the key to the FROM wallet. PRIVATE_KEY 是 FROM 钱包的密钥。

mint_txn = NFT_CONTRACT.functions.transferFrom(FROM, TO, 8).buildTransaction(
    {
        'from': FROM,
        'nonce': nonce,
        'gas': 1000000,
        'gasPrice': w3.toWei("70", "gwei"),

    }
)

signed_txn = w3.eth.account.sign_transaction(mint_txn, 
private_key=PRIVATE_KEY)
w3.eth.send_raw_transaction(signed_txn.rawTransaction)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM