Skip to main content

Contracts

Methods for deploying and interacting with contracts

BlockNumber

BlockNumber() → Promise.<number>

Retrieve the latest block number on the blockchain

Returns: The latest block number

CallContractMethod

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

NameTypeRequiredDescription
contractAddressstring

Address of the contract to call the specified method on

abiObject

ABI of contract - If the contract is a standard Eluvio contract, this can be determined automatically if not specified

methodNamestring

Method to call on the contract

methodArgsArray

List of arguments to the contract constructor

valuenumber | BigNumber

Amount of ether to include in the transaction

formatArgumentsboolean

If specified, the arguments will automatically be formatted to the ABI specification

(default: true)
overridesObject

Change default gasPrice or gasLimit used for this action

CallContractMethodAndWait

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

NameTypeRequiredDescription
contractAddressstring

Address of the contract to call the specified method on

abiObject

ABI of contract - If the contract is a standard Eluvio contract, this can be determined automatically if not specified

methodNamestring

Method to call on the contract

methodArgsArray.<string>

List of arguments to the contract constructor

(default: [)
valuenumber | BigNumber

Amount of ether to include in the transaction

overridesObject

Change default gasPrice or gasLimit used for this action

formatArgumentsboolean

If specified, the arguments will automatically be formatted to the ABI specification

(default: true)

ContentAdminGroup

ContentAdminGroup({ tenantContractId }) // optional → Promise.<(*|undefined)>

Returns the content_admin group address for a given tenant contract.

Parameters

NameTypeRequiredDescription
tenantContractIdstring

The ID of the tenant contract

ContractAbi

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

NameTypeRequiredDescription
contractAddressstring

The address of the contract

idstring

The Fabric ID of the contract

ContractEvents

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

NameTypeRequiredDescription
contractAddressstring

The address of the contract

abiObject

ABI of contract - If the contract is a standard Eluvio contract, this can be determined automatically if not specified

fromBlocknumber

Limit results to events after the specified block (inclusive)

toBlocknumber

Limit results to events before the specified block (inclusive)

countnumber

Maximum range of blocks to search (unless both toBlock and fromBlock are specified)

(default: 1000)
includeTransactionboolean

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

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

NameTypeRequiredDescription
idstring

The Fabric ID of the contract

addressstring

The address of the contract

ContractMetadata

ContractMetadata({
  contractAddress,
  metadataKey
}) → Promise.<(Object|string)>

Retrieve metadata from the specified contract

Parameters

NameTypeRequiredDescription
contractAddressstring

The address of the contract

metadataKeystring

The metadata key to retrieve

ContractName

ContractName({ contractAddress }) → Promise.<string>

Return the name of the contract, as specified in the contracts "version" string

Returns: Name of the contract

Parameters

NameTypeRequiredDescription
contractAddressstring

Address of the contract

CustomContractAddress

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

NameTypeRequiredDescription
libraryIdstring

ID of the library

objectIdstring

ID of the object

versionHashstring

Version hash of the object

DeployContract

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

NameTypeRequiredDescription
abiObject

ABI of contract

bytecodestring

Bytecode of the contract

constructorArgsArray.<string>

List of arguments to the contract constructor

overridesObject

Change default gasPrice or gasLimit used for this action

Events

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

NameTypeRequiredDescription
toBlocknumber

Limit results to events before the specified block (inclusive) - If not specified, will start from latest block

fromBlocknumber

Limit results to events after the specified block (inclusive)

countnumber

Max number of events to include (unless both toBlock and fromBlock are specified)

(default: 10)
includeTransactionboolean

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

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

NameTypeRequiredDescription
contractAddressstring

Address of the contract to call the specified method on

eventObject

Event of the transaction from CallContractMethodAndWait

eventNamestring

Name of the event to parse

ExtractValueFromEvent

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

NameTypeRequiredDescription
contractAddressstring

Address of the contract to call the specified method on

abiObject

ABI of contract

eventObject

Event of the transaction from CallContractMethodAndWait

eventNamestring

Name of the event to parse

eventValuestring

Name of the value to extract from the event

FormatContractArguments

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

NameTypeRequiredDescription
abiObject

ABI of contract

methodNamestring

Name of method for which arguments will be formatted

argsArray.<string>

List of arguments

GetBalance

GetBalance({ address }) → Promise.<string>

Get the balance (in ether) of the specified address

Returns: Balance of the account, in ether (as string)

Parameters

NameTypeRequiredDescription
addressstring

Address to query

MergeContractMetadata

MergeContractMetadata({
  contractAddress,
  metadataKey,
  metadata
})

Merge contract metadata at the specified key.

Parameters

NameTypeRequiredDescription
contractAddressstring

The address of the contract

metadataKeystring

The metadata key to retrieve

metadatastring

ObjectCleanup

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

NameTypeRequiredDescription
contractAddressstring

The address of the object

objectIdstring

The ID of the object

versionHashstring

A version hash of the object

objectTypeToCleanstring

The type of object to clean: one of "library", "content_object", "group", "content_type", or "all"

ReplaceContractMetadata

ReplaceContractMetadata({
  contractAddress,
  metadataKey,
  metadata
})

Replace the contract metadata at the specified key

Parameters

NameTypeRequiredDescription
contractAddressstring

The address of the contract

metadataKeystring

The metadata key to retrieve

metadatastring | Object

The metadata to insert

ResetTenantId

ResetTenantId({
  contractAddress, // optional
  objectId, // optional
  versionHash // optional
}) → Promise.<void>

Remove the tenant contract ID and tenant admin group ID for the specified object

Parameters

NameTypeRequiredDescription
contractAddressstring

The address of the object

objectIdstring

The ID of the object

versionHashstring

A version hash of the object

SendFunds

SendFunds({
  recipient,
  ether
}) → Promise.<Object>

Send ether from this client's current signer to the specified recipient address

Returns: The transaction receipt

Parameters

NameTypeRequiredDescription
recipientstring

Address of the recipient

ethernumber

Amount of ether to send

SetCustomContentContract

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

NameTypeRequiredDescription
libraryIdstring

ID of the library

objectIdstring

ID of the object

customContractAddressstring

Address of the deployed custom contract

namestring

Optional name of the custom contract

descriptionstring

Optional description of the custom contract

abiObject

ABI of the custom contract

factoryAbiObject

If the custom contract is a factory, the ABI of the contract it deploys

overridesObject

Change default gasPrice or gasLimit used for this action

SetTenantContractId

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

NameTypeRequiredDescription
contractAddressstring

The address of the object

objectIdstring

The ID of the object

versionHashstring

A version hash of the object

tenantContractIdstring

The tenant contract ID to set

SetTenantId

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

NameTypeRequiredDescription
contractAddressstring

The address of the object

objectIdstring

The ID of the object

versionHashstring

A version hash of the object

tenantContractIdstring

The tenant contract ID to set

tenantIdstring

The tenant ID to set

TenantAdminGroup

TenantAdminGroup({ tenantContractId }) // optional → Promise.<(*|undefined)>

Returns the tenant_admin group address for a given tenant contract.

Parameters

NameTypeRequiredDescription
tenantContractIdstring

The ID of the tenant contract

TenantContractId

TenantContractId({
  contractAddress, // optional
  objectId, // optional
  versionHash // optional
}) → Promise.<(string|undefined)>

Retrieve the ID of the tenant contract for the specified object

Parameters

NameTypeRequiredDescription
contractAddressstring

The address of the object

objectIdstring

The ID of the object

versionHashstring

A version hash of the object

TenantId

TenantId({
  contractAddress, // optional
  objectId, // optional
  versionHash // optional
}) → Promise.<(string|undefined)>

Retrieve the ID of the tenant admin group set for the specified object

Parameters

NameTypeRequiredDescription
contractAddressstring

The address of the object

objectIdstring

The ID of the object

versionHashstring

A version hash of the object

TenantUsersGroup

TenantUsersGroup({ tenantContractId }) // optional → Promise.<(*|undefined)>

Returns the tenant_users group address for a given tenant contract.

Parameters

NameTypeRequiredDescription
tenantContractIdstring

The ID of the tenant contract