@astradefi/eip712
TypeScript icon, indicating that this package has built-in type declarations

0.9.4 • Public • Published

EIP712

EIP712 transactions creator.

Installation

  • yarn add @astradefi/astrajs

Example

  • MsgSend:
import {
  createEIP712,
  generateFee,
  generateMessage,
  generateTypes,
  createMsgSend,
  MSG_SEND_TYPES,
} from '@astradefi/astrajs/packages/eip712'

let fee = generateFee(
  '20',
  'aphoton',
  '20000',
  'ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm',
)
let types = generateTypes(MSG_SEND_TYPES)
let msg = createMsgSend(
  '1',
  'aphoton',
  'ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm',
  'ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm',
)
let messages = generateMessage('9', '0', 'ethermint_9000-1', '', fee, msg)
let complete = createEIP712(types, 9000, messages)
console.log(complete)
{
  "types": {
    "EIP712Domain": [
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "version",
        "type": "string"
      },
      {
        "name": "chainId",
        "type": "uint256"
      },
      {
        "name": "verifyingContract",
        "type": "string"
      },
      {
        "name": "salt",
        "type": "string"
      }
    ],
    "Tx": [
      {
        "name": "account_number",
        "type": "string"
      },
      {
        "name": "chain_id",
        "type": "string"
      },
      {
        "name": "fee",
        "type": "Fee"
      },
      {
        "name": "memo",
        "type": "string"
      },
      {
        "name": "msgs",
        "type": "Msg[]"
      },
      {
        "name": "sequence",
        "type": "string"
      }
    ],
    "Fee": [
      {
        "name": "feePayer",
        "type": "string"
      },
      {
        "name": "amount",
        "type": "Coin[]"
      },
      {
        "name": "gas",
        "type": "string"
      }
    ],
    "Coin": [
      {
        "name": "denom",
        "type": "string"
      },
      {
        "name": "amount",
        "type": "string"
      }
    ],
    "Msg": [
      {
        "name": "type",
        "type": "string"
      },
      {
        "name": "value",
        "type": "MsgValue"
      }
    ],
    "MsgValue": [
      {
        "name": "from_address",
        "type": "string"
      },
      {
        "name": "to_address",
        "type": "string"
      },
      {
        "name": "amount",
        "type": "TypeAmount[]"
      }
    ],
    "TypeAmount": [
      {
        "name": "denom",
        "type": "string"
      },
      {
        "name": "amount",
        "type": "string"
      }
    ]
  },
  "primaryType": "Tx",
  "domain": {
    "name": "Cosmos Web3",
    "version": "1.0.0",
    "chainId": 9000,
    "verifyingContract": "cosmos",
    "salt": "0"
  },
  "message": {
    "account_number": "9",
    "chain_id": "ethermint_9000-1",
    "fee": {
      "amount": [
        {
          "amount": "20",
          "denom": "aphoton"
        }
      ],
      "gas": "20000",
      "feePayer": "ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm"
    },
    "memo": "",
    "msgs": [
      {
        "type": "cosmos-sdk/MsgSend",
        "value": {
          "amount": [
            {
              "amount": "1",
              "denom": "aphoton"
            }
          ],
          "from_address": "ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm",
          "to_address": "ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm"
        }
      }
    ],
    "sequence": "0"
  }
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.9.410latest
0.6.1-beta.61canary
0.6.1-beta1beta

Version History

VersionDownloads (Last 7 Days)Published
0.9.410
0.9.01
0.8.12
0.8.00
0.7.02
0.6.10
0.6.1-beta.61
0.6.1-beta1
0.6.01

Package Sidebar

Install

npm i @astradefi/eip712

Weekly Downloads

18

Version

0.9.4

License

MIT

Unpacked Size

91.5 kB

Total Files

71

Last publish

Collaborators

  • tiendn
  • thinhtran3