python OpenSea API V2 -创建列表时订单签名无效

pb3s4cty  于 2023-03-11  发布在  Python
关注(0)|答案(3)|浏览(202)

我想通过OpenSea API与Python创建列表。我有回应:{"errors":["['Invalid order signature']"]}.我在文档中找不到要签名的信息。目前我正在签名订单参数。下面是我的代码:

import requests
from web3.auto import w3
from eth_account.messages import encode_defunct
import time

def create_order_model():
    current_time = int(time.time())
    order = {
        "offerer": "0xd107AC5e5830BB95f880cA3b1270ccCdAA0A3c5e",
        "zone": "0x00000000e88fe2628ebc5da81d2b3cead633e89e",
        "zoneHash": "0x3000000000000000000000000000000000000000000000000000000000000000",
        "startTime": current_time,
        "endTime": current_time + 2629743, # current_time + 1 month in seconds
        "orderType": 2,
        "offer": [
            {
                "itemType": 2,
                "token": "0x45aeb17Db4dd06FF9Ca6cB1E37455AAF761Bdc14",
                "identifierOrCriteria": "1",
                "startAmount": "1",
                "endAmount": "1",
            },
        ],
        "consideration": [
            {
                "itemType": 0,
                "token": "0x0000000000000000000000000000000000000000",
                "identifierOrCriteria": "0",
                "startAmount": "9750000000000000000",
                "endAmount": "9750000000000000000",
                "recipient": "0xd107AC5e5830BB95f880cA3b1270ccCdAA0A3c5e",
            },
            {
                "itemType": 0,
                "token": "0x0000000000000000000000000000000000000000",
                "identifierOrCriteria": "0",
                "startAmount": "250000000000000000",
                "endAmount": "250000000000000000",
                "recipient": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
            },
        ],
        "totalOriginalConsiderationItems": 2,
        "salt": 12686911856931635052326433555881236148,
        "conduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
        "nonce": 0,
        "counter": 0
    }
    return order

def sing_order(msg):
    private_key = "PRIVATE_KEY"
    message = encode_defunct(text=str(msg))
    signed_message = w3.eth.account.sign_message(message, private_key=private_key)
    return signed_message.signature.hex()


def main():
    url = "https://testnets-api.opensea.io/v2/orders/goerli/seaport/listings"
    headers = {
        "accept": "application/json",
        "content-type": "application/json"
    }

    order_parameters = create_order_model()
    print(order_parameters)

    signature = sing_order(order_parameters)
    print(signature)

    params = {"parameters": order_parameters, "signature": str(signature)}
    response = requests.post(url, headers=headers, json=params)
    print(response.text)

if __name__ == '__main__':
    main()

seaport-js内部(用于JavaScript的SDK:https://github.com/ProjectOpenSea/seaport-js/blob/fb 1c 40 d 776070 a8 ee 57735 ad 17 f2 bdb 4a 91 ac 7 c6/src/seaport.ts#L386)我发现有一个函数可以对数据singOrder()进行签名,并试图将这个想法转换成Python。这是我转换sign_order的效果:

def sing_order(msg):
    private_key = "PRIVATE_KEY"
    domain_data = {
        "name": "Seaport",
        "version": "1.1",
        "chainId": 5,
        "verifyingContract": "0x00000000e88fe2628ebc5da81d2b3cead633e89e",
    }
    eip_721_order_type = {
        "OrderComponents": [
            {"name": "offerer", "type": "address"},
            {"name": "zone", "type": "address"},
            {"name": "offer", "type": "OfferItem[]"},
            {"name": "consideration", "type": "ConsiderationItem[]"},
            {"name": "orderType", "type": "uint8"},
            {"name": "startTime", "type": "uint256"},
            {"name": "endTime", "type": "uint256"},
            {"name": "zoneHash", "type": "bytes32"},
            {"name": "salt", "type": "uint256"},
            {"name": "conduitKey", "type": "bytes32"},
            {"name": "counter", "type": "uint256"},
        ],
        "OfferItem": [
            {"name": "itemType", "type": "uint8"},
            {"name": "token", "type": "address"},
            {"name": "identifierOrCriteria", "type": "uint256"},
            {"name": "startAmount", "type": "uint256"},
            {"name": "endAmount", "type": "uint256"},
        ],
        "ConsiderationItem": [
            {"name": "itemType", "type": "uint8"},
            {"name": "token", "type": "address"},
            {"name": "identifierOrCriteria", "type": "uint256"},
            {"name": "startAmount", "type": "uint256"},
            {"name": "endAmount", "type": "uint256"},
            {"name": "recipient", "type": "address"},
        ],
    }
    order_components = str(msg)
    message = encode_defunct(text=(str(domain_data) + str(eip_721_order_type) + str(order_components)))
    signed_message = w3.eth.account.sign_message(message, private_key=private_key)
    return signed_message.signature.hex()

您是否知道如何正确签署OpenSea API可接受的订单?

vq8itlhq

vq8itlhq1#

是的,有一些注意事项。我解释了如何使用Seaport SDK中的CreateOrder,然后在这个github链接中使用Opensea API。CreateOrder的结构与API结构略有不同。

rggaifut

rggaifut2#

看看这个https://github.com/AliETninja/testnet-bidding,我有同样的问题你有,然后我找到了解决方案,如果你试图使用主网你应该改变“chainID”为1

w8f9ii69

w8f9ii693#

使用Javascript和Seaport SDK时出现此错误的用户。请使用版本1.4而不是默认版本1.1初始化Seaport

const seaport = new Seaport(signer, { seaportVersion: '1.4' });

相关问题