diff --git a/packages/@magic-sdk/provider/src/modules/wallet.ts b/packages/@magic-sdk/provider/src/modules/wallet.ts index a09fe79f0..f925ba9df 100644 --- a/packages/@magic-sdk/provider/src/modules/wallet.ts +++ b/packages/@magic-sdk/provider/src/modules/wallet.ts @@ -2,12 +2,14 @@ import { Events, GasApiResponse, MagicPayloadMethod, + GaslessTransactionRequest, RequestUserInfoScope, UserEnv, UserInfo, WalletInfo, Wallets, } from '@magic-sdk/types'; + import { BaseModule } from './base-module'; import { createJsonRpcRequestPayload } from '../core/json-rpc'; import { createDeprecationWarning } from '../core/sdk-exceptions'; @@ -81,9 +83,9 @@ export class WalletModule extends BaseModule { return this.request(createJsonRpcRequestPayload(MagicPayloadMethod.ShowBalances)); } - public sendGaslessTransaction(address: string, serializedTransaction: string) { + public sendGaslessTransaction(address: string, transaction: GaslessTransactionRequest) { return this.request( - createJsonRpcRequestPayload(MagicPayloadMethod.SendGaslessTransaction, [address, serializedTransaction]), + createJsonRpcRequestPayload(MagicPayloadMethod.SendGaslessTransaction, [address, transaction]), ); } diff --git a/packages/@magic-sdk/provider/test/spec/modules/wallet/sendGaslessTransaction.spec.ts b/packages/@magic-sdk/provider/test/spec/modules/wallet/sendGaslessTransaction.spec.ts index bbbb5636c..02f4588c0 100644 --- a/packages/@magic-sdk/provider/test/spec/modules/wallet/sendGaslessTransaction.spec.ts +++ b/packages/@magic-sdk/provider/test/spec/modules/wallet/sendGaslessTransaction.spec.ts @@ -1,4 +1,5 @@ import browserEnv from '@ikscodes/browser-env'; +import { GaslessTransactionRequest } from '@magic-sdk/types'; import { createMagicSDK } from '../../../factories'; import { isPromiEvent } from '../../../../src/util'; @@ -11,20 +12,28 @@ test('Generate JSON RPC request payload with method `eth_sendGaslessTransaction` magic.wallet.request = jest.fn(); const address = '0x1234'; - const sericalizedTranasction = '0x1234567890abcdef'; + const transaction: GaslessTransactionRequest = { + from: '0x1234', + to: '0x5678', + value: BigInt('12'), + }; - magic.wallet.sendGaslessTransaction(address, sericalizedTranasction); + magic.wallet.sendGaslessTransaction(address, transaction); const requestPayload = magic.wallet.request.mock.calls[0][0]; expect(requestPayload.method).toBe('eth_sendGaslessTransaction'); - expect(requestPayload.params).toEqual([address, sericalizedTranasction]); + expect(requestPayload.params).toEqual([address, transaction]); }); test('method should return a PromiEvent', () => { const magic = createMagicSDK(); const address = '0x1234'; - const sericalizedTranasction = '0x1234567890abcdef'; + const transaction: GaslessTransactionRequest = { + from: '0x1234', + to: '0x5678', + value: BigInt('12'), + }; - expect(isPromiEvent(magic.wallet.sendGaslessTransaction(address, sericalizedTranasction))).toBeTruthy(); + expect(isPromiEvent(magic.wallet.sendGaslessTransaction(address, transaction))).toBeTruthy(); }); diff --git a/packages/@magic-sdk/types/src/modules/wallet-types.ts b/packages/@magic-sdk/types/src/modules/wallet-types.ts index 1b7f10abd..9ad05caf5 100644 --- a/packages/@magic-sdk/types/src/modules/wallet-types.ts +++ b/packages/@magic-sdk/types/src/modules/wallet-types.ts @@ -3,3 +3,85 @@ export type GasApiResponse = { state: string; success: boolean; }; + +export type AccessListEntry = { address: string; storageKeys: Array }; + +/** + * An ordered collection of [[AccessList]] entries. + */ +export type AccessList = Array; + +export interface GaslessTransactionRequest { + /** + * The transaction type. + */ + type?: number; + + /** + * The target of the transaction. + */ + to?: string; + + /** + * The sender of the transaction. + */ + from?: string; + + /** + * The nonce of the transaction, used to prevent replay attacks. + */ + + nonce?: number; + + /** + * The maximum amount of gas to allow this transaction to consime. + */ + gasLimit?: bigint; + + /** + * The gas price to use for legacy transactions or transactions on + * legacy networks. + * + * Most of the time the ``max*FeePerGas`` is preferred. + */ + gasPrice?: bigint; + + /** + * The [[link-eip-1559]] maximum priority fee to pay per gas. + */ + maxPriorityFeePerGas?: bigint; + + /** + * The [[link-eip-1559]] maximum total fee to pay per gas. The actual + * value used is protocol enforced to be the block's base fee. + */ + maxFeePerGas?: bigint; + + /** + * The transaction data. + */ + data?: string; + + /** + * The transaction value (in wei). + */ + value?: bigint; + + /** + * The chain ID for the network this transaction is valid on. + */ + chainId?: bigint; + + /** + * The [[link-eip-2930]] access list. Storage slots included in the access + * list are //warmed// by pre-loading them, so their initial cost to + * fetch is guaranteed, but then each additional access is cheaper. + */ + accessList?: AccessList; + + /** + * A custom object, which can be passed along for network-specific + * values. + */ + customData?: any; +}