Forked from jjgonecrypto/gnosis-safe-multisend-submitter.js
Created
February 10, 2022 16:15
-
-
Save eth-jashan/f2e5ddc1a19f09315ee0619f44f3d15b to your computer and use it in GitHub Desktop.
Programmatically submit multiple transactions to a gnosis safe to be signed as one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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