Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support chaining of live-contract types #28

Open
3Nigma opened this issue Mar 3, 2022 · 0 comments
Open

Support chaining of live-contract types #28

3Nigma opened this issue Mar 3, 2022 · 0 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@3Nigma
Copy link
Contributor

3Nigma commented Mar 3, 2022

Given the following solidity file:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

contract Square {
  uint public size;

  constructor(uint _size) payable {
    size = _size;
  }
}

contract SquareCreator {
  function create(uint _size) public returns (Square Square_) {
    return new Square(_size);
  }
}

it would be nice if we would support doing this:

const liveSquare = await squareCreatorLiveContract.create(10);

console.log(await liveSquare.size());

This will allow chaining contract type calls which will further stream-line the development experience.

To make this working, we need a way to understand that a method return type is an actual contract. @ethersproject/abi's Interface does not provide too much help in this regards:
image
even though the solidity compiler does appear to export more info regarding the raw internalType of the output:
image

One way to avoid this is to try and have a naming convention in place similar to the one present in the above example where we could say that 'if a returned variable name ends with an underscore, then try to map its address to a live-contract and return that'. If we go on this path, we need to settle on this convention. For flexibility reasons, It would be nice if we could avoid enforcing this convention and take advantage of solidity's internalType.

Another issue that needs to be addressed for this feature to be implemented is the parser's access to the ABIs for which the resulting live-contracts are built. Basically, in our previous example case, this is the equivalent to answering the question of how to make available the Square ABI to the create result mapper. What happens if the returned contract type is not part of the same solidity file (eg. import path)?

This feature should be flagged by a context config-parameter.

@3Nigma 3Nigma added enhancement New feature or request question Further information is requested labels Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant