Integrate Gosuto Mobile into your app

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

const isConnected = await window.gosuto.isConnected()
if (isConnected){
    const accountHex = await window.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

const to = "" // recipient address
const amount = "" // amount in motes to send
// For native-transfers the payment price is fixed.
const paymentAmount = 10000000000;

// transfer_id field in the request to tag the transaction and to correlate it to your back-end storage.
const id = 1;

// gasPrice for native transfers can be set to 1.
const gasPrice = 1;

// Time that the deploy will remain valid for, in milliseconds
// The default value is 1800000 ms (30 minutes).
const ttl = 1800000;
const publicKeyHex = await window.gosuto.getActivePublicKey();
const publicKey = CLPublicKey.fromHex(publicKeyHex)

let deployParams = new DeployUtil.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).
const toPublicKey = CLPublicKey.fromHex(to);

const session = DeployUtil.ExecutableDeployItem.newTransfer( amount,toPublicKey,null,id);

const payment = DeployUtil.standardPayment(paymentAmount);
const deploy = DeployUtil.makeDeploy(deployParams, session, payment);

// Turn your transaction data to format JSON
const json = DeployUtil.deployToJson(deploy)

// Sign transcation using casper-signer.
const signature = await window.gosuto.sign(json,publicKeyHex,to)
const deployObject = DeployUtil.deployFromJson(signature)

// Here we are sending the signed deploy.
const signed = await casperClient.putDeploy(deployObject.val);

Sign a message

await window.gosuto.signMessage(message, signingPublicKeyHex)

Last updated