• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-core-sdk / 12008523214

25 Nov 2024 10:55AM UTC coverage: 75.515%. Remained the same
12008523214

push

github

web-flow
feat(protocol-kit): Add react native compatibility (#1033)

241 of 390 branches covered (61.79%)

Branch coverage included in aggregate %.

786 of 970 relevant lines covered (81.03%)

3.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/packages/sdk-starter-kit/src/extensions/messages/onChainMessages.ts
1
import { getSignMessageLibContract, hashSafeMessage } from '@safe-global/protocol-kit'
2✔
2
import { OperationType } from '@safe-global/types-kit'
2✔
3

4
import { SafeClient } from '@safe-global/sdk-starter-kit/SafeClient'
5
import { SafeClientResult, SendOnChainMessageProps } from '@safe-global/sdk-starter-kit/types'
6
import { Hash } from 'viem'
7

8
/**
9
 * Extend the SafeClient with the ability to use on-chain messages
10
 * The on-chain messages are regular transactions created using the SignMessageLib so after sendMessage()
11
 * you can confirm the transaction using the safeTxHash anf the confirm() method for transactions
12
 *
13
 * @example
14
 * const safeClient = await createSafeClient({ ... })
15
 *
16
 * const safeMessageClient = await safeClient.extend(
17
 *   onChainMessages()
18
 * )
19
 *
20
 * const { transactions } = await safeMessageClient.sendOnChainMessage({ message })
21
 * await safeMessageClient.confirm({ safeTxHash: transactions?.safeTxHash})
22
 */
23
export function onChainMessages() {
2✔
24
  return (client: SafeClient) => ({
2✔
25
    /**
26
     * Creates and sends a message as a regular transaction using the SignMessageLib contract
27
     * The message can be a string or an EIP712TypedData object
28
     * As this method creates a new transaction you can confirm it using the safeTxHash and the confirm() method and
29
     * retrieve the pending transactions using the getPendingTransactions() method from the general client
30
     * @param {SendOnChainMessageProps} props The message properties
31
     * @returns {Promise<SafeClientResult>} A SafeClientResult. You can get the safeTxHash to confirm from the transaction property
32
     */
33
    async sendOnChainMessage(props: SendOnChainMessageProps): Promise<SafeClientResult> {
34
      const { message, ...transactionOptions } = props
×
35

36
      const signMessageLibContract = await getSignMessageLibContract({
×
37
        safeProvider: client.protocolKit.getSafeProvider(),
38
        safeVersion: client.protocolKit.getContractVersion()
39
      })
40

41
      const transaction = {
×
42
        to: signMessageLibContract.getAddress(),
43
        value: '0',
44
        data: signMessageLibContract.encode('signMessage', [hashSafeMessage(message) as Hash]),
45
        operation: OperationType.DelegateCall
46
      }
47

48
      return client.send({ transactions: [transaction], ...transactionOptions })
×
49
    }
50
  })
51
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc