Contracts
Methods for deploying and interacting with contracts
BlockNumber
Retrieve the latest block number on the blockchain
Returns: The latest block number
CallContractMethod
contractAddress,
abi, // optional
methodName,
methodArgs, // optional
value, // optional
formatArguments, // optional
overrides // optional
}) → Promise.<*>
Call the specified method on a deployed contract. This action will be performed by this client's signer.
Use this method to call constant methods and contract attributes, as well as transaction-performing methods for which the transaction does not need to be awaited.
Returns: Response containing information about the transaction
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | ✓ | Address of the contract to call the specified method on |
abi | Object | ABI of contract - If the contract is a standard Eluvio contract, this can be determined automatically if not specified | |
methodName | string | ✓ | Method to call on the contract |
methodArgs | Array | List of arguments to the contract constructor | |
value | number | BigNumber | Amount of ether to include in the transaction | |
formatArguments | boolean | If specified, the arguments will automatically be formatted to the ABI specification (default:true) | |
overrides | Object | Change default gasPrice or gasLimit used for this action |
CallContractMethodAndWait
contractAddress,
abi, // optional
methodName,
methodArgs, // optional
value, // optional
overrides, // optional
formatArguments // optional
}) → Promise.<*>
Call the specified method on a deployed contract and wait for the transaction to be mined. This action will be performed by this client's signer.
Use this method to call transaction-performing methods and wait for the transaction to complete.
Returns: The event object of this transaction. See the ExtractEventFromLogs method for parsing the resulting event(s)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | ✓ | Address of the contract to call the specified method on |
abi | Object | ABI of contract - If the contract is a standard Eluvio contract, this can be determined automatically if not specified | |
methodName | string | ✓ | Method to call on the contract |
methodArgs | Array.<string> | List of arguments to the contract constructor (default:[) | |
value | number | BigNumber | Amount of ether to include in the transaction | |
overrides | Object | Change default gasPrice or gasLimit used for this action | |
formatArguments | boolean | If specified, the arguments will automatically be formatted to the ABI specification (default:true) |
ContentAdminGroup
Returns the content_admin group address for a given tenant contract.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tenantContractId | string | The ID of the tenant contract |
ContractAbi
contractAddress, // optional
id // optional
}) → Promise.<Object>
Retrieve the ABI for the given contract via its address or a Fabric ID. Contract must be a standard Eluvio contract
Returns: The ABI for the given contract
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | The address of the contract | |
id | string | The Fabric ID of the contract |
ContractEvents
contractAddress,
abi, // optional
fromBlock, // optional
toBlock, // optional
count, // optional
includeTransaction // optional
}) → Promise.<Array.<Array.<Object>>>
Get all events on the specified contract
Returns: List of blocks, in ascending order by block number, each containing a list of the events in the block.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | ✓ | The address of the contract |
abi | Object | ABI of contract - If the contract is a standard Eluvio contract, this can be determined automatically if not specified | |
fromBlock | number | Limit results to events after the specified block (inclusive) | |
toBlock | number | Limit results to events before the specified block (inclusive) | |
count | number | Maximum range of blocks to search (unless both toBlock and fromBlock are specified) (default:1000) | |
includeTransaction | boolean | If specified, more detailed transaction info will be included. Note: This requires one extra network call per block, so it should not be used for very large ranges (default:false) |
ContractInfo
id, // optional
address // optional
}) → Promise.<Object>
Retrieve the ABI, access type, and whether V3 is used for a given contract via its address or a Fabric ID.
Returns: The ABI, access type, and isV3 for the given contract
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
id | string | The Fabric ID of the contract | |
address | string | The address of the contract |
ContractMetadata
contractAddress,
metadataKey
}) → Promise.<(Object|string)>
Retrieve metadata from the specified contract
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | ✓ | The address of the contract |
metadataKey | string | ✓ | The metadata key to retrieve |
ContractName
Return the name of the contract, as specified in the contracts "version" string
Returns: Name of the contract
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | ✓ | Address of the contract |
CustomContractAddress
libraryId, // optional
objectId, // optional
versionHash // optional
}) → Promise.<string> | undefined
Get the custom contract of the specified object
Returns: If the object has a custom contract, this will return the address of the custom contract
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
libraryId | string | ID of the library | |
objectId | string | ID of the object | |
versionHash | string | Version hash of the object |
DeployContract
abi,
bytecode,
constructorArgs,
overrides // optional
}) → Promise.<Object>
Deploy a contract from ABI and bytecode. This client's signer will be the owner of the contract.
Returns: Response containing the deployed contract address and the transaction hash of the deployment
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
abi | Object | ✓ | ABI of contract |
bytecode | string | ✓ | Bytecode of the contract |
constructorArgs | Array.<string> | ✓ | List of arguments to the contract constructor |
overrides | Object | Change default gasPrice or gasLimit used for this action |
Events
toBlock, // optional
fromBlock, // optional
count, // optional
includeTransaction // optional
}) → Promise.<Array.<Array.<Object>>>
Get events from the blockchain in reverse chronological order, starting from toBlock. This will also attempt to identify and parse any known Eluvio contract methods. If successful, the method name, signature, and input values will be included in the log entry.
Returns: List of blocks, in ascending order by block number, each containing a list of the events in the block.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
toBlock | number | Limit results to events before the specified block (inclusive) - If not specified, will start from latest block | |
fromBlock | number | Limit results to events after the specified block (inclusive) | |
count | number | Max number of events to include (unless both toBlock and fromBlock are specified) (default:10) | |
includeTransaction | boolean | If specified, more detailed transaction info will be included. Note: This requires two extra network calls per transaction, so it should not be used for very large ranges (default:false) |
ExtractEventFromLogs
contractAddress,
event,
eventName
}) → Promise.<Object>
Extract the specified event log from the given event obtained from the CallContractAndMethodAndWait method
Returns: The parsed event log from the event
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | ✓ | Address of the contract to call the specified method on |
event | Object | ✓ | Event of the transaction from CallContractMethodAndWait |
eventName | string | ✓ | Name of the event to parse |
ExtractValueFromEvent
contractAddress,
abi,
event,
eventName,
eventValue
}) → Promise.<string>
Extract the specified value from the specified event log from the given event obtained from the CallContractAndMethodAndWait method
Returns: The value extracted from the event
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | ✓ | Address of the contract to call the specified method on |
abi | Object | ✓ | ABI of contract |
event | Object | ✓ | Event of the transaction from CallContractMethodAndWait |
eventName | string | ✓ | Name of the event to parse |
eventValue | string | ✓ | Name of the value to extract from the event |
FormatContractArguments
abi,
methodName,
args
}) → Array.<string>
Format the arguments to be used for the specified method of the contract
Returns: List of formatted arguments
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
abi | Object | ✓ | ABI of contract |
methodName | string | ✓ | Name of method for which arguments will be formatted |
args | Array.<string> | ✓ | List of arguments |
GetBalance
Get the balance (in ether) of the specified address
Returns: Balance of the account, in ether (as string)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
address | string | ✓ | Address to query |
MergeContractMetadata
contractAddress,
metadataKey,
metadata
})
Merge contract metadata at the specified key.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | ✓ | The address of the contract |
metadataKey | string | ✓ | The metadata key to retrieve |
metadata | string | ✓ |
ObjectCleanup
contractAddress, // optional
objectId, // optional
versionHash, // optional
objectTypeToClean // optional
}) → Promise.<Object>
Cleans up deleted objects pointed to by the access index of a given "access group" or "user wallet" Contracts of type "access group" and "user wallet" contain an "access index" - a list of objects that they have access to.
There are 4 specific indexes, one for each object type:
- content
- library
- access groups
- content types
If an object gets deleted and the access index still points to it, it will cause errors in API calls for the access group or user wallet.
This function checks each index for objects that are deleted, and removes them from the index (either all indexes or just the one specified by parameter 'objectTypeToClean')
For user, the cleanup is performed on the user wallet and on all its access group
Returns: Resolves with an object showing the count of items before and after cleanup. Example return value: { "0x123...": { beforeCleanup: { librariesLength: 2, contentObjectsLength: 4, accessGroupsLength: 1, contentTypesLength: 3 }, afterCleanup: { librariesLength: 0, contentObjectsLength: 0, accessGroupsLength: 0, contentTypesLength: 0 } }, "groups": { "0x123...": { beforeCleanup: { contentObjectsLength: 1 }, afterCleanup: { contentObjectsLength: 0 } } } }
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | The address of the object | |
objectId | string | The ID of the object | |
versionHash | string | A version hash of the object | |
objectTypeToClean | string | The type of object to clean: one of "library", "content_object", "group", "content_type", or "all" |
ReplaceContractMetadata
contractAddress,
metadataKey,
metadata
})
Replace the contract metadata at the specified key
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | ✓ | The address of the contract |
metadataKey | string | ✓ | The metadata key to retrieve |
metadata | string | Object | ✓ | The metadata to insert |
ResetTenantId
contractAddress, // optional
objectId, // optional
versionHash // optional
}) → Promise.<void>
Remove the tenant contract ID and tenant admin group ID for the specified object
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | The address of the object | |
objectId | string | The ID of the object | |
versionHash | string | A version hash of the object |
SendFunds
recipient,
ether
}) → Promise.<Object>
Send ether from this client's current signer to the specified recipient address
Returns: The transaction receipt
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
recipient | string | ✓ | Address of the recipient |
ether | number | ✓ | Amount of ether to send |
SetCustomContentContract
libraryId,
objectId,
customContractAddress,
name, // optional
description, // optional
abi,
factoryAbi, // optional
overrides // optional
}) → Promise.<Object>
Set the custom contract of the specified object with the contract at the specified address
Note: This also updates the content object metadata with information about the contract - particularly the ABI
Returns: Result transaction of calling the setCustomContract method on the content object contract
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
libraryId | string | ✓ | ID of the library |
objectId | string | ✓ | ID of the object |
customContractAddress | string | ✓ | Address of the deployed custom contract |
name | string | Optional name of the custom contract | |
description | string | Optional description of the custom contract | |
abi | Object | ✓ | ABI of the custom contract |
factoryAbi | Object | If the custom contract is a factory, the ABI of the contract it deploys | |
overrides | Object | Change default gasPrice or gasLimit used for this action |
SetTenantContractId
contractAddress, // optional
objectId, // optional
versionHash, // optional
tenantContractId
}) → Promise.<{tenantId: (undefined|string), tenantContractId}>
Set the tenant contract ID and tenant admin group ID for the specified object when tenant contract ID is provided
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | The address of the object | |
objectId | string | The ID of the object | |
versionHash | string | A version hash of the object | |
tenantContractId | string | ✓ | The tenant contract ID to set |
SetTenantId
contractAddress, // optional
objectId, // optional
versionHash, // optional
tenantContractId,
tenantId
}) → Promise.<{tenantId: (undefined|string), tenantContractId}>
Set the tenant contract ID and tenant admin group ID for the specified object when tenant admin group ID is provided
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | The address of the object | |
objectId | string | The ID of the object | |
versionHash | string | A version hash of the object | |
tenantContractId | string | ✓ | The tenant contract ID to set |
tenantId | string | ✓ | The tenant ID to set |
TenantAdminGroup
Returns the tenant_admin group address for a given tenant contract.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tenantContractId | string | The ID of the tenant contract |
TenantContractId
contractAddress, // optional
objectId, // optional
versionHash // optional
}) → Promise.<(string|undefined)>
Retrieve the ID of the tenant contract for the specified object
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | The address of the object | |
objectId | string | The ID of the object | |
versionHash | string | A version hash of the object |
TenantId
contractAddress, // optional
objectId, // optional
versionHash // optional
}) → Promise.<(string|undefined)>
Retrieve the ID of the tenant admin group set for the specified object
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
contractAddress | string | The address of the object | |
objectId | string | The ID of the object | |
versionHash | string | A version hash of the object |
TenantUsersGroup
Returns the tenant_users group address for a given tenant contract.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
tenantContractId | string | The ID of the tenant contract |