ProjectOpenSea / opensea-js

TypeScript SDK for the OpenSea marketplace
https://docs.opensea.io/reference
MIT License
2.28k stars 955 forks source link

Ajdusting gasPrice of fulfillOrder method by gasPriceAdditon Method #203

Closed happyeric77 closed 1 year ago

happyeric77 commented 2 years ago

I am trying to use openseajs library's fulfillOrder method to buy NFT token. And I want to adjust the gas price to prioritize my transaction. Below shows how I do this.

I pass the tokenId, tokenAddress and owner address as arguments to the .getOrder() method to get the order instance. And then use fulfillOder() method to buy that token. But I realize that I am not able to manipulate the gas price section.

The reason why I want to do this is that in order to buy a certain popular token NFT as soon as it gets ready on sale. especially sometimes the valuable (popular) NFT buying transaction could be difficult to sign through using average gas price, so I would like to make the gas_price higher for certain NFT items. Do you think it will be possible? It will be very appreciated if anyone can let me know how to make this approach.

After checking around, I realized there is a gasPriceAddition property in seaport instance which has a default value as BigNumber(3) as below in source code:

Screen Shot 2021-10-14 at 13 54 09

So I tried to adjust the value to set the gas price and I can see it is actually set successfully and then I use it to sign the transaction without problem. the log below is printed out from my console:

[10/14 0 : 31 : 16]   * Estimated gas price: 1.000000018

[10/14 0 : 31 : 17]   * Set fastest gas price 158.000000018

[10/14 0 : 31 : 40] ---> SUCCESS: token bought: 0xa3f6b07b54948081bd7478a5080c96b102bfd35c5fe334eabfd79a7216c20d78 

But when I check the real gas price in the signed transaction from etherscan, it turns out using the average gas price instead of the set gas price. Below is my transaction: https://rinkeby.etherscan.io/tx/0xa3f6b07b54948081bd7478a5080c96b102bfd35c5fe334eabfd79a7216c20d78

I do not know why it is happening, is anybody can let me know why? I also list my code herewith below:


    async buy(order: Order, item: TargetType): Promise<string|Error> { 
        let accountAddress = this.web3._provider.addresses[0]
        let price = order.currentPrice.toString()/1e18

        // fetch all async function return
        let balance = await this.web3.eth.getBalance(accountAddress)/1e18

        this.seaport.gasPriceAddition = this.web3.utils.toBN(String(0));
        let estimatedGasPrice = (await this.seaport._computeGasPrice()).toString()/1e9
        this.printLog(`Estimated gas price: ${estimatedGasPrice}`, "h2")
        let gasPrice = await this.getGasPrice(item.transaction_speed)
        // Set addtionalGas = target gasPric - estimatedPrice
        this.seaport.gasPriceAddition = gasPrice && gasPrice>estimatedGasPrice && this.web3.utils.toBN(String(Math.round(gasPrice-estimatedGasPrice)));        

        this.printLog(`Set ${item.transaction_speed} gas price ${(await this.seaport._computeGasPrice()).toString()/1e9}`, "h2" )

        if (balance < item.max_price) {
            this.printLog("---> wallet balance is less than price, breaking the process ....\n", "p")
            process.exit(1);
        } else if (price <= item.max_price) {
            try {
                let transactionHash = await this.seaport.fulfillOrder({ order, accountAddress })
                return transactionHash as string
            } catch (e) {
                return new Error(e as string)
            }
        } else {
            return new Error(`Selling price is larger than max_price: ${item.max_price}`)
        }       
    }

Below is my understanding of source code FYI.

The gasPriceAddition property is used in _computeGasPrice as addition price to add on top of average gasPrice

Screen Shot 2021-10-14 at 13 55 27

Then I can see the gasPrice is actually passed into transaction like below:

Screen Shot 2021-10-14 at 13 53 30
txHash = await this._wyvernProtocol.wyvernExchange.atomicMatch_.sendTransactionAsync(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], txnData)
nedosa commented 2 years ago

I also ran into this, it looks like the SDK does not yet support EIP-1559 type transactions and the gasPrice is not being taken into account. Some other open issues also ask for clarification in that regard: https://github.com/ProjectOpenSea/opensea-js/issues/158

Racherin commented 2 years ago

hi, @happyeric77 @nedosa any solution yet? i'm facing with same problem

vasinl124 commented 2 years ago

+1

emorling commented 2 years ago

+1

amzfcy commented 2 years ago

+1

nmduarteus commented 2 years ago

+1

cagrisungur commented 2 years ago

Is there any update for it?

nmduarte commented 2 years ago

no update afay, but if you check #158 you'll see that @hack3r-0m made a fork that returns the encrypted data for the transaction (instead of executing it) and then you can just make the gas adjustment and send the transaction using ether/web3

Slers commented 2 years ago

@esteban-OpenSea Any update on this?

oli107 commented 2 years ago

Still waiting on an update, pls

walruzperil commented 1 year ago

Any update on this?

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.