Skip to content

Instantly share code, notes, and snippets.

@jordanmessina
Created December 14, 2018 19:32
Show Gist options
  • Save jordanmessina/34c849d0305df874cfb89f6cfc7a4081 to your computer and use it in GitHub Desktop.
Save jordanmessina/34c849d0305df874cfb89f6cfc7a4081 to your computer and use it in GitHub Desktop.
Backend Order Matching
# https://web3py.readthedocs.io/en/stable/web3.eth.account.html
import json
import os
from web3 import Web3
from django.conf import settings
from api.lib import w3
from api.models import Order
buy_order = Order.objects.get(id=50957)
wyvern_addr = Web3.toChecksumAddress('0x7be8076f4ea4a4ad08075c2508e481d6c946d12b')
user_addr = Web3.toChecksumAddress('0xfec9B10D0D4A8d0ff4C42be035ecd3a503d80C3a')
pk = 'FILL IN'
nonce = w3.eth.getTransactionCount(user_addr)
with open(os.path.join(settings.BASE_DIR, '../', 'api', 'abi', 'auctions', 'WyvernExchange.json'), 'r') as wyvern_abi_file:
wyvern_abi = json.loads(wyvern_abi_file.read())
contract = w3.eth.contract(address=wyvern_addr, abi=wyvern_abi)
wyvern_tx = contract.functions.atomicMatch_(
[
Web3.toChecksumAddress("0x7be8076f4ea4a4ad08075c2508e481d6c946d12b"),
Web3.toChecksumAddress("0x74b78e98093f5b522a7ebdac3b994641ca7c2b20"),
Web3.toChecksumAddress("0x0000000000000000000000000000000000000000"),
Web3.toChecksumAddress("0x5b3256965e7c3cf26e11fcaf296dfc8807c01073"),
Web3.toChecksumAddress("0xbfde6246df72d3ca86419628cac46a9d2b60393c"),
Web3.toChecksumAddress("0x0000000000000000000000000000000000000000"),
Web3.toChecksumAddress("0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359"),
Web3.toChecksumAddress("0x7be8076f4ea4a4ad08075c2508e481d6c946d12b"),
Web3.toChecksumAddress("0xfec9b10d0d4a8d0ff4c42be035ecd3a503d80c3a"),
Web3.toChecksumAddress("0x74b78e98093f5b522a7ebdac3b994641ca7c2b20"),
Web3.toChecksumAddress("0x0000000000000000000000000000000000000000"),
Web3.toChecksumAddress("0xbfde6246df72d3ca86419628cac46a9d2b60393c"),
Web3.toChecksumAddress("0x0000000000000000000000000000000000000000"),
Web3.toChecksumAddress("0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359")
],
[
0,
0,
0,
0,
10000000000000000,
0,
1544798934,
0,
57033639861506436517672134500047875054866400844296650918797624893449440780169,
0,
0,
0,
0,
10000000000000000,
0,
1544798948,
0,
22630348737028669552401187809094560133473408132691446000700049733396924285329
],
[1, 0, 0, 0, 1, 1, 0, 0],
w3.toBytes(hexstr="0x23b872dd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074b78e98093f5b522a7ebdac3b994641ca7c2b2000000000000000000000000000000000000000000000000000000000000033bc"),
w3.toBytes(hexstr="0x23b872dd000000000000000000000000fec9b10d0d4a8d0ff4c42be035ecd3a503d80c3a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033bc"),
w3.toBytes(hexstr="0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
w3.toBytes(hexstr="0x000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000"),
w3.toBytes(hexstr="0x"),
w3.toBytes(hexstr="0x"),
[28, 28],
[
w3.toBytes(hexstr="0x35d3b06b72de6ef3b146f913a84ee0ac1e9cba7e5007f61319cc99409d48e572"),
w3.toBytes(hexstr="0x678b2f529956d024781621603a5e0d1a88c7db9d2eb69b3aa74222951e6440a1"),
w3.toBytes(hexstr="0x35d3b06b72de6ef3b146f913a84ee0ac1e9cba7e5007f61319cc99409d48e572"),
w3.toBytes(hexstr="0x678b2f529956d024781621603a5e0d1a88c7db9d2eb69b3aa74222951e6440a1"),
w3.toBytes(hexstr="0xeb84928d21dc4dfca98642f6c9ad5cad6f780c37eb17b8afa415c23444b76b8d")
],
).buildTransaction({'chainId': 1, 'gas': 357948, 'gasPrice': w3.toWei('7', 'gwei'), 'nonce': nonce,})
signed = w3.eth.account.signTransaction(wyvern_tx, private_key=pk)
w3.eth.sendRawTransaction(signed.rawTransaction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment