contracts module loads Rocket Pool contract ABIs and addresses from
RocketStorage, where all network contracts are registered.
Contract ABIs and addresses are loaded from the chain, the ABIs are decompressed and decoded, and then web3 contract instances are created from them.
This is performed dynamically because Rocket Pool contracts can be upgraded and their ABIs and addresses may change.
This module is used by other library modules internally, and generally does not need to be used directly. However, it is exposed publicly for when direct access to web3 contract instances is desired, or the library wrapper methods are insufficient.
Loading Contracts & ABIs¶
Network contracts can be loaded via the
contracts.get() method, which accepts either a single contract name as a string, or a list of contract names as an array of strings.
If a single contract name is passed, this method returns a promise resolving to a web3 contract instance.
If a list of contract names is passed, it returns a promise resolving to an array of web3 contract instances, in the same order.
Contract addresses and ABIs can be loaded in a similar fashion via the
contracts.abi() methods, which accept either a single contract name, or a list of names, to retrieve data for.
Creating Contract Instances¶
Some network contracts, such as
RocketMinipool, have multiple instances deployed at a number of different addresses.
To create an instance of one of these contracts, use the
contracts.make(name, address) method.
It accepts the name of the contract and the address of the specific instance required, both as strings, and returns a promise resolving to a web3 contract instance.
Alternate Contract Versions¶
When Rocket Pool network contracts are upgraded, old versions remain on the chain and can still be accessed if required.
A “contract version set”, consisting of all versions of a contract by name, can be loaded with the
This method accepts the name of the contract to load, and returns a promise resolving to the version set object.
Contract version sets are primarily used for accessing old event data. They provide the following methods:
versionSet.current(): Returns the current version of the contract
versionSet.first(): Returns the first version of the contract deployed
versionSet.at(index): Returns the version of the contract at the specified version index (0 = first version)
versionSet.getPastEvents(eventName, options): As per web3’s contract.getPastEvents, but returns a promise resolving to the events for all versions of the contract