Skip to content

Instantly share code, notes, and snippets.

@jjgonecrypto
Created September 21, 2021 11:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jjgonecrypto/6db21caed633f27548a4bcc1642c6f76 to your computer and use it in GitHub Desktop.
Save jjgonecrypto/6db21caed633f27548a4bcc1642c6f76 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));
}
})();
@jjgonecrypto
Copy link
Author

jjgonecrypto commented Sep 21, 2021

Functionality to submit a batch of transactions to be signed and executed at once in a Gnosis safe.

image

@eth-jashan
Copy link

@justinjmoses how are the nounce and gas limit price is set in batch transaction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment