How do you refer to a contract own address inside it?

  • I am attempting to use 2 contracts together, and I need my 2nd contract to pass his own address to the first contract.

    Is there an easy way to do this? Like this.address?

    Or should I update my contract own address into a variable?

    @ClaudinelameldoiseClaudinelam please clarify what you need?

  • niksmac

    niksmac Correct answer

    5 years ago

    Get contract address in Solidity

    Short answer: The global variable this is the contract address.

    Long answer: this is a variable representing the current contract. Its type is the type of the contract. Since any contract type basically inherits from the address type, this is always convertible to address and in this case contains its own address.

    Update

    As of Solidity v5, this become deprecated. Now, you have to use address(this).

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM