JSPM

  • Created
  • Published
  • Downloads 14404
  • Score
    100M100P100Q146811F
  • License MIT

SDK developed to integrate third-party apps with Safe-Multisig app.

Package Exports

  • @gnosis.pm/safe-apps-sdk

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@gnosis.pm/safe-apps-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Safe Apps SDK

Logo

Build Status

Software development kit to integrate third-party applications (Safe Apps) with Safe Multisig (https://gnosis-safe.io/app/).

Install

Install the package with yarn or npm:

yarn add @gnosis.pm/safe-apps-sdk

npm install @gnosis.pm/safe-apps-sdk

Build

yarn install
yarn build

npm install
npm build

Documentation

Apps built with this Sdk are meant to be run in an iframe inside the Safe Web UI. This library exposes a single method called initSdk that receives a single optional parameter, an array of regular expressions. By default it's configured to accept messages from this URLs:

By passing the argument to initSdk you can add more URLs to the list. It's useful when you are running a local instance of Safe Multisig.

import React, { useState, useEffect } from 'react';
import initSdk from '@gnosis.pm/safe-apps-sdk';

const [appsSdk] = useState(initSdk());

It returns a SDK instance that allows you to interact with the Safe Multisig application.

Register events

Once you get the SDK instance, you will be able to subscribe to events from the Safe Multisig.

The SDK instance exposes a method called addListener that receives an object with known keys, over these keys you will be able to subscribe to different events.

The first event that you should subscribe to is onSafeInfo; It will provide you first level information like the safeAddress, network, etc.

const [safeInfo, setSafeInfo] = useState(); // Hook for SafeInfo to be stored

useEffect(() => {
  appsSdk.addListeners({
    onSafeInfo: setSafeInfo,
  });

  return () => appsSdk.removeListeners();
}, [appsSdk]);

Sending TXs

Sending a TX through the Safe Multisig is as simple as invoking sendTransaction method with an array of TXs.

// Create a web3 instance
const web3: any = new Web3('https://rinkeby.infura.io/v3/token');
const contract = new web3.eth.Contract(abi, contractAddress);

// Set Txs array
txs = [
  {
    to: someAddress,
    value: 0,
    data: contract.methods.someMethod().encodeABI(),
  },
  {
    to: someAddress2,
    value: 0,
    data: contract.methods.someOtherMethod().encodeABI(),
  },
];

// Send to Safe-multisig
appsSdk.sendTransactions(txs);

Testing in the Safe Multisig application

Once your app is ready you need to deploy it on the internet. It is mandatory that your app exposes a manifest.json file in the root dir with this structure:

{
  "name": "YourAppName",
  "description": "A description of what your app do",
  "iconPath": "myAppIcon.svg"
}

Note: iconPath it's the public relative path where the Safe Multisig will try to load your app icon. For this example, it should be https://yourAppUrl/myAppIcon.svg.

Remember to also enable Cross Site Requests for the site. For example if using Netlify add a file _headers with the following content:

/*
Access-Control-Allow-Origin: *

When your app is live, you can import it to the Safe Multisig application. To do so, you should select the "Apps" tab:

alt text

Use the Manage Apps button and add your app using a link:

alt text

Examples of applications built with this SDK

License

This library is released under MIT.

Contributors