Hello,
I am trying to use Casper JS SDK with Chrome Casper Signer plugin to access a test node from my web server. I have nodejs set up and running and connecting nicely with the Casper Signer Chrome plugin (I had to request to be added to the plugin whitelist). When I try to retrieve the latest block info, using the Casper JS SDK, I get a timeout. I am trying to follow the instructions outlined here:
My code looks like this. I have put a comment above the line that is causing the timeout:
import * as casper from "https://cdn.jsdelivr.net/npm/casper-js-sdk@2.10.0";
//Create Casper client and service to interact with Casper node.
const apiUrl = 'http://178.170.62.143:7777/rpc';
const casperService = new CasperServiceByJsonRPC(apiUrl);
const casperClient = new CasperClient(apiUrl);
const btnConnect = document.getElementById("btnConnect");
btnConnect.addEventListener("click", async () => {
window.casperlabsHelper.requestConnection();
await AccountInformation();
})
const btnDisconnect = document.getElementById("btnDisconnect");
btnDisconnect.addEventListener("click", () => {
window.casperlabsHelper.disconnectFromSite();
})
async function AccountInformation(){
const isConnected = await window.casperlabsHelper.isConnected()
if(isConnected){
const publicKey = await window.casperlabsHelper.getActivePublicKey();
textAddress.textContent += publicKey;
// ****** THIS CALL FAILS WITH A TIMEOUT *****************
const latestBlock = await casperService.getLatestBlockInfo();
const root = await casperService.getStateRootHash(latestBlock.block.hash);
const balanceUref = await casperService.getAccountBalanceUrefByPublicKey(
root,
CLPublicKey.fromHex(publicKey)
)
//account balance from the last block
const balance = await casperService.getAccountBalance(
latestBlock.block.header.state_root_hash,
balanceUref
);
textBalance.textContent = `PublicKeyHex ${balance.toString()}`;
}
}
Many thanks for your help!
Adrian