Establishing a Connection

To start interacting with Goby, you must first establish a connection. This connection request will prompt the user for permission to share their account info, indicating that they are willing to interact further. Once approval is established, the web application's domain will allow future connection requests.

Similarly, it is possible to terminate the connection both on the application and the user side.


Before Connnecting

Before connecting, you should check if Goby is installed; if not, follow the guide to install it.

const { chia } = window;
return Boolean(chia && chia.isGoby);

Connecting

The recommended and easiest way to connect to Goby is by calling window.chia.request({ method: "connect" }) .

try {
await window.chia.request({ method: "connect" });
const publicKeys = await window.chia.request({ method: "getPublicKeys" });
// synthetic public keys
// more details, please visit: https://docs.goby.app/example
console.log(publicKeys)
} catch (err) {
// { code: 4001, message: 'User rejected the request.' }
}

The call will return a Promise that resolves when the user has accepted the connection request and reject (throw when awaited) when the user declines the request or closes the pop-up.

Once the web application is connected to Goby, it will be able to read the connected account's address and send transactions.

Eagerly Connecting

After a web application connects to Goby for the first time, it becomes trusted. The application can connect to Goby on subsequent visits, or the page refreshes automatically. This is often called "eagerly connecting.”

To implement this, Goby offers the method called window. chia.request({ method: "connect", params: {eager: true} }) to check if it has been connecting to the wallet.

await window.chia.request({ method: "connect" , "params": {eager: true}})