I'm trying to execute my first contract on Ethereum. I've been able to compile and deploy one of Vyper's test examples of an auction. I believe the contract is executed when a transaction is sent to it. The thing I'm not yet understanding is when the constructor and the methods are called. As I understand it the bytecode is sent to the nodes for computation, but I'm missing how/when/where the constructor and the methods themselves are called. For instance, below I have a method called 'bid', but how does the transaction know how to call 'bid'? I think I'm not quite understanding the entire process from transaction submission down to contract execution. Thanks for your help!

beneficiary: public(address)
auctionStart: public(timestamp)
auctionEnd: public(timestamp)
highestBidder: public(address)
highestBid: public(uint256)
ended: public(bool)
pendingReturns: public(map(address, uint256))

def __init__(_beneficiary: address, _bidding_time: uint256):
    self.beneficiary = _beneficiary
    self.auctionStart = block.timestamp
    self.auctionEnd = self.auctionStart + _bidding_time

def bid():
    assert block.timestamp < self.auctionEnd
    assert msg.value > self.highestBid
    self.pendingReturns[self.highestBidder] += self.highestBid
    self.highestBidder = msg.sender
    self.highestBid = as_unitless_number(msg.value)

Each function has a signature. Inside of a transaction, there is a data field.

This data field contains what function signature you would like to call along with what arguments - Vyper compiles to EVM bytecode. This bytecode contains the function signatures.

  • Thank you Dylan. I was just starting out when I was working with this example. I didn't realize that the code was transactional in that I had to actually put the function on the ledger and then launch a transaction to get it to execute. I was having difficulty thinking in a distributed sense, but your note about the EVM bytecode is helpful as it gets distributed to many participants on the ledger and eventually executed sand verified. – jkovba Oct 22 '20 at 22:06
  • Ok, im just reading through all of the old vyper questions on here :) - i didnt realise how few people where using the language until i saw how few questions there were :0. – Dylan Kerler Oct 22 '20 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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