Contracts.getFromLocal() vs. contract.fromArtifact()

What are the differences between Contracts.getFromLocal("ContractA") from @openzeppelin/upgrades and contract.fromArtifact("ContractA") from @openzeppelin/test-environment?

In which scenarios should each be used? Is there a hard and fast rule for using one vs the other in a test suite or with upgradable contracts?

1 Like

Hi @dtp5,

Welcome to the community :wave:

fromArtifact used in OpenZeppelin Test Environment is from Contract Loader whilst the Upgrades library uses its own getFromLocal.

Iā€™m not sure what the differences are. For testing you can use fromArtifact unless you are testing an upgradeable contract (rather than just the logic contract).

Thanks @abcoathup. It seems like getFromLocal and createProxy both create Web3 contract objects, even with contracts.type set to "truffle" in test-environment.config.js. Any way to get a Truffle contract object from these?

1 Like

Hi @dtp5,

Upgrades getFromLocal adds a few extra methods for linking, but otherwise getFromLocal and fromArtifact do pretty much the same. .

There is no way to get a truffle contract directly from either, but you can construct a Truffle contract from a web3 contract, using the ABI and address from the web3 contract. See @truffle/contract usage for details.