Exciting release!Introducing "safe npm". Learn more →
Socket
Log inDemoInstall

@morpho-labs/gnosis-tx-builder

Package Overview
Dependencies
1
Maintainers
4
Versions
6
Issues
File Explorer

Advanced tools

@morpho-labs/gnosis-tx-builder

Transform an array of transactions into a json for Gnosis Tx-Builder UX

    1.3.1latest
    GitHub

Version published
Maintainers
4
Weekly downloads
618
increased by9.19%

Weekly downloads

Changelog

Source

v1.3.1

1.3.1 (2023-01-19)

Bug Fixes

  • TxBuilder: export types (09a5f85)

Readme

Source

Gnosis Tx-Builder from a script

npm package Build Status Downloads Issues Commitizen Friendly Semantic Release

⚡🚀 Transform an array of transactions in a Transaction builder json for the Gnosis UX, based on ethers-js

Install

npm install @morpho-labs/gnosis-tx-builder yarn add @morpho-labs/gnosis-tx-builder

Usage

Generate JSON

Generate a Tx builder json file:

import { constants } from "ethers"; import fs from "fs"; import TxBuilder, { ParsingError, ChecksumParsingError, TransactionParsingError, } from "@morpho-labs/gnosis-tx-builder"; const safeAddress = "0x12341234123412341234123412341232412341234"; const transactions = [ { to: constants.AddressZero, value: parseEther("1").toString(), data: "0x", }, ]; const batchJson = TxBuilder.batch(safeAddress, transactions); // dump into a file fs.writeFileSync("batchTx.json", JSON.stringify(batchJson, null, 2));

Now, with the json file, go to the Gnosis dApp, and select Transaction Builder app

Transaction builder

And then, drag and drop the batchTx.json file

img.png

And tada! 🎉🎉

Parse JSON

Parse transactions from a Tx Builder JSON file:

import fs from "fs"; import TxBuilder from "@morpho-labs/gnosis-tx-builder"; // read from a file const batchJson = fs.readFileSync("batchTx.json"); try { const batch = TxBuilder.parse(batchJson); console.log(batch); /* [ { to: "0x000000000000000000000000", value: "1000000000000000000", data: "0x", }, ] */ } catch (e: ParsingError) { if (e instanceof ChecksumParsingError) console.debug(e.params); // { code: ErrorCode; expected: string; computed: string } if (e instanceof TransactionParsingError) console.debug(e.params); // { code: ErrorCode; index: number; parameter?: string } console.debug(e.params); // { code: ErrorCode } }
Error Codes

You can import the error codes from the package

import { ErrorCode } from "@morpho-labs/gnosis-tx-builder";

Available codes

export enum ErrorCode { wrongFormat = "WRONG_FORMAT", //The json file don't match the expected format ({ meta:..., transactions: [...] }) wrongTxFormat = "WRONG_TRANSACTION_FORMAT", //The transaction at index `index` doesn't match the expected format (not an object or parameter `parameter` doesn't have the right type) invalidChecksum = "INVALID_CHECKSUM", //The computed checksum doesn't match the expected one (the one in the file) }

Keywords

FAQs

Last updated on 19 Jan 2023

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc