Replies: 10 comments 22 replies
-
snake case. This is the Cairo convention. camelCase will only lead to more camelCase, and mangling, IMO. |
Beta Was this translation helpful? Give feedback.
-
If you asked me a week ago I would have also said snake case (in fact, my smart contracts use snake case), but I changed my mind recently when thinking how to integrate StarkNet with a multi-chain frontend. For example, I have the following code (kinda): const { address, chainId } = useEthers()
const contractAddress = useTokenAddress(chainId)
const balance = useContractCall(
address && contractAddress && { method: 'balanceOf', args: [address] }) Now, if the contracts used the same capitalization I would have to deal with StarkNet only at the lowest level (when I make the web3 call), but with snake case I would need to add a case for StarkNet for every contract call. const { address, chainId } = useEthers()
const contractAddress = useTokenAddress(chainId)
const contractMethod = useTokenBalanceOfMethod(chainId)
const balance = useContractCall(
address && contractAddress && contractMethod && { method: contractMethod, args: [address] }) For a moment, please ignore we're months away from writing code like the one above :) In my contracts I'm thinking of renaming all external and view functions to camel case and leave internal/private functions as snake case (it also makes it obvious if you're calling a private or external function). I don't like it, but it saves frontend developers a lot of complexity IMHO. EDIT: I think what I propose is technically consistent with the Cairo standard library, since they don't include any external function. |
Beta Was this translation helpful? Give feedback.
-
What do we know about how Vyper deals with this issue? Apparently they follow camelCase, even if their tooling is on python, right? Does it make sense to push for changing Cairo itself to follow camelCase, following Vyper's example, for consistency with existing ERCs? |
Beta Was this translation helpful? Give feedback.
-
My intuition is that chains will differ along many different aspects. Think data structures, transaction filecycle, finality, etc. It will be a substantial effort to build a compatibility layer that will hide all those differences under a single abstraction if ever possible. |
Beta Was this translation helpful? Give feedback.
-
How Solana solves that problem? There should be a similar problem. Rust uses snake case for method names. |
Beta Was this translation helpful? Give feedback.
-
After having discussed and thought about this for a while now, this is how I see this: InterfacesGiven that we're discussing the implementation of a standard and standards are all about interoperability, I think the focus of the discussion should be on interfaces only (not coding style). We should consider several kinds of interoperability:
ERC20 compatibilityIf we want to implement ERC20 there's more than just function names blocking us. The ERC20 standard assumes a given ABI encoding (Ethereum's) which Cairo doesn't have and it would also requiere a similar But it's doable. For Conclusion
|
Beta Was this translation helpful? Give feedback.
-
I think that it is rather an interpretation than implementation. StarkNet is a significantly different execution environment with its own set of design choices that can't be hidden by just an interface. Input from StarkWare would be helpful. They have enormous power to establish practicies in this ecosystem. Just for information, here is our (Maker) interpretation of erc20 for DAI: https://github.com/makerdao/starknet-dai-bridge/blob/mk/draft/contracts/l2/dai.cairo |
Beta Was this translation helpful? Give feedback.
-
The point we want to make is that it is a worthwhile pursuit to offer an Ethereum-compatible interface to StarkNet, which coupled with an exact ERC20 interface could make integration into the existing ecosystem significantly easier. If this is technically impossible I would love to see the explanation and we can move on with a custom fungible token standard using snake case. But if it is technically possible, and there is a project to build a compatible JSON RPC interface, and there is a feasible path to abstracting away the different ABI encoding, then I don't think we should put more obstacles in the way of that pursuit by using different function names than ERC20. |
Beta Was this translation helpful? Give feedback.
-
Good argument for camelCase is: if StarkNet is ever going to have EVM compatibility, then I would like to be able to use contracts that interact with erc20 like tokens (let's say Uniswap v2 contracts) without any modifications. It means this hypotetical Uniswap contract on StarkNet should recognize native StarkNet tokens and its liquidity tokens as first class tokens on StarkNet. |
Beta Was this translation helpful? Give feedback.
-
I think as far as possible we should attempt to be compatible with existing standards and stick to camelCase for ERC-20. If we're going to go down the route of incompatibility, then I say we got all out and drop the 256-bit uint in favor of 251-bit (?) felts. |
Beta Was this translation helpful? Give feedback.
-
The problem:
camelCase
vssnake_case
According to EIP-20 token functions are written in camel case (
balanceOf
) whereas Cairo, coming from Python, suggests snake casing (balance_of
).for
camelCase
:for
snake_case
:Any thoughts?
(*) In solidity, selector encoding is the first four bytes of the keccak signature of the function, e.g.
keccak256("transfer(uint, uint)")
whereas in StarkNet selectors are much larger, 250-bit hashes of the function name, this is applying a 250-bit mask tokeccak256("transfer")
.Beta Was this translation helpful? Give feedback.
All reactions