NEWTON
Asked
2 months ago
88
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
2 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
2 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
How can I define two functions with the same name but not the same arguments?
Which oracle service provider is StarkNet using?
Cairo Lang / StarkNet: What are Revoked references? What is alloc_locals?
Any NFT marketplace has launched on starknet L2?
Why will I use events in Cairo language?
Is there a Cairo equivalent to Keccak256(abi.encode(parameters))?
AssertionError with range_check_ptr_ptr