๐ Feature Request
There are some extension wallets that have their own RPC provider. So I'd like to suggest that using wallet's RPC URL in the AptosClient
so that dapp developer don't need to set up a separate RPC in the SDK to use the wallet's resources.
Motivation
We are working on adding a WELLDONE Wallet to the aptos-wallet-adapter
. When implementing the signAndSubmitTransaction
method, I have to use AptosClient.generateTransaction()
method to convert the payload received by arguments into a transaction form. However, in order to create the AptosClient
, I have to put nodeUrl
.
Despite having an RPC provider in the wallet, it felt unncessary to use redundant RPC URL. Therefore, I think changing the SDK methods to utilize the wallet's RPC provider would be much more practical for developers.
Pitch
Iโd like to first add the request
method to PluginProvider
in wallet-adapter-core
, an interface that communicates with the wallet. This method allows communication with the Aptos node using the RPC url in the wallet.
// <https://github.com/aptos-labs/aptos-core/blob/2a1dd9ec05cd4eb4b32d5ff505d21fee8e44a5ea/ecosystem/typescript/sdk/src/generated/core/BaseHttpRequest.ts>
/*
export abstract {
constructor(public readonly config: OpenAPIConfig) {}
public abstract request<T>(options: ApiRequestOptions): CancelablePromise<T>;
}
*/
export interface PluginProvider extends BaseHttpRequest {
connect: () => Promise<AccountInfo>;
account: () => Promise<AccountInfo>;
disconnect: () => Promise<void>;
signAndSubmitTransaction: (
transaction: any,
options?: any
) => Promise<{ hash: Types.HexEncodedBytes } | AptosWalletErrorResult>;
signMessage: (message: SignMessagePayload) => Promise<SignMessageResponse>;
network: () => Promise<NetworkName>;
onAccountChange: (
listener: (newAddress: AccountInfo) => Promise<void>
) => Promise<void>;
onNetworkChange: (
listener: (network: { networkName: NetworkInfo }) => Promise<void>
) => Promise<void>;
//
request<T>(options: ApiRequestOptions) => CancelablePromise<T>;
}
Then, I'd like to make it possible to use a PluginProvider
by adding a constructor option to AptosGeneratedClient
. It is anticipated that the wallet's usability would rise. (You don't need to set up a separate RPC in the SDK to use the wallet's resources.)
// <https://github.com/aptos-labs/aptos-core/blob/2a1dd9ec05cd4eb4b32d5ff505d21fee8e44a5ea/ecosystem/typescript/sdk/src/aptos_client.ts#L88>
constructor(nodeUrl: string | PluginProvider, config?: Partial<Gen.OpenAPIConfig>, doNotFixNodeUrl: boolean = false) {
//...........
if(typeof nodeUrl === 'string') {
this.client = new Gen.AptosGeneratedClient(new HttpRequest({
BASE: config?.BASE ?? '/v1',
VERSION: config?.VERSION ?? '1.2.0',
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
CREDENTIALS: config?.CREDENTIALS ?? 'include',
TOKEN: config?.TOKEN,
USERNAME: config?.USERNAME,
PASSWORD: config?.PASSWORD,
HEADERS: config?.HEADERS,
ENCODE_PATH: config?.ENCODE_PATH,
}));
} else {
this.client = new Gen.AptosGeneratedClient(nodeUrl);
}
}
// <https://github.com/aptos-labs/aptos-core/blob/2a1dd9ec05cd4eb4b32d5ff505d21fee8e44a5ea/ecosystem/typescript/sdk/src/generated/AptosGeneratedClient.ts>
export class AptosGeneratedClient {
public readonly accounts: AccountsService;
public readonly blocks: BlocksService;
public readonly events: EventsService;
public readonly general: GeneralService;
public readonly tables: TablesService;
public readonly transactions: TransactionsService;
public readonly view: ViewService;
public readonly request: BaseHttpRequest;
constructor(Request: BaseHttpRequest | PluginProvider) {
this.request = Request;
this.accounts = new AccountsService(this.request);
this.blocks = new BlocksService(this.request);
this.events = new EventsService(this.request);
this.general = new GeneralService(this.request);
this.tables = new TablesService(this.request);
this.transactions = new TransactionsService(this.request);
this.view = new ViewService(this.request);
}
}
I opened the same issue on aptos-core
.