6

Let's say I have a contract in solidity:

pragma solidity 0.8.8;

contract MyContract{
    function getFive() public pure returns (uint256){
        return 5;
    }
} 

Could I import, inhert, etc in vyper? Or do something with it's ABI to import into vyper?

Ie in vyper:

from MyContract import getFive 

Additional:

  • Would the best thing to do be to rewrite contracts into vyper interfaces if I just wanted to interact with a contract?
  • Is there some way to grab the solidity bytecode of a function and drop it into vyper? (Or even the vyper bytecode...)
2
  • "Would the best thing to do be to rewrite contracts into vyper interfaces if I just wanted to interact with a contract?" yes, this is the preferred method Jun 8, 2022 at 2:56
  • 1
    "Is there some way to grab the solidity bytecode of a function and drop it into vyper? (Or even the vyper bytecode...)" no, as the vyper compiler cannot provide safety guarantees this way. Jun 8, 2022 at 2:56

1 Answer 1

4

vyper supports importing interfaces from JSON ABI files. You can convert a vyper contract to a JSON ABI interface file with vyper -f abi foo.vy, and you can convert a solidity contract to a JSON ABI interface file with solc --abi foo.sol. In the latest version of vyper, v0.3.3, you would import foo.json using the following syntax:

import foo as Foo

my_foo: Foo  # an external contract which has the interface defined by foo.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.