mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
added toWei/fromWei in datatokens
This commit is contained in:
parent
0c7e867a47
commit
82178ee3dc
@ -69,7 +69,7 @@ export class DataTokens {
|
|||||||
* Approve
|
* Approve
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} toAddress
|
* @param {String} toAddress
|
||||||
* @param {Number} amount
|
* @param {Number} amount Number of datatokens, as number. Will be converted to wei
|
||||||
* @param {Account} account
|
* @param {Account} account
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
@ -84,7 +84,9 @@ export class DataTokens {
|
|||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
{ from: account }
|
{ from: account }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods.approve(spender, amount).send()
|
const trxReceipt = await datatoken.methods
|
||||||
|
.approve(spender, this.web3.utils.toWei(String(amount)))
|
||||||
|
.send()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +94,7 @@ export class DataTokens {
|
|||||||
* Mint
|
* Mint
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {Account} account
|
* @param {Account} account
|
||||||
* @param {Number} amount
|
* @param {Number} amount Number of datatokens, as number. Will be converted to wei
|
||||||
* @param {String} toAddress - only if toAddress is different from the minter
|
* @param {String} toAddress - only if toAddress is different from the minter
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
@ -109,17 +111,19 @@ export class DataTokens {
|
|||||||
{ from: account }
|
{ from: account }
|
||||||
)
|
)
|
||||||
const estGas = await datatoken.methods
|
const estGas = await datatoken.methods
|
||||||
.mint(address, amount)
|
.mint(address, this.web3.utils.toWei(String(amount)))
|
||||||
.estimateGas(function (err, estGas) {
|
.estimateGas(function (err, estGas) {
|
||||||
if (err) console.log('Datatokens: ' + err)
|
if (err) console.log('Datatokens: ' + err)
|
||||||
return estGas
|
return estGas
|
||||||
})
|
})
|
||||||
|
|
||||||
const trxReceipt = await datatoken.methods.mint(address, amount).send({
|
const trxReceipt = await datatoken.methods
|
||||||
from: account,
|
.mint(address, this.web3.utils.toWei(String(amount)))
|
||||||
gas: estGas + 1,
|
.send({
|
||||||
gasPrice: '3000000000'
|
from: account,
|
||||||
})
|
gas: estGas + 1,
|
||||||
|
gasPrice: '3000000000'
|
||||||
|
})
|
||||||
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
@ -128,7 +132,7 @@ export class DataTokens {
|
|||||||
* Transfer from Account to Address
|
* Transfer from Account to Address
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} toAddress
|
* @param {String} toAddress
|
||||||
* @param {Number} amount
|
* @param {Number} amount Number of datatokens, as number. Will be converted to wei
|
||||||
* @param {Account} account
|
* @param {Account} account
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
@ -143,7 +147,9 @@ export class DataTokens {
|
|||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
{ from: account }
|
{ from: account }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods.transfer(toAddress, amount).send()
|
const trxReceipt = await datatoken.methods
|
||||||
|
.transfer(toAddress, this.web3.utils.toWei(String(amount)))
|
||||||
|
.send()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +157,7 @@ export class DataTokens {
|
|||||||
* Transfer from Address to Account (needs an Approve operation before)
|
* Transfer from Address to Account (needs an Approve operation before)
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {String} fromAddress
|
* @param {String} fromAddress
|
||||||
* @param {Number} amount
|
* @param {Number} amount Number of datatokens, as number. Will be converted to wei
|
||||||
* @param {Account} account
|
* @param {Account} account
|
||||||
* @return {Promise<string>} transactionId
|
* @return {Promise<string>} transactionId
|
||||||
*/
|
*/
|
||||||
@ -167,7 +173,7 @@ export class DataTokens {
|
|||||||
{ from: account }
|
{ from: account }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods
|
const trxReceipt = await datatoken.methods
|
||||||
.transferFrom(fromAddress, account, amount)
|
.transferFrom(fromAddress, account, this.web3.utils.toWei(String(amount)))
|
||||||
.send()
|
.send()
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
@ -176,7 +182,7 @@ export class DataTokens {
|
|||||||
* Get Account Balance for datatoken
|
* Get Account Balance for datatoken
|
||||||
* @param {String} dataTokenAddress
|
* @param {String} dataTokenAddress
|
||||||
* @param {Account} account
|
* @param {Account} account
|
||||||
* @return {Promise<number>} balance
|
* @return {Promise<number>} balance Number of datatokens, as number. Will be converted from wei
|
||||||
*/
|
*/
|
||||||
public async balance(dataTokenAddress: string, account: Account): Promise<number> {
|
public async balance(dataTokenAddress: string, account: Account): Promise<number> {
|
||||||
const datatoken = new this.web3.eth.Contract(
|
const datatoken = new this.web3.eth.Contract(
|
||||||
@ -185,7 +191,7 @@ export class DataTokens {
|
|||||||
{ from: account }
|
{ from: account }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods.balanceOf(account).call()
|
const trxReceipt = await datatoken.methods.balanceOf(account).call()
|
||||||
return trxReceipt
|
return this.web3.utils.fromWei(trxReceipt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,7 +210,7 @@ export class DataTokens {
|
|||||||
{ from: spender }
|
{ from: spender }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods.allowance(owner, spender).call()
|
const trxReceipt = await datatoken.methods.allowance(owner, spender).call()
|
||||||
return trxReceipt
|
return this.web3.utils.fromWei(trxReceipt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get Blob
|
/** Get Blob
|
||||||
@ -264,6 +270,6 @@ export class DataTokens {
|
|||||||
{ from: account.getId() }
|
{ from: account.getId() }
|
||||||
)
|
)
|
||||||
const trxReceipt = await datatoken.methods.cap().call()
|
const trxReceipt = await datatoken.methods.cap().call()
|
||||||
return trxReceipt
|
return this.web3.utils.fromWei(trxReceipt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user