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

safe-global / safe-core-sdk / 11029255652

25 Sep 2024 08:18AM CUT coverage: 77.534%. Remained the same
11029255652

push

github

dasanra
chore: set release versions

261 of 410 branches covered (63.66%)

Branch coverage included in aggregate %.

978 of 1188 relevant lines covered (82.32%)

3.49 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 { hashSafeMessage } from '@safe-global/protocol-kit'
1✔
2
import { OperationType } from '@safe-global/safe-core-sdk-types'
1✔
3

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

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

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

41
      const transaction = {
×
42
        to: await signMessageLibContract.getAddress(),
43
        value: '0',
44
        data: signMessageLibContract.encode('signMessage', [hashSafeMessage(message)]),
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