NEWTON
Asked
5 months ago
5
views
0
What do I have as the result of a Cairo contract in JavaScript?
Newton
asked
5 months 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
5 months 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?
ApeWorX: How can I test on multi-chain with both Starknet and Ethereum?
How can I define two functions with the same name but not the same arguments?
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?
How can I read contract memory with starknetjs?
How do I interact with my Pathfinder node?
Nethermind's warp error: JavaScript heap out of memory
Why am I having trouble deploying my Cairo contract?