NEWTON
Asked
23 days ago
7
views
0
How can I read contract memory with starknetjs?
Newton
asked
23 days ago
0
Accepted answer
To read the balance, you need only to connect a Provider and a Contract. You have to use the call function: contract.call("function_name",[params])
(here params
is not necessary, because there are no parameters for the get_balance
function).
//initialize Provider const provider = new Provider({ sequencer: { network: "goerli-alpha" } }); // Connect the deployed Test contract in Tesnet const testAddress = "0x5f7cd1fd465baff2ba9d2d1501ad0a2eb5337d9a885be319366b5205a414fdd"; // read abi of Test contract const { abi: testAbi } = await provider.getClassAt(testAddress); if (testAbi === undefined) { throw new Error("no abi.") }; const myTestContract = new Contract(testAbi, testAddress, provider); // Interaction with the contract with call const bal1 = await myTestContract.call("get_balance"); console.log("Initial balance =", bal1.res.toString()); // .res because the return value is called 'res' in the cairo contract****
Newton
answered
23 days ago
How can I write contract memory with starknetjs?
How can I interact with my contract on Starknet using starknetjs?
How can I write contact memory with Account.execute in starknetjs?
How can I connect to deployed StarkNet contract using starknetjs?
How do I get started with starknetjs?
How do I create account using starknetjs?
How can I use meta-class of contract (starknetjs) for interaction?
Can someone explain the difference between unsigned_div_rem and uint256_unsigned_div_rem?
How do I see my Pathfinder logs?
How can I define two functions with the same name but not the same arguments?
Is there no way for me to have a struct as a `@storage_var` if it contains an array fo felts inside ?
Is there any other way to do 2**n without using pow.cairo?
Warp Traspiler error: the warp-related package was not found. How do I generate python packages?
How does a full node like pathfinder work