Created
September 21, 2021 11:47
-
-
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
This file contains 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
Functionality to submit a batch of transactions to be signed and executed at once in a Gnosis safe.