使用接口调用其他智能合约。
下面是我们将调用的TestInterfaceself.act。
# @version ^0.3.7
owner: public(address)
eth: public(uint256)
@external
def setOwner(owner: address):
self.owner = owner
@external
@payable
def sendEth():
self.eth = msg.value
@external
@payable
def setOwnerAndSendEth(owner: address):
self.owner = owner
self.eth = msg.value
# @version ^0.3.7
interface TestInterface:
# get address of owner
def owner() -> address: view
# set new owner
def setOwner(owner: address): nonpayable
# send ETH
def sendEth(): payable
# set owner and send ETH
def setOwnerAndSendEth(owner: address): payable
# store contract having the above interface
test: public(TestInterface)
@external
def __init__(test: address):
# store contract instance
self.test = TestInterface(test)
# if you need to get address from self.test
addr: address = self.test.address
@external
@view
def getOwner() -> address:
return self.test.owner()
@external
@view
def getOwnerFromAddress(test: address) -> address:
# you can also call functions by passing in the address of the interface
return TestInterface(test).owner()
@external
def setOwner(owner: address):
self.test.setOwner(owner)
@external
@payable
def sendEth():
self.test.sendEth(value=msg.value)
@external
@payable
def setOwnerAndSendEth(owner: address):
self.test.setOwnerAndSendEth(owner, value=msg.value)
Yanbo的Twitter|Web3Club的Twitter
加入Web3Club 官方讨论群:YanboTravelAllWorld(微信号)