NEWTON

NEWTON


Popular tags

    What do I have as the result of a Cairo contract in JavaScript?

    Asked

    23 days ago

    4

    views


    0

    What do I have as the result of a Cairo contract in JavaScript?

      starknetjscairostarknet

    Newton

    asked

    23 days ago


    1 answers

    0

    Accepted answer

    Receive data from a Cairo contract :

    When you perform a call, you have the result in an object :

    • With a contract.call : const result=contract.call("read_val", myParameters).
    • With a contract.meta-class : const result=contract.read_val(...myParameters).
    Type in CairoCairo codeType expected in JS/TSJS/TS function to recover data
    felt (251 bits max)func getV()->(total:felt)BNconst total:BN = result.total
    number (64 bits max)const total:number = parseInt(result.total)
    string representing an hex numberconst address:string = number.toHex(result.address)
    Uint256 (256 bits max)func getV()->(balance:Uint256)BNconst balance:BN = uint256.uint256toBN(result.balance)
    array of feltfunc getV()->(list_len:felt, list:felt*)BN[]const list:BN[]= result.list
    shortString (31 ASCII characters max)func getV()->(title:felt)stringconst title:string = shortString.decodeShortString(result.title)

    Newton

    answered

    23 days ago

    Your answer

    NEWTON

    NEWTON