NEWTON
Asked
3 months ago
59
views
0
This question has a bounty of $0.00 in testnet ETH. Answers to this question are eligible to win that bounty.
These are testnet contracts. Not real ETH.
$0.00
Hello! I was wondering whether it was possible to check if a certain address has code in Cairo. In Solidity, we do something like:
assembly {
codeSize := extcodesize(contractAddress)
}
or just:
uint256 codeSize = contractAddress.code;
I was wondering if there was a way to check something like this in cairo? I checked the syscalls file but didn't find anything promising there.
Thank you in advance!
0x57B0...F5A4FD
asked
3 months ago
-2
Accepted answer
In order to obtain the address of the account contract (or any other contract, in the case that the function was invoked by a contract) that invoked our function, we can use the get_caller_address() library function:
from starkware.starknet.common.syscalls import get_caller_address
// ...
let (caller_address) = get_caller_address(); get_caller_address() returns the address of the source contract that called this contract. It can be the address of the account contract or the address of another contract (if the function was invoked by another contract). When the contract is called directly (rather than through a contract), the function returns 0.
Note that if you use get_caller_address() in a function foo() that was called by another function bar() within your contract, it will still return the address of the contract that invoked bar() (or 0 if it was invoked directly).
0xeF57...46cee1
answered
2 months ago
How to check for smaller Uints in Cairo?
Equivalent to Solidity's keccak256(abi.encodePacked())?
Cairo: How do I find the current contract's address?
What if my solidity contract contains Assembly or special EVM calls ?
Did you change the factory/create2 part (to compute pool addresses)? What's easier, adapt the create2 trick in Solidity then transpile or transpile first then adapt in Cairo?
How do you check if a number is even in Cairo?
Cairo: Using less than or greater than in conditional
Does anyone know of newsletters that focus on StarkNet or the zk ecosystem in general?
How to use Access Control in Cairo language securely?
What the etherscan equivalent for starknet is ?
Cairo Automatic Events
How to create Structs in Cairo Lang for StarkNet?
Cairo: How to return true from a function?
StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT error in Cairo. Can anyone help?