12 KiB
@oceanprotocol/lib / Exports / Dispenser
Class: Dispenser
Hierarchy
-
↳
Dispenser
Table of contents
Constructors
Properties
Methods
- activate
- amountToUnits
- create
- deactivate
- dispense
- getContract
- getDefaultAbi
- getFairGasPrice
- isDispensable
- ownerWithdraw
- setAllowedSwapper
- status
- unitsToAmount
Constructors
constructor
• new Dispenser(address
, signer
, network?
, config?
, abi?
)
Instantiate the smart contract.
Parameters
Name | Type | Description |
---|---|---|
address |
string |
The address of the contract. |
signer |
Signer |
The signer object. |
network? |
string | number |
Network id or name |
config? |
Config |
The configuration object. |
abi? |
AbiItem [] |
ABI array of the smart contract |
Inherited from
SmartContractWithAddress.constructor
Defined in
contracts/SmartContractWithAddress.ts:17
Properties
abi
• abi: AbiItem
[]
Inherited from
Defined in
address
• address: string
Inherited from
SmartContractWithAddress.address
Defined in
contracts/SmartContractWithAddress.ts:6
config
• config: Config
Inherited from
SmartContractWithAddress.config
Defined in
contract
• contract: Contract
Inherited from
SmartContractWithAddress.contract
Defined in
contracts/SmartContractWithAddress.ts:7
signer
• signer: Signer
Inherited from
SmartContractWithAddress.signer
Defined in
Methods
activate
▸ activate<G
>(dtAddress
, maxTokens
, maxBalance
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Activates a dispener.
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
dtAddress |
string |
refers to datatoken address. |
maxTokens |
string |
max amount of tokens to dispense |
maxBalance |
string |
max balance of user. If user balance is >, then dispense will be rejected |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
TransactionReceipt
Defined in
amountToUnits
▸ Protected
amountToUnits(token
, amount
, tokenDecimals?
): Promise
<string
>
Converts an amount of tokens to units
Parameters
Name | Type | Description |
---|---|---|
token |
string |
The token to convert |
amount |
string |
The amount of tokens to convert |
tokenDecimals? |
number |
The number of decimals of the token |
Returns
Promise
<string
>
- The converted amount in units
Inherited from
SmartContractWithAddress.amountToUnits
Defined in
create
▸ create<G
>(dtAddress
, address
, maxTokens
, maxBalance
, allowedSwapper
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Creates a new Dispenser
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
dtAddress |
string |
Datatoken address |
address |
string |
Owner address |
maxTokens |
string |
max tokens to dispense |
maxBalance |
string |
max balance of requester |
allowedSwapper |
string |
only account that can ask tokens. set address(0) if not required |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
transactionId
Defined in
deactivate
▸ deactivate<G
>(dtAddress
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Deactivate an existing dispenser.
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
dtAddress |
string |
refers to datatoken address. |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
TransactionReceipt
Defined in
dispense
▸ dispense<G
>(dtAddress
, amount?
, destination
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Dispense datatokens to caller. The dispenser must be active, hold enough datatokens (or be able to mint more) and respect maxTokens/maxBalance requirements
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
dtAddress |
string |
undefined |
Datatoken address. |
amount |
string |
'1' |
Amount of datatokens required. |
destination |
string |
undefined |
address of tokens receiver |
estimateGas? |
G |
undefined |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Defined in
getContract
▸ Protected
getContract(address
, abi?
): Contract
Returns a contract instance for the given address
Parameters
Name | Type | Description |
---|---|---|
address |
string |
The address of the contract |
abi? |
AbiItem [] |
The ABI of the contract |
Returns
Contract
- The contract instance
Inherited from
SmartContractWithAddress.getContract
Defined in
getDefaultAbi
▸ getDefaultAbi(): AbiItem
[]
Returns
AbiItem
[]
Overrides
SmartContractWithAddress.getDefaultAbi
Defined in
getFairGasPrice
▸ Protected
getFairGasPrice(): Promise
<string
>
Retruns the gas price
Returns
Promise
<string
>
- The fair gas price
Inherited from
SmartContractWithAddress.getFairGasPrice
Defined in
isDispensable
▸ isDispensable(dtAddress
, datatoken
, address
, amount?
): Promise
<Boolean
>
Check if tokens can be dispensed
Parameters
Name | Type | Default value | Description |
---|---|---|---|
dtAddress |
string |
undefined |
Datatoken address |
datatoken |
Datatoken |
undefined |
- |
address |
string |
undefined |
User address that will receive datatokens |
amount |
string |
'1' |
amount of datatokens required. |
Returns
Promise
<Boolean
>
Defined in
ownerWithdraw
▸ ownerWithdraw<G
>(dtAddress
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Withdraw all tokens from the dispenser
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
dtAddress |
string |
Datatoken address. |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Defined in
setAllowedSwapper
▸ setAllowedSwapper<G
>(dtAddress
, newAllowedSwapper
, estimateGas?
): Promise
<ReceiptOrEstimate
<G
>>
Sets a new allowed swapper.
Type parameters
Name | Type |
---|---|
G |
extends boolean = false |
Parameters
Name | Type | Description |
---|---|---|
dtAddress |
string |
Datatoken address. |
newAllowedSwapper |
string |
The address of the new allowed swapper. |
estimateGas? |
G |
if True, return gas estimate |
Returns
Promise
<ReceiptOrEstimate
<G
>>
Defined in
status
▸ status(dtAdress
): Promise
<DispenserToken
>
Get information about a datatoken dispenser
Parameters
Name | Type |
---|---|
dtAdress |
string |
Returns
Promise
<DispenserToken
>
Defined in
unitsToAmount
▸ Protected
unitsToAmount(token
, amount
, tokenDecimals?
): Promise
<string
>
Converts an amount of units to tokens
Parameters
Name | Type | Description |
---|---|---|
token |
string |
The token to convert |
amount |
string |
The amount of units to convert |
tokenDecimals? |
number |
The number of decimals in the token |
Returns
Promise
<string
>
- The converted amount in tokens
Inherited from
SmartContractWithAddress.unitsToAmount