diff --git a/provider/implementations/js/package.json b/provider/implementations/js/package.json index 029d903..6564889 100644 --- a/provider/implementations/js/package.json +++ b/provider/implementations/js/package.json @@ -1,7 +1,7 @@ { "name": "@polywrap/ethereum-provider-js", "description": "Ethereum Provider JS Plugin", - "version": "0.2.4", + "version": "0.2.5", "license": "MIT", "main": "build/index.js", "files": [ diff --git a/provider/implementations/js/polywrap.yaml b/provider/implementations/js/polywrap.yaml index 9e43388..b4f934c 100644 --- a/provider/implementations/js/polywrap.yaml +++ b/provider/implementations/js/polywrap.yaml @@ -5,3 +5,6 @@ project: source: module: ./src/index.ts schema: ./src/schema.graphql + import_abis: + - uri: wrap://ens/wraps.eth:ethereum-provider@1.1.0 + abi: ../../interface/src/schema.graphql \ No newline at end of file diff --git a/provider/implementations/js/src/index.ts b/provider/implementations/js/src/index.ts index 691d807..09b61d3 100644 --- a/provider/implementations/js/src/index.ts +++ b/provider/implementations/js/src/index.ts @@ -8,7 +8,9 @@ import { IProvider_Module_Args_address as Args_address, IProvider_Module_Args_chainId as Args_chainId, IProvider_Module_Args_waitForTransaction as Args_waitForTransaction, - IProvider_Connection as SchemaConnection + IProvider_Connection as SchemaConnection, + IProvider_Module_Args_nonce as Args_nonce, + IProvider_Module_Args_isWeb3Provider as Args_isWeb3Provider, } from "./wrap"; import { PluginFactory, PluginPackage } from "@polywrap/plugin-js"; import { Connection } from "./Connection"; @@ -46,7 +48,7 @@ export class EthereumProviderPlugin extends Module { * Ethers-rs defines the type of EIP 1559 tx * as 0x02, but metamask expects it as 0x2, * hence, the need of this workaround. Related: - * https://github.com/foundry-rs/foundry/issues/3890. + * https://github.com/MetaMask/metamask-extension/issues/18076 * * We check if the parameters comes as array, if the error * contains 0x2 and if the type is 0x02, then we change it @@ -67,6 +69,27 @@ export class EthereumProviderPlugin extends Module { } } + public async isWeb3Provider( + args: Args_isWeb3Provider, + _client: CoreClient + ): Promise { + const connection = await this._getConnection(args.connection); + /** + * This methods gives to the plugin the capability + * to check if the provider is a wallet (i.e metamask) + * or a given private key (with `new Wallet("0x..")`) + * this allows the wrapper to check if it needs to call + * sendTransaction or sendRawTransaction RPC method + * + * It checks if the provider has the `provider` attribute + * which is something that only the `Web3Provider` has + * but not the JsonRpcProvider: Check the following link for more info: + * https://github.com/ethers-io/ethers.js/blob/v5.7.0/packages/providers/src.ts/web3-provider.ts#L122 + */ + const provider = connection.getProvider(); + return "provider" in provider + } + async waitForTransaction( args: Args_waitForTransaction, _client: CoreClient @@ -119,6 +142,15 @@ export class EthereumProviderPlugin extends Module { return network.chainId.toString(); } + public async nonce( + args: Args_nonce, + _client: CoreClient + ): Promise { + const connection = await this._getConnection(args.connection); + const nonce = await connection.getSigner().getTransactionCount(); + return nonce + } + private async _getConnection(connection?: SchemaConnection | null): Promise { return this._connections.getConnection(connection ?? this.env.connection); } diff --git a/provider/interface/deployment.json b/provider/interface/deployment.json index a524d92..0fafef6 100644 --- a/provider/interface/deployment.json +++ b/provider/interface/deployment.json @@ -6,7 +6,7 @@ "name": "ipfs_deploy", "id": "deploy.ipfs_deploy", "input": "wrap://fs/./build", - "result": "wrap://ipfs/QmXBQNWLpQcR95nequWFLHEcsTDP772QyVFnNuroyr2nzu" + "result": "wrap://ipfs/QmWP9Y1hoZNN6ccjdy6QiskKx3aJXYVrqmx5MCxQ72UML3" } ] } diff --git a/provider/interface/src/schema.graphql b/provider/interface/src/schema.graphql index 2684d17..a582a0e 100644 --- a/provider/interface/src/schema.graphql +++ b/provider/interface/src/schema.graphql @@ -40,4 +40,14 @@ type Module { Get the chain id of the signer's connection. Throws if signer is missing. """ chainId(connection: Connection): String! + + """ + Get the nonce of the signer's. Throws if signer is missing. + """ + nonce(connection: Connection): Int! + + """ + Check if signer is wallet-based. Throws if signer is missing. + """ + isWeb3Provider(connection: Connection): Boolean! }