Skip to content

Commit

Permalink
Add sendTransaction method
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsonevv committed Dec 5, 2024
1 parent e5de64b commit f94f9a3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/core/docs/guides/custom-wallets.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,11 @@ This method is similar to `signMessage` but instead signs and returns a `SignedT

This method composes and signs a SignedDelegate action to be executed in a transaction. Returns the `SignedDelegateWithHash` object.

> Note: Browser wallets (i.e. MyNearWallet) are unable to return the transaction outcome as they can trigger a redirect. The return type in this case is `Promise<void>` instead of the usual `Promise<SignedDelegateWithHash>`.
> Note: Browser wallets (i.e. MyNearWallet) are unable to return the transaction outcome as they can trigger a redirect. The return type in this case is `Promise<void>` instead of the usual `Promise<SignedDelegateWithHash>`.

### `sendTransaction`

This method sends a previously signed transaction to the network. It takes a transaction hash and a signed transaction object, and optionally a callback URL. Returns a `FinalExecutionOutcome` when successful.

> Note: Browser wallets (i.e. MyNearWallet) are unable to return the transaction outcome as they can trigger a redirect. The return type in this case is `Promise<void>` instead of the usual `Promise<FinalExecutionOutcome>`.
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export class WalletModules {
const _signOut = wallet.signOut;
const _signMessage = wallet.signMessage;
const _signTransaction = wallet.signTransaction;
const _sendTransaction = wallet.sendTransaction;
const _signDelegateAction = wallet.signDelegateAction;

wallet.signIn = async (params: never) => {
Expand Down Expand Up @@ -352,6 +353,16 @@ export class WalletModules {
}
};

wallet.sendTransaction = async (signedTransaction: never) => {
if (_sendTransaction === undefined) {
throw new Error(
`The sendTransaction method is not supported by ${wallet.metadata.name}`
);
}

return await _sendTransaction(signedTransaction);
};

wallet.signDelegateAction = async (params: never) => {
if (_signDelegateAction === undefined) {
throw new Error(
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/lib/wallet/wallet.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ interface BaseWalletBehaviour {
signTransaction?(
params: SignTransactionParams
): Promise<[Uint8Array, SignedTransaction] | void>;
/**
* Sends a signed transaction to the network.
*/
sendTransaction?(params: {
hash: Uint8Array;
signedTransaction: SignedTransaction;
callbackUrl?: string;
}): Promise<providers.FinalExecutionOutcome>;
/**
* Composes and signs a SignedDelegate action to be executed in a transaction
*/
Expand Down Expand Up @@ -338,6 +346,14 @@ export type BrowserWalletBehaviour = Modify<
signAndSendTransactions(
params: BrowserWalletSignAndSendTransactionsParams
): Promise<void>;
signTransaction?(
params: SignTransactionParams
): Promise<[Uint8Array, SignedTransaction] | void>;
sendTransaction?(params: {
hash: Uint8Array;
signedTransaction: SignedTransaction;
callbackUrl?: string;
}): Promise<FinalExecutionOutcome | void>;
}
>;

Expand Down

0 comments on commit f94f9a3

Please sign in to comment.