修改链交互操作的gas和gasPrice

This commit is contained in:
CounterFire2023 2023-06-26 18:45:00 +08:00
parent e0591c1be5
commit 3edab20653
4 changed files with 168 additions and 241 deletions

View File

@ -1,13 +1,13 @@
import Web3 from "web3";
import { abiERC1155 } from "../abis/abiERC1155";
import { universalChainCb } from "../util/chain.util";
import { timeoutFetch } from "../util/net.util";
import { getFormattedIpfsUrl } from "../util/wallet.util";
import Web3 from 'web3';
import { abiERC1155 } from '../abis/abiERC1155';
import { universalChainCb } from '../util/chain.util';
import { timeoutFetch } from '../util/net.util';
import { getFormattedIpfsUrl } from '../util/wallet.util';
export const ERC1155 = "ERC1155";
export const ERC1155_INTERFACE_ID = "0xd9b67a26";
export const ERC1155_METADATA_URI_INTERFACE_ID = "0x0e89341c";
export const ERC1155_TOKEN_RECEIVER_INTERFACE_ID = "0x4e2312e0";
export const ERC1155 = 'ERC1155';
export const ERC1155_INTERFACE_ID = '0xd9b67a26';
export const ERC1155_METADATA_URI_INTERFACE_ID = '0x0e89341c';
export const ERC1155_TOKEN_RECEIVER_INTERFACE_ID = '0x4e2312e0';
export class ERC1155Standard {
private web3: Web3;
@ -22,13 +22,8 @@ export class ERC1155Standard {
* @param address - ERC1155 asset contract address.
* @returns Promise resolving to whether the contract implements ERC1155 URI Metadata interface.
*/
contractSupportsURIMetadataInterface = async (
address: string
): Promise<boolean> => {
return this.contractSupportsInterface(
address,
ERC1155_METADATA_URI_INTERFACE_ID
);
contractSupportsURIMetadataInterface = async (address: string): Promise<boolean> => {
return this.contractSupportsInterface(address, ERC1155_METADATA_URI_INTERFACE_ID);
};
/**
@ -37,13 +32,8 @@ export class ERC1155Standard {
* @param address - ERC1155 asset contract address.
* @returns Promise resolving to whether the contract implements ERC1155 Token Receiver interface.
*/
contractSupportsTokenReceiverInterface = async (
address: string
): Promise<boolean> => {
return this.contractSupportsInterface(
address,
ERC1155_TOKEN_RECEIVER_INTERFACE_ID
);
contractSupportsTokenReceiverInterface = async (address: string): Promise<boolean> => {
return this.contractSupportsInterface(address, ERC1155_TOKEN_RECEIVER_INTERFACE_ID);
};
/**
@ -52,9 +42,7 @@ export class ERC1155Standard {
* @param address - ERC1155 asset contract address.
* @returns Promise resolving to whether the contract implements the base ERC1155 interface.
*/
contractSupportsBase1155Interface = async (
address: string
): Promise<boolean> => {
contractSupportsBase1155Interface = async (address: string): Promise<boolean> => {
return this.contractSupportsInterface(address, ERC1155_INTERFACE_ID);
};
@ -68,16 +56,14 @@ export class ERC1155Standard {
getTokenURI = async (address: string, tokenId: string): Promise<string> => {
const contract = new this.web3.eth.Contract(abiERC1155, address);
return new Promise<string>((resolve, reject) => {
contract.methods
.tokenURI(tokenId)
.call((error: Error, result: string) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
contract.methods.tokenURI(tokenId).call((error: Error, result: string) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
});
};
@ -89,25 +75,17 @@ export class ERC1155Standard {
* @param tokenId - ERC1155 asset identifier.
* @returns Promise resolving to the 'balanceOf'.
*/
getBalanceOf = async (
contractAddress: string,
address: string,
tokenId: string
): Promise<number> => {
getBalanceOf = async (contractAddress: string, address: string, tokenId: string): Promise<number> => {
const contract = new this.web3.eth.Contract(abiERC1155, contractAddress);
return new Promise<number>((resolve, reject) => {
contract.methods.balanceOf(
address,
tokenId,
(error: Error, result: number) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
contract.methods.balanceOf(address, tokenId, (error: Error, result: number) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
);
resolve(result);
});
});
};
@ -118,23 +96,17 @@ export class ERC1155Standard {
* @param interfaceId - Interface identifier.
* @returns Promise resolving to whether the contract implements `interfaceID`.
*/
private contractSupportsInterface = async (
address: string,
interfaceId: string
): Promise<boolean> => {
private contractSupportsInterface = async (address: string, interfaceId: string): Promise<boolean> => {
const contract = new this.web3.eth.Contract(abiERC1155, address);
return new Promise<boolean>((resolve, reject) => {
contract.methods.supportsInterface(
interfaceId,
(error: Error, result: boolean) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
contract.methods.supportsInterface(interfaceId, (error: Error, result: boolean) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
);
resolve(result);
});
});
};
@ -164,7 +136,7 @@ export class ERC1155Standard {
if (tokenId) {
tokenURI = await this.getTokenURI(address, tokenId);
if (tokenURI.startsWith("ipfs://")) {
if (tokenURI.startsWith('ipfs://')) {
tokenURI = getFormattedIpfsUrl(ipfsGateway, tokenURI, true);
}
@ -172,7 +144,7 @@ export class ERC1155Standard {
const response = await timeoutFetch(tokenURI);
const object = await response.json();
image = object?.image;
if (image?.startsWith("ipfs://")) {
if (image?.startsWith('ipfs://')) {
image = getFormattedIpfsUrl(ipfsGateway, image, true);
}
} catch {
@ -207,9 +179,7 @@ export class ERC1155Standard {
}) {
const contract = new this.web3.eth.Contract(abiERC1155, address);
if (!gas) {
gas = await contract.methods
.safeBatchTransferFrom(from, to, tokenIds, amounts, [])
.estimateGas();
gas = await contract.methods.safeBatchTransferFrom(from, to, tokenIds, amounts, []).estimateGas();
}
gas = (gas * 1.1) | 1;
if (estimate) {
@ -227,17 +197,17 @@ export class ERC1155Standard {
}
const logData = {
gas,
title: "transfer",
title: 'transfer',
details: detailArr,
};
let gasPrice = await this.web3.eth.getGasPrice();
return universalChainCb(
logData,
contract.methods
.safeBatchTransferFrom(from, to, tokenIds, amounts, [])
.send({
from,
gas,
})
contract.methods.safeBatchTransferFrom(from, to, tokenIds, amounts, []).send({
from,
gas,
gasPrice,
})
);
}
}

View File

@ -1,8 +1,8 @@
import Web3 from "web3";
import { abiERC20 } from "../abis/abiERC20";
import { BN, toUtf8 } from "ethereumjs-util";
import { universalChainCb } from "../util/chain.util";
import { toWeiBn } from "../util/number.util";
import Web3 from 'web3';
import { abiERC20 } from '../abis/abiERC20';
import { BN, toUtf8 } from 'ethereumjs-util';
import { universalChainCb } from '../util/chain.util';
import { toWeiBn } from '../util/number.util';
export class ERC20Standard {
private web3: Web3;
@ -21,17 +21,15 @@ export class ERC20Standard {
async getBalanceOf(address: string, selectedAddress: string): Promise<BN> {
const contract = new this.web3.eth.Contract(abiERC20, address);
return new Promise<BN>((resolve, reject) => {
contract.methods
.balanceOf(selectedAddress)
.call({ from: selectedAddress }, (error: Error, result: BN) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
console.log("getBalanceOf success " + result);
resolve(result);
});
contract.methods.balanceOf(selectedAddress).call({ from: selectedAddress }, (error: Error, result: BN) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
console.log('getBalanceOf success ' + result);
resolve(result);
});
});
}
@ -126,10 +124,7 @@ export class ERC20Standard {
decimals: string | undefined;
balance: BN | undefined;
}> {
const [decimals, symbol] = await Promise.all([
this.getTokenDecimals(address),
this.getTokenSymbol(address),
]);
const [decimals, symbol] = await Promise.all([this.getTokenDecimals(address), this.getTokenSymbol(address)]);
let balance;
if (userAddress) {
balance = await this.getBalanceOf(address, userAddress);
@ -138,7 +133,7 @@ export class ERC20Standard {
decimals,
symbol,
balance,
standard: "ERC20",
standard: 'ERC20',
};
}
@ -162,7 +157,7 @@ export class ERC20Standard {
const contract = new this.web3.eth.Contract(abiERC20, address);
let amountBN = toWeiBn(amount, decimal);
if (!gas) {
gas = await contract.methods.transfer(to, "0").estimateGas();
gas = await contract.methods.transfer(to, '0').estimateGas();
}
gas = (gas * 1.1) | 1;
if (estimate) {
@ -170,22 +165,24 @@ export class ERC20Standard {
}
const logData = {
gas,
title: "transfer",
title: 'transfer',
details: [
{
address,
from,
to,
value: amountBN,
id: "0",
id: '0',
},
],
};
let gasPrice = await this.web3.eth.getGasPrice();
return universalChainCb(
logData,
contract.methods.transfer(to, amountBN).send({
from,
gas,
gasPrice,
})
);
}

View File

@ -1,13 +1,13 @@
import Web3 from "web3";
import { abiERC721 } from "../abis/abiERC721";
import { universalChainCb } from "../util/chain.util";
import { timeoutFetch } from "../util/net.util";
import { getFormattedIpfsUrl } from "../util/wallet.util";
import Web3 from 'web3';
import { abiERC721 } from '../abis/abiERC721';
import { universalChainCb } from '../util/chain.util';
import { timeoutFetch } from '../util/net.util';
import { getFormattedIpfsUrl } from '../util/wallet.util';
export const ERC721 = "ERC721";
export const ERC721_INTERFACE_ID = "0x80ac58cd";
export const ERC721_METADATA_INTERFACE_ID = "0x5b5e139f";
export const ERC721_ENUMERABLE_INTERFACE_ID = "0x780e9d63";
export const ERC721 = 'ERC721';
export const ERC721_INTERFACE_ID = '0x80ac58cd';
export const ERC721_METADATA_INTERFACE_ID = '0x5b5e139f';
export const ERC721_ENUMERABLE_INTERFACE_ID = '0x780e9d63';
export class ERC721Standard {
private web3: Web3;
@ -22,13 +22,8 @@ export class ERC721Standard {
* @param address - ERC721 asset contract address.
* @returns Promise resolving to whether the contract implements ERC721Metadata interface.
*/
contractSupportsMetadataInterface = async (
address: string
): Promise<boolean> => {
return this.contractSupportsInterface(
address,
ERC721_METADATA_INTERFACE_ID
);
contractSupportsMetadataInterface = async (address: string): Promise<boolean> => {
return this.contractSupportsInterface(address, ERC721_METADATA_INTERFACE_ID);
};
/**
@ -37,13 +32,8 @@ export class ERC721Standard {
* @param address - ERC721 asset contract address.
* @returns Promise resolving to whether the contract implements ERC721Enumerable interface.
*/
contractSupportsEnumerableInterface = async (
address: string
): Promise<boolean> => {
return this.contractSupportsInterface(
address,
ERC721_ENUMERABLE_INTERFACE_ID
);
contractSupportsEnumerableInterface = async (address: string): Promise<boolean> => {
return this.contractSupportsInterface(address, ERC721_ENUMERABLE_INTERFACE_ID);
};
/**
@ -52,9 +42,7 @@ export class ERC721Standard {
* @param address - ERC721 asset contract address.
* @returns Promise resolving to whether the contract implements ERC721 interface.
*/
contractSupportsBase721Interface = async (
address: string
): Promise<boolean> => {
contractSupportsBase721Interface = async (address: string): Promise<boolean> => {
return this.contractSupportsInterface(address, ERC721_INTERFACE_ID);
};
@ -66,42 +54,31 @@ export class ERC721Standard {
* @param index - A collectible counter less than `balanceOf(selectedAddress)`.
* @returns Promise resolving to token identifier for the 'index'th asset assigned to 'selectedAddress'.
*/
getCollectibleTokenId = async (
address: string,
selectedAddress: string,
index: number
): Promise<string> => {
getCollectibleTokenId = async (address: string, selectedAddress: string, index: number): Promise<string> => {
const contract = new this.web3.eth.Contract(abiERC721, address);
return new Promise<string>((resolve, reject) => {
contract.methods
.tokenOfOwnerByIndex(selectedAddress, index)
.call((error: Error, result: string) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
contract.methods.tokenOfOwnerByIndex(selectedAddress, index).call((error: Error, result: string) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
});
};
getBalance = async (
address: string,
selectedAddress: string
): Promise<number> => {
getBalance = async (address: string, selectedAddress: string): Promise<number> => {
const contract = new this.web3.eth.Contract(abiERC721, address);
return new Promise<number>((resolve, reject) => {
contract.methods
.balanceOf(selectedAddress)
.call((error: Error, result: number) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
contract.methods.balanceOf(selectedAddress).call((error: Error, result: number) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
});
};
@ -114,23 +91,19 @@ export class ERC721Standard {
*/
getTokenURI = async (address: string, tokenId: string): Promise<string> => {
const contract = new this.web3.eth.Contract(abiERC721, address);
const supportsMetadata = await this.contractSupportsMetadataInterface(
address
);
const supportsMetadata = await this.contractSupportsMetadataInterface(address);
if (!supportsMetadata) {
throw new Error("Contract does not support ERC721 metadata interface.");
throw new Error('Contract does not support ERC721 metadata interface.');
}
return new Promise<string>((resolve, reject) => {
contract.methods
.tokenURI(tokenId)
.call((error: Error, result: string) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
contract.methods.tokenURI(tokenId).call((error: Error, result: string) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
});
};
@ -202,22 +175,17 @@ export class ERC721Standard {
* @param interfaceId - Interface identifier.
* @returns Promise resolving to whether the contract implements `interfaceID`.
*/
private contractSupportsInterface = async (
address: string,
interfaceId: string
): Promise<boolean> => {
private contractSupportsInterface = async (address: string, interfaceId: string): Promise<boolean> => {
const contract = new this.web3.eth.Contract(abiERC721, address);
return new Promise<boolean>((resolve, reject) => {
contract.methods
.supportsInterface(interfaceId)
.call((error: Error, result: boolean) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
contract.methods.supportsInterface(interfaceId).call((error: Error, result: boolean) => {
/* istanbul ignore if */
if (error) {
reject(error);
return;
}
resolve(result);
});
});
};
@ -263,14 +231,14 @@ export class ERC721Standard {
if (tokenId) {
try {
tokenURI = await this.getTokenURI(address, tokenId);
if (tokenURI.startsWith("ipfs://")) {
if (tokenURI.startsWith('ipfs://')) {
tokenURI = getFormattedIpfsUrl(ipfsGateway, tokenURI, true);
}
const response = await timeoutFetch(tokenURI);
const object = await response.json();
image = object ? object.image : "";
if (image.startsWith("ipfs://")) {
image = object ? object.image : '';
if (image.startsWith('ipfs://')) {
image = getFormattedIpfsUrl(ipfsGateway, image, true);
}
} catch {
@ -304,9 +272,7 @@ export class ERC721Standard {
}) {
const contract = new this.web3.eth.Contract(abiERC721, address);
if (!gas) {
gas = await contract.methods
.safeTransferFrom(from, to, tokenId)
.estimateGas();
gas = await contract.methods.safeTransferFrom(from, to, tokenId).estimateGas();
}
gas = (gas * 1.1) | 1;
if (estimate) {
@ -314,7 +280,7 @@ export class ERC721Standard {
}
const logData = {
gas,
title: "transfer",
title: 'transfer',
details: [
{
address,
@ -324,11 +290,13 @@ export class ERC721Standard {
},
],
};
let gasPrice = await this.web3.eth.getGasPrice();
return universalChainCb(
logData,
contract.methods.safeTransferFrom(from, to, tokenId).send({
from,
gas,
gasPrice,
})
);
}

View File

@ -1,9 +1,7 @@
import assert from 'assert';
import Web3 from 'web3';
import { abiMinterFactory } from '../abis/abiUserMinterFactory';
import { GAS_BOOST, ZERO_ADDRESS } from '../config/constants';
import { getAddressByName, universalChainCb } from '../util/chain.util';
import { SAMPLE_GAS } from './ChainCommon';
import { universalChainCb } from '../util/chain.util';
import { abiMarket } from '../abis/abiMarket';
import { abiMall } from '../abis/abiMall';
import { abiGameMarket } from '../abis/abiGameMarket';
@ -71,9 +69,10 @@ export class JCStandard {
title: 'mint_nft',
details: details,
};
let gasPrice = await this.web3.eth.getGasPrice();
return universalChainCb(
logData,
contract.methods.mintNft(address, tokenIds, startTime, saltNonce, signature).send({ gas })
contract.methods.mintNft(address, tokenIds, startTime, saltNonce, signature).send({ gas, gasPrice })
);
}
// begin of NFT Market
@ -108,16 +107,15 @@ export class JCStandard {
});
let approved = await tokenInstance.methods.getApproved(tokenId);
let gasApprove = 0;
let gasPrice = await this.web3.eth.getGasPrice();
if (approved != addressMarket) {
gasApprove = cfg.gasInfo.nftApprove;
gasApprove = await tokenInstance.methods.approve(addressMarket, tokenId).estimateGas();
gasApprove = (gasApprove * GAS_BOOST) | 1;
await tokenInstance.methods.approve(addressMarket, tokenId).send({ gas: gasApprove, gasPrice });
}
if (!gas) {
gas = cfg.gasInfo.marketSellNFT;
// gas = await contract.methods
// .sell(nftToken, currency, tokenId, price, amount)
// .estimateGas();
gas = await contract.methods.sell(nftToken, currency, tokenId, price, amount).estimateGas();
}
gas = (gas * GAS_BOOST) | 1;
@ -143,11 +141,11 @@ export class JCStandard {
title: 'market_sell',
details: details,
};
if (approved != addressMarket) {
await tokenInstance.methods.approve(addressMarket, tokenId).send({ gas: gasApprove });
console.log('approve done');
}
return universalChainCb(logData, contract.methods.sell(nftToken, currency, tokenId, price, amount).send({ gas }));
return universalChainCb(
logData,
contract.methods.sell(nftToken, currency, tokenId, price, amount).send({ gas, gasPrice })
);
}
async marketUpdatePrice({
@ -170,8 +168,7 @@ export class JCStandard {
from: jc.wallet.currentAccAddr,
});
if (!gas) {
// gas = await contract.methods.updatePrice(orderId, price).estimateGas();
gas = cfg.gasInfo.marketUpdatePrice;
gas = await contract.methods.updatePrice(orderId, price).estimateGas();
}
gas = (gas * GAS_BOOST) | 1;
if (estimate) {
@ -190,7 +187,8 @@ export class JCStandard {
title: 'market_update_price',
details: details,
};
return universalChainCb(logData, contract.methods.updatePrice(orderId, price).send({ gas }));
let gasPrice = await this.web3.eth.getGasPrice();
return universalChainCb(logData, contract.methods.updatePrice(orderId, price).send({ gas, gasPrice }));
}
async marketCancelOrder({ orderId, gas, estimate }: { orderId: string; gas?: number; estimate: number }) {
@ -227,12 +225,13 @@ export class JCStandard {
id: orderInfo.tokenId,
},
];
let gasPrice = await this.web3.eth.getGasPrice();
const logData = {
gas,
title: 'market_cancel_order',
details: details,
};
return universalChainCb(logData, contract.methods.cancelOrder(orderId).send({ gas }));
return universalChainCb(logData, contract.methods.cancelOrder(orderId).send({ gas, gasPrice }));
}
async marketBuy({ orderId, gas, estimate }: { orderId: string; gas?: number; estimate: number }) {
@ -255,13 +254,14 @@ export class JCStandard {
let approved = await tokenInstance.methods.allowance(jc.wallet.currentAccAddr, addressMarket).call();
console.log('approved:: ', approved);
let gasApprove = 0;
let gasPrice = await this.web3.eth.getGasPrice();
if (approved < orderInfo.price) {
gasApprove = cfg.gasInfo.cecApprove;
gasApprove = await tokenInstance.methods.approve(addressMarket, orderInfo.price).estimateGas();
gasApprove = (gasApprove * GAS_BOOST) | 1;
await tokenInstance.methods.approve(addressMarket, orderInfo.price).send({ gas: gasApprove, gasPrice });
}
gasApprove = (gasApprove * GAS_BOOST) | 1;
if (!gas) {
// gas = await contract.methods.buy(orderId).estimateGas();
gas = cfg.gasInfo.marketBuy;
gas = await contract.methods.buy(orderId).estimateGas();
}
gas = (gas * GAS_BOOST) | 1;
// begin of increase allowance
@ -295,10 +295,7 @@ export class JCStandard {
title: 'market_buy',
details: details,
};
if (approved < orderInfo.price) {
await tokenInstance.methods.approve(addressMarket, orderInfo.price).send({ gas: gasApprove });
}
return universalChainCb(logData, contract.methods.buy(orderId).send({ gas }));
return universalChainCb(logData, contract.methods.buy(orderId).send({ gas, gasPrice }));
}
async marketOrderInfo(orderId: string) {
@ -349,15 +346,15 @@ export class JCStandard {
let approved = await tokenInstance.methods.allowance(jc.wallet.currentAccAddr, addressGameMall).call();
console.log('approved:: ', approved);
let gasApprove = 0;
let gasPrice = await this.web3.eth.getGasPrice();
if (approved < price) {
gasApprove = cfg.gasInfo.cecApprove;
gasApprove = await tokenInstance.methods.approve(addressGameMall, price).estimateGas();
gasApprove = (gasApprove * GAS_BOOST) | 1;
await tokenInstance.methods.approve(addressGameMall, price).send({ gas: gasApprove, gasPrice });
}
gasApprove = (gasApprove * GAS_BOOST) | 1;
if (!gas) {
// gas = await contract.methods
// .buy(orderId, currency, price, startTime, saltNonce, signature)
// .estimateGas();
gas = cfg.gasInfo.gameMallBuy;
gas = await contract.methods.buy(orderId, currency, price, startTime, saltNonce, signature).estimateGas();
}
gas = (gas * GAS_BOOST) | 1;
if (estimate) {
@ -382,12 +379,10 @@ export class JCStandard {
title: 'game_mall_buy',
details: details,
};
if (approved < price) {
await tokenInstance.methods.approve(addressGameMall, price).send({ gas: gasApprove });
}
return universalChainCb(
logData,
contract.methods.buy(orderId, currency, price, startTime, saltNonce, signature).send({ gas })
contract.methods.buy(orderId, currency, price, startTime, saltNonce, signature).send({ gas, gasPrice })
);
}
// end of game item mall
@ -429,16 +424,15 @@ export class JCStandard {
let approved = await tokenInstance.methods.allowance(jc.wallet.currentAccAddr, addressGameMarket).call();
console.log('approved:: ', approved);
let gasApprove = 0;
let gasPrice = await this.web3.eth.getGasPrice();
if (approved < price) {
gasApprove = cfg.gasInfo.cecApprove;
gasApprove = await tokenInstance.methods.approve(addressGameMarket, price).estimateGas();
gasApprove = (gasApprove * GAS_BOOST) | 1;
await tokenInstance.methods.approve(addressGameMarket, price).send({ gas: gasApprove, gasPrice });
}
gasApprove = (gasApprove * GAS_BOOST) | 1;
console.log('gasApprove: ' + gasApprove);
if (!gas) {
// gas = await contract.methods
// .buy(orderId, seller, currency, price, startTime, saltNonce, signature)
// .estimateGas();
gas = cfg.gasInfo.gameMarketBuy;
gas = await contract.methods.buy(orderId, seller, currency, price, startTime, saltNonce, signature).estimateGas();
}
gas = (gas * GAS_BOOST) | 1;
console.log('gas: ' + gas);
@ -465,12 +459,9 @@ export class JCStandard {
title: 'game_market_buy',
details: details,
};
if (approved < price) {
await tokenInstance.methods.approve(addressGameMarket, price).send({ gas: gasApprove });
}
return universalChainCb(
logData,
contract.methods.buy(orderId, seller, currency, price, startTime, saltNonce, signature).send({ gas })
contract.methods.buy(orderId, seller, currency, price, startTime, saltNonce, signature).send({ gas, gasPrice })
);
}
// end of game item market
@ -513,11 +504,12 @@ export class JCStandard {
});
let approved = await tokenInstance.methods.allowance(jc.wallet.currentAccAddr, addressMall).call();
console.log('approved:: ', approved);
let gasPrice = await this.web3.eth.getGasPrice();
let gasApprove = 0;
if (approved < values[1]) {
gasApprove = cfg.gasInfo.cecApprove;
gasApprove = await tokenInstance.methods.approve(addressMall, values[1]).estimateGas();
gasApprove = (gasApprove * GAS_BOOST) | 1;
await tokenInstance.methods.approve(addressMall, values[1]).send({ gas: gasApprove });
await tokenInstance.methods.approve(addressMall, values[1]).send({ gas: gasApprove, gasPrice });
}
if (!gas) {
gas = await contract.methods.buyNFT(currency, addresses, ids, amounts, values, signature).estimateGas();
@ -557,7 +549,7 @@ export class JCStandard {
};
return universalChainCb(
logData,
contract.methods.buyNFT(currency, addresses, ids, amounts, values, signature).send({ gas })
contract.methods.buyNFT(currency, addresses, ids, amounts, values, signature).send({ gas, gasPrice })
);
}
// end of NFT Mall