NEWTON

NEWTON


Popular tags

    How can I send a Uint256 amount of ERC20 tokens from L1 to starknet? And how should I build my payload for "sendMessageToL2" to match the Uint256 format of Cairo?

    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)

      l1l2bridgecairostarknet

    Newton

    asked

    2 months ago


    1 answers

    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

    Answer is not submitted on chain

    Your answer

    NEWTON

    NEWTON