NEWTON
Asked
4 months ago
90
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
How can I send a Uint256 amount of ERC20 tokens from L1 to starknet?
I have "amount" as a uint256 on L1 but how should I build my payload for "sendMessageToL2
" to match the Uint256 format of Cairo?
This question is participating in Newton Bounties | Incentivized Test Program Every verified valid question gets $10 USDC (mainnet)
Newton
asked
4 months ago
2
Accepted answer
You can try something like this (cf Starkgate code):
uint256 constant UINT256_PART_SIZE_BITS = 128;
uint256 constant UINT256_PART_SIZE = 2**UINT256_PART_SIZE_BITS;
And payload will be like this :
uint256[] memory payload = new uint256[](3);
payload[0] = l2Recipient;
payload[1] = amount & (UINT256_PART_SIZE - 1);
payload[2] = amount >> UINT256_PART_SIZE_BITS;
Then on L2 you will received amount as 2 felt, high and low. Then you juste have to use it with let (amount: Uint256) =Uint256(low=low, high=high)
And that's it.
0xC7a4...1094Da
answered
4 months ago
Cairo error "Expected expression of type 'starkware.cairo.common.uint256.Uint256' to have an address."
Cairo: How to reassign Uint256 in a conditional
How do you optimize gas in Cairo with Uint256/felt?
How to import uint256 in Cairo?
Cairo Error: 'range_check_ptr' cannot be used as an implicit return value. Consider using a 'with' statement.
Is uint256 math operators like uint256_le safe? Why do I need to use uint256_check?
Fixed Point pow operation error
What’s the difference between Account Abstraction (AA) and Externally Owned Accounts (EOA)?
Cairo: How do I find the current contract's address?
How to write a function in Cairo Lang (StarkNet)?
StarkNet Faucet: How can I get a Goerli-2 eth faucet tokens (StarkNet)?
Any NFT marketplace has launched on starknet L2?
What does this error means? (AssertionError: assert_not_zero failed: 0 = 0.)
What is the maximum value an uint and felt can store in Cairo Language?