This page describes how to integrate Gosuto Mobile wallet into a dApp on Casper that all users with Gosuto Mobile wallet can interact with the dApp through Gosuto's built-in dApp browser
Check whether Gosuto wallet provider is enabled or loaded
if (window.gosuto &&window.gosuto.isGosuto) {// gosuto provider is enabled} else {// gosuto provider not loaded yet}
Request to connect to Gosuto Wallet user account
if (window.gosuto &&window.gosuto.isGosuto) {window.gosuto.requestConnection();}
Disconnect from the wallet
window.gosuto.disconnectFromSite();
Get connected account information
constisConnected=awaitwindow.gosuto.isConnected()if (isConnected){constaccountHex=awaitwindow.gosuto.getActivePublicKey();// do something with user account hex}
Listen to wallet connection
window.addEventListener("signer:connected", (eventInfo) => {const { activeKey,isConnected,isUnlocked } =eventInfo.detail// do something with information },false);
Sign and send a deploy
constto=""// recipient addressconstamount=""// amount in motes to send// For native-transfers the payment price is fixed.constpaymentAmount=10000000000;// transfer_id field in the request to tag the transaction and to correlate it to your back-end storage.constid=1;// gasPrice for native transfers can be set to 1.constgasPrice=1;// Time that the deploy will remain valid for, in milliseconds// The default value is 1800000 ms (30 minutes).constttl=1800000;constpublicKeyHex=awaitwindow.gosuto.getActivePublicKey();constpublicKey=CLPublicKey.fromHex(publicKeyHex)let deployParams =newDeployUtil.DeployParams(publicKey,"casper-test", gasPrice, ttl);// We create a public key from account-address (it is the hex representation of the public-key with an added prefix).consttoPublicKey=CLPublicKey.fromHex(to);constsession=DeployUtil.ExecutableDeployItem.newTransfer( amount,toPublicKey,null,id);constpayment=DeployUtil.standardPayment(paymentAmount);constdeploy=DeployUtil.makeDeploy(deployParams, session, payment);// Turn your transaction data to format JSONconstjson=DeployUtil.deployToJson(deploy)// Sign transcation using casper-signer.constsignature=awaitwindow.gosuto.sign(json,publicKeyHex,to)constdeployObject=DeployUtil.deployFromJson(signature)// Here we are sending the signed deploy.constsigned=awaitcasperClient.putDeploy(deployObject.val);