Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawiromitchel/0e89e92f77364f09e67973783c37b5b1 to your computer and use it in GitHub Desktop.
Save pawiromitchel/0e89e92f77364f09e67973783c37b5b1 to your computer and use it in GitHub Desktop.
Programmatically submit multiple transactions to a gnosis safe to be signed as one
// Extrapolated from https://github.com/gnosis/safe-core-sdk
const ethers = require('ethers');
const { EthersAdapter } = require('@gnosis.pm/safe-core-sdk');
const Safe = require('@gnosis.pm/safe-core-sdk').default;
const SafeServiceClient = require('@gnosis.pm/safe-service-client').default;
const providerUrl = '....';
const provider = new ethers.providers.JsonRpcProvider(providerUrl);
const privateKey = '....';
const signer = new ethers.Wallet(privateKey, provider);
const ethAdapter = new EthersAdapter({
ethers,
signer,
});
(async function() {
const safeAddress = '....';
const safeSdk = await Safe.create({
ethAdapter,
safeAddress,
});
const transactions = [
{
to: '0x....',
value: '0',
data: '0x....',
},
{
to: '0x...',
value: '0',
data: '0x...',
},
];
const safeTransaction = await safeSdk.createTransaction(...transactions);
const txHash = await safeSdk.getTransactionHash(safeTransaction);
const signature = await safeSdk.signTransactionHash(txHash);
const safeService = new SafeServiceClient('https://safe-transaction.gnosis.io');
try {
await safeService.proposeTransaction(safeAddress, safeTransaction.data, txHash, signature);
console.log(
'Submitted a batch of',
transactions.length,
'transactions to the safe',
safeAddress
);
} catch (err) {
console.log(require('util').inspect(err, true, null, true));
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment