mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
restore estApprove() function and add estTransfer() function
This commit is contained in:
parent
0a0d96aa01
commit
cab4d5b1a7
@ -1,4 +1,5 @@
|
|||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
|
import { Contract } from 'web3-eth-contract'
|
||||||
import {
|
import {
|
||||||
amountToUnits,
|
amountToUnits,
|
||||||
estimateGas,
|
estimateGas,
|
||||||
@ -10,6 +11,29 @@ import LoggerInstance from './Logger'
|
|||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimate gas cost for approval function
|
||||||
|
* @param {String} account
|
||||||
|
* @param {String} tokenAddress
|
||||||
|
* @param {String} spender
|
||||||
|
* @param {String} amount
|
||||||
|
* @param {String} force
|
||||||
|
* @param {Contract} contractInstance optional contract instance
|
||||||
|
* @return {Promise<number>}
|
||||||
|
*/
|
||||||
|
export async function estApprove(
|
||||||
|
web3: Web3,
|
||||||
|
account: string,
|
||||||
|
tokenAddress: string,
|
||||||
|
spender: string,
|
||||||
|
amount: string,
|
||||||
|
contractInstance?: Contract
|
||||||
|
): Promise<number> {
|
||||||
|
const tokenContract = contractInstance || new web3.eth.Contract(minAbi, tokenAddress)
|
||||||
|
|
||||||
|
return estimateGas(account, tokenContract.methods.approve, spender, amount)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Approve spender to spent amount tokens
|
* Approve spender to spent amount tokens
|
||||||
* @param {String} account
|
* @param {String} account
|
||||||
@ -58,6 +82,29 @@ export async function approve(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimate gas cost for transfer function
|
||||||
|
* @param {String} account
|
||||||
|
* @param {String} tokenAddress
|
||||||
|
* @param {String} recipient
|
||||||
|
* @param {String} amount
|
||||||
|
* @param {String} force
|
||||||
|
* @param {Contract} contractInstance optional contract instance
|
||||||
|
* @return {Promise<number>}
|
||||||
|
*/
|
||||||
|
export async function estTransfer(
|
||||||
|
web3: Web3,
|
||||||
|
account: string,
|
||||||
|
tokenAddress: string,
|
||||||
|
recipient: string,
|
||||||
|
amount: string,
|
||||||
|
contractInstance?: Contract
|
||||||
|
): Promise<number> {
|
||||||
|
const tokenContract = contractInstance || new web3.eth.Contract(minAbi, tokenAddress)
|
||||||
|
|
||||||
|
return estimateGas(account, tokenContract.methods.transfer, recipient, amount)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves amount tokens from the caller’s account to recipient.
|
* Moves amount tokens from the caller’s account to recipient.
|
||||||
* @param {String} account
|
* @param {String} account
|
||||||
|
Loading…
x
Reference in New Issue
Block a user