# Creating Gnosis Safes via the API

**URL:** <https://forum.openzeppelin.com/t/creating-gnosis-safes-via-the-api/12031>\
**Category:** Defender\
**Created:** [July 7, 2021, 11:08am UTC](https://forum.openzeppelin.com/t/creating-gnosis-safes-via-the-api/12031 "2021-07-07T11:08:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Roman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/george_roman/32/4116_2.png) [@George\_Roman](https://forum.openzeppelin.com/u/George_Roman)\
**Post date:** [July 7, 2021, 11:08am UTC](https://forum.openzeppelin.com/t/creating-gnosis-safes-via-the-api/12031/1 "2021-07-07T11:08:03Z")

</div>

Is it possible to create a Gnosis Safe via API instead of the UI? Or at least is there a factory contract that can be used to easily deploy safes and then have them linked to defender (I’m interested in polygon and mumbai networks)?

---

<div class="post-metadata">

**Author:** ![MartinVerzilli](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/martinverzilli/32/1912_2.png) [@MartinVerzilli](https://forum.openzeppelin.com/u/MartinVerzilli)\
**Post date:** [July 7, 2021, 2:26pm UTC](https://forum.openzeppelin.com/t/creating-gnosis-safes-via-the-api/12031/2 "2021-07-07T14:26:13Z")

</div>

Hi George, thanks for reaching out. Out of curiosity, may I ask why you need to create a Safe via the API? The information could help us design better ways of supporting your use scenarios from Defender.

As regards Safe factory contracts, we deployed them to the following addresses:

Polygon/Matic:

- Safe Master Contract: ‘0xC4180A6A9EeCc46Ae83b6281C07EC1c6544fe581’
- Safe Contract Factory: ‘0x971497458154c42a3d96B8c03453cB97219ce7Ee’

Mumbai:

- Safe Master Contract: ‘0xC4180A6A9EeCc46Ae83b6281C07EC1c6544fe581’
- Safe Contract Factory: ‘0x971497458154c42a3d96B8c03453cB97219ce7Ee’

To deploy one, you need to execute the Contract Factory’s `createProxy` function, which receives arguments to execute the `setup` function on the Master Contract.

The code using Ethers JS would look (approximately) like this:

```auto
const masterContractAddress = '0x...';
const safeOwners: string[] = ['0x...', '0x...', etc];
const threshold = 3;

// gnosisSafeAbi is the Gnosis Safe ABI in JSON format,
// you can find an example here: https://github.com/gnosis/safe-deployments/blob/main/src/assets/v1.1.1/gnosis_safe.json#L16
const gnosisInterface = new Interface(gnosisSafeAbi);
const safeSetupData = gnosisInterface.encodeFunctionData('setup', [
  safeOwners, 
  threshold,
  '0x0000000000000000000000000000000000000000',
  '0x',
  '0x0000000000000000000000000000000000000000',
  '0x0000000000000000000000000000000000000000',
  '0',
  '0x0000000000000000000000000000000000000000',
]);

// safeContractFactory is an instance of the "Contract" type from Ethers JS
// see https://docs.ethers.io/v5/getting-started/#getting-started--contracts
// for more details.
// You're going to need the address of a Safe contract factory and the ABI,
// which can be found here: https://github.com/gnosis/safe-deployments/blob/main/src/assets/v1.1.1/proxy_factory.json#L16
const proxy = await safeContractFactory.functions.createProxy(masterContractAddress, safeSetupData);

```

Once you’ve deployed a Safe, you can use [https://www.npmjs.com/package/defender-admin-client#user-content-adding-contracts](https://www.npmjs.com/package/defender-admin-client#user-content-adding-contracts) to programmatically import it to Defender via the API. It’s worth noting that you don’t need to do this though, you can “just use it” by pasting its address when you create an Admin proposal.

Hope this helps!  
Martín

---

<div class="post-metadata">

**Author:** ![George\_Roman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/george_roman/32/4116_2.png) [@George\_Roman](https://forum.openzeppelin.com/u/George_Roman)\
**Post date:** [July 8, 2021, 7:52am UTC](https://forum.openzeppelin.com/t/creating-gnosis-safes-via-the-api/12031/3 "2021-07-08T07:52:23Z")

</div>

Hi Martin! Thank you for your response, it’s really helpful. We have a use case where we need to trigger the deployment of a safe on demand (once an API call is made) - this is where deployment via API would come handy (but given all your info that’s not really needed at all since we can trigger the deployment directly via the code you provided).

---

<div class="post-metadata">

**Author:** ![MartinVerzilli](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/martinverzilli/32/1912_2.png) [@MartinVerzilli](https://forum.openzeppelin.com/u/MartinVerzilli)\
**Post date:** [July 8, 2021, 9:35am UTC](https://forum.openzeppelin.com/t/creating-gnosis-safes-via-the-api/12031/4 "2021-07-08T09:35:03Z")

</div>

Glad it helped! For your use case, you might want to consider writing an autotask that takes care of the deploy for you through a relayer. You can configure the autotask to be triggered via a webhook, and invoke it from your API call. That way you can take advantage of Defender’s secure key management, its gas estimation heuristics, and you can also keep a single relayer as the funding account for those deployments.

---

<div class="post-metadata">

**Author:** ![hugh](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@hugh](https://forum.openzeppelin.com/u/hugh)\
**Post date:** [January 19, 2022, 6:08pm UTC](https://forum.openzeppelin.com/t/creating-gnosis-safes-via-the-api/12031/5 "2022-01-19T18:08:26Z")

</div>

Can you add the Safe Master Contract and Safe Master Factory addresses for ETH as well?

---

<div class="post-metadata">

**Author:** ![spalladino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/spalladino/32/22_2.png) [@spalladino](https://forum.openzeppelin.com/u/spalladino)\
**Post date:** [January 19, 2022, 8:42pm UTC](https://forum.openzeppelin.com/t/creating-gnosis-safes-via-the-api/12031/6 "2022-01-19T20:42:33Z")

</div>

We're using the v1.3.0 deployments:

> **[safe-deployments/src/assets/v1.3.0 at main · gnosis/safe-deployments](https://github.com/gnosis/safe-deployments/tree/main/src/assets/v1.3.0)**
>
> main/src/assets/v1.3.0

```auto
safeMasterContract: "0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552"
safeContractFactory: "0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2"

```
