NEWTON
Asked
23 days ago
4
views
0
What do I have as the result of a Cairo contract in JavaScript?
Newton
asked
23 days ago
0
Accepted answer
When you perform a call, you have the result in an object :
const result=contract.call("read_val", myParameters)
.const result=contract.read_val(...myParameters)
.Type in Cairo | Cairo code | Type expected in JS/TS | JS/TS function to recover data |
---|---|---|---|
felt (251 bits max) | func getV()->(total:felt) | BN | const total:BN = result.total |
number (64 bits max) | const total:number = parseInt(result.total) | ||
string representing an hex number | const address:string = number.toHex(result.address) | ||
Uint256 (256 bits max) | func getV()->(balance:Uint256) | BN | const balance:BN = uint256.uint256toBN(result.balance) |
array of felt | func getV()->(list_len:felt, list:felt*) | BN[] | const list:BN[]= result.list |
shortString (31 ASCII characters max) | func getV()->(title:felt) | string | const title:string = shortString.decodeShortString(result.title) |
Newton
answered
23 days ago
How do I transform data from javascript to Cairo?
Cairo: Javascript API for cairo compile
Is there a javascript version of StarkEx playground?
Getting the CLASS_HASH of a contract in Cairo
Nethermind's warp error: JavaScript heap out of memory
How to use Pedersen Hash in StarkNet / Cairo Language?
How to submit a StarkNet contract?
What is the difference between tempvar/let in Cairo Lang? How to use allow_locals and local?
Can anyone explain Pathfinder JSON-RPC InvokeTXNV1?
how to return struct
Is anyone experiencing slowness on goerli StarkNet?
How to make math operation with Field Elements (felts) in Cairo lang?
How to make Bitwise operations in Cairo Lang using %builtins bitwise, bitwise_xor?
Is there a threshold of optimum transaction speed/cost in L2s?