Ajdusting gasPrice of fulfillOrder method by gasPriceAdditon Method
See original GitHub issueI 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:
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
Then I can see the gasPrice is actually passed into transaction like below:
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)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:11
Top GitHub Comments
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
Any update on this?