cosmo / send.py
tripleS-Dev
start
1c1f3a2
raw
history blame contribute delete
No virus
1.88 kB
import json
from web3 import Web3
# Ethereum ๋…ธ๋“œ์— ์—ฐ๊ฒฐ (Infura๋‚˜ Alchemy ๊ฐ™์€ ์„œ๋น„์Šค ์‚ฌ์šฉ)
infura_url = 'https://mainnet.infura.io/v3/16185d569adf4d00a04f2d2a200cf231'
web3 = Web3(Web3.HTTPProvider(infura_url))
# ์ง€๊ฐ‘ ์ฃผ์†Œ์™€ ํ”„๋ผ์ด๋น— ํ‚ค
sender_address = '0x9526E51ee3D9bA02Ef674eB1E41FB24Dc2165380'
sender_private_key = '740e61590a4b047aeba4a416fe8155572d28c4a91759fa0596bd9f31e06b386f'
receiver_address = '0x7BC5706471B71547566ACd445e9B6e7f6CE79eF1'
nft_contract_address = '0xA4B37bE40F7b231Ee9574c4b16b7DDb7EAcDC99B'
token_id = 3493792 # ์ „์†กํ•  NFT์˜ ํ† ํฐ ID
erc721_abi = [
{
"constant": False,
"inputs": [
{
"name": "from",
"type": "address"
},
{
"name": "to",
"type": "address"
},
{
"name": "tokenId",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [],
"type": "function"
}
]
# NFT ์ปจํŠธ๋ž™ํŠธ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
nft_contract = web3.eth.contract(address=nft_contract_address, abi=erc721_abi)
# ์ „์†ก ํŠธ๋žœ์žญ์…˜ ์ƒ์„ฑ
transaction = nft_contract.functions.transferFrom(sender_address, receiver_address, token_id).build_transaction({
'from': sender_address,
'nonce': web3.eth.get_transaction_count(sender_address),
'gas': 21000, # ๊ฐ€์Šค ํ•œ๋„
'maxFeePerGas': web3.toWei('30.015832944', 'gwei'), # ์ตœ๋Œ€ ๊ธฐ๋ณธ ์š”๊ธˆ
'maxPriorityFeePerGas': web3.toWei('30', 'gwei') # ์šฐ์„  ์š”๊ธˆ
})
# ํŠธ๋žœ์žญ์…˜ ์„œ๋ช…
signed_transaction = web3.eth.account.signTransaction(transaction, sender_private_key)
# ํŠธ๋žœ์žญ์…˜ ์ „์†ก
tx_hash = web3.eth.sendRawTransaction(signed_transaction.rawTransaction)
# ํŠธ๋žœ์žญ์…˜ ํ•ด์‹œ ์ถœ๋ ฅ
print(f'Transaction hash: {web3.toHex(tx_hash)}')