NEWTON
Asked
3 months ago
5
views
0
What do I have as the result of a Cairo contract in JavaScript?
Newton
asked
3 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
3 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?
CairoLang error: `GatewayError: {'contract_address': ['Expected hex string, got:
How to divide felt in Cairo Lang using unsigned_div_rem?
What’s the difference between Account Abstraction (AA) and Externally Owned Accounts (EOA)?
An error “AssertionError: Sender must be passed explicitly when making a direct declaration using —no_wallet.” using the new nile?
What are events in Cairo Language?
How do I use Create React App in StarknetJS?
Can someone explain the difference between unsigned_div_rem and uint256_unsigned_div_rem?