diff --git a/modules/sdk-coin-icp/src/lib/iface.ts b/modules/sdk-coin-icp/src/lib/iface.ts index ea6ac471ba..f8379fb017 100644 --- a/modules/sdk-coin-icp/src/lib/iface.ts +++ b/modules/sdk-coin-icp/src/lib/iface.ts @@ -25,6 +25,10 @@ export enum MethodName { SEND_PB = 'send_pb', // send_pb is the method name for ICP transfer transaction } +export enum NetworkID { + MAINNET = '00000000000000020101', // ICP does not have different network IDs for mainnet and testnet +} + export interface IcpTransactionData { senderAddress: string; receiverAddress: string; @@ -170,3 +174,13 @@ export interface IcpTransactionExplanation extends BaseTransactionExplanation { sender?: string; type?: BitGoTransactionType; } + +export interface NetworkIdentifier { + blockchain: string; + network: string; +} + +export interface SignedTransactionRequest { + network_identifier: NetworkIdentifier; + signed_transaction: string; +} diff --git a/modules/sdk-coin-icp/src/lib/transaction.ts b/modules/sdk-coin-icp/src/lib/transaction.ts index 03adcb947d..c15ad37eb3 100644 --- a/modules/sdk-coin-icp/src/lib/transaction.ts +++ b/modules/sdk-coin-icp/src/lib/transaction.ts @@ -15,6 +15,8 @@ import { Signatures, TxData, IcpTransactionExplanation, + SignedTransactionRequest, + NetworkID, } from './iface'; import { Utils } from './utils'; import { KeyPair } from './keyPair'; @@ -167,8 +169,22 @@ export class Transaction extends BaseTransaction { } /** @inheritdoc */ - toBroadcastFormat(): void { - throw new Error('Method not implemented.'); + toBroadcastFormat(): string { + if (!this._signedTransaction) { + throw new InvalidTransactionError('Empty transaction'); + } + return this.serialize(); + } + + serialize(): string { + const transaction: SignedTransactionRequest = { + signed_transaction: this._signedTransaction, + network_identifier: { + blockchain: this._coinConfig.fullName, + network: NetworkID.MAINNET, + }, + }; + return Buffer.from(JSON.stringify(transaction)).toString('base64'); } /** @inheritdoc */