0

Is there a way of proposing multisig transactions in Gnosis programmatically (with Safe Transaction Service API or Safe Core SDK or anything else) that can interact with external contract (by calling a its method, e.g.) once signed? I see such transactions can be created from Gnosis Safe UI by New Transaction -> Contract Interaction

1 Answer 1

0

With 0xweb you can initialize contract transactions via CLI or with Node.js.

  1. You install the desired contract as a package. For example, the DAI contract to transfer funds.
$ npm i 0xweb -g
$ 0xweb init
$ 0xweb install 0x6b175474e89094c44da98b954eedeac495271d0f --name DAI --chain eth

After you have installed the contract's package. You can view its read and write methods with 0xweb contract abi DAI --chain eth

  1. Add the safe's member to accounts
$ 0xweb accounts add --key 0x... --pin STORAGE_PASSWORD --name fooOwner1
  1. Add existing safe
$ 0xweb safe add --owner fooOwner1 --address 0x... --name fooSafe --chain eth
  1. Create the transfer proposal transaction

    a. via CLI

    0xweb contract write DAI transfer --dst 0x... --wad 5000000000000000000 --account fooSafe --chain eth
    

    b. with Node.js

    import { DAI } from './0xweb/eth/DAI';
    import { Config } from '@dequanto/Config';
    import { ChainAccountsService } from '@dequanto/ChainAccountsService';
    
    async function transfer () {
        await Config.fetch();
    
        const dai = new DAI();
        const accounts = new ChainAccountsService();
        const safeAccount = await accounts.get('fooSafe');
    
        const toAddress = '0x...';
        const amount = 5n * 10n**18n;
        const writer = await dai.transfer(safeAccount, '0x...', amount);
        const receipt = await writer.wait();
    
        console.log(`DAI(${amount}) was sent to ${toAddress}`);
    }
    transfer();
    
  2. Now you have to confirm the transaction before it is sent to the blockchain. For example, if you have a gnosis app, you should have received the push notification with a transaction proposal. After the participants have confirmed the transaction, the CLI process will pick those automatically from the gnosis safe service. Also writer.wait() will also pick the confirmations and send the TX on behalf of the fooOwner1 to the blockchain. And after the tx is mined you'll get the receipt.


You can install any validated contract from etherscan, polygonscan, etc, or you can install a contract by providing the file path to the ABI JSON. And then call any method.


Per default Gnosis Service is used to exchange the confirmation signatures. But you can use also a simple file for this.

$ 0xweb contract write DAI transfer --safe-transport ./my-transaction.json --dst 0x... --wad 5000000000000000000 --account fooSafe --chain eth 

This will serialize the transaction and your confirmation by fooOwner1 to the file. You send the file to all participants, they confirm the transaction, and the last one can execute the transaction, or you get the file back, rewrites the original one, and the CLI process will automatically pick the confirmations and sends the transaction to the blockchain.

To do this with code, you provide the file in the configuration:

const writer = await dai
    .$config({ safeTransport: './my-transaction.json' })
    .transfer(safeAccount, '0x...', amount);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.