From 6015c994bcd4180be1e8b7095c99ce5dc8a36777 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Thu, 12 Sep 2024 18:02:40 +0200 Subject: [PATCH 1/3] fix how we validate if the contract is from Ethers and update example --- examples/sdk-simple/index.ts | 36 ++++++++++++++++----- packages/sdk/src/contract/contract.utils.ts | 2 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/examples/sdk-simple/index.ts b/examples/sdk-simple/index.ts index 6acdc27a..c35c5617 100644 --- a/examples/sdk-simple/index.ts +++ b/examples/sdk-simple/index.ts @@ -1,19 +1,39 @@ /* eslint-disable import/no-extraneous-dependencies */ import { dot, moonbeam, polkadot } from '@moonbeam-network/xcm-config'; -import { Sdk, TransferData } from '@moonbeam-network/xcm-sdk'; +import { EvmSigner, Sdk, TransferData } from '@moonbeam-network/xcm-sdk'; import { Keyring } from '@polkadot/api'; import { cryptoWaitReady } from '@polkadot/util-crypto'; import { ethers } from 'ethers'; import { setTimeout } from 'node:timers/promises'; - +import { createWalletClient, http } from 'viem'; +import { privateKeyToAccount } from 'viem/accounts'; +import { moonbeam as moonbeamViem } from 'viem/chains'; // Moonbeam Signer =========================================================== -const moonbeamPrivateKey = ''; -const provider = new ethers.WebSocketProvider(moonbeam.ws, { +const moonbeamPrivateKey = '0x...'; +const provider = new ethers.WebSocketProvider(moonbeam.ws[0], { chainId: moonbeam.id, name: moonbeam.name, }); -const evmSigner = new ethers.Wallet(moonbeamPrivateKey, provider); + +// Using ethers +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const ethersSigner = new ethers.Wallet(moonbeamPrivateKey, provider); + +// Using viem +const account = privateKeyToAccount(moonbeamPrivateKey); +const viemSigner = createWalletClient({ + account, + chain: moonbeamViem, + transport: http('https://rpc.api.moonbeam.network'), +}); + +// ethers +// const evmSigner: EvmSigner = ethersSigner +// const address = ethersSigner.address +// viem +const evmSigner: EvmSigner = viemSigner; +const { address } = account; // Polkadot Signer =========================================================== @@ -65,7 +85,7 @@ export async function fromPolkadot() { console.log('\nTransfer from Polkadot to Moonbeam\n'); const data = await Sdk().getTransferData({ - destinationAddress: evmSigner.address, + destinationAddress: address, destinationKeyOrChain: moonbeam, keyOrAsset: dot, polkadotSigner: pair, @@ -93,7 +113,7 @@ export async function fromMoonbeam() { .asset(dot) .source(moonbeam) .destination(polkadot) - .accounts(evmSigner.address, pair.address, { + .accounts(address, pair.address, { evmSigner, }); @@ -114,7 +134,7 @@ async function main() { console.warn = () => null; console.clear(); - console.log(`\nMoonbeam address: ${evmSigner.address}.`); + console.log(`\nMoonbeam address: ${address}.`); console.log(`Polkadot address: ${pair.address}.`); await fromPolkadot(); diff --git a/packages/sdk/src/contract/contract.utils.ts b/packages/sdk/src/contract/contract.utils.ts index 3a275b74..b3872aa1 100644 --- a/packages/sdk/src/contract/contract.utils.ts +++ b/packages/sdk/src/contract/contract.utils.ts @@ -13,5 +13,5 @@ export function isWalletClient(signer: EvmSigner): signer is WalletClient { export function isEthersContract( contract: Contract | GetContractReturnType, ): contract is Contract { - return 'signer' in contract; + return !('abi' in contract); } From 3b29cc0143a6f196ce6e5ca00f304add6fa800cc Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Thu, 12 Sep 2024 18:03:22 +0200 Subject: [PATCH 2/3] add changeset --- .changeset/famous-meals-wait.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/famous-meals-wait.md diff --git a/.changeset/famous-meals-wait.md b/.changeset/famous-meals-wait.md new file mode 100644 index 00000000..da8f7a50 --- /dev/null +++ b/.changeset/famous-meals-wait.md @@ -0,0 +1,5 @@ +--- +'@moonbeam-network/xcm-sdk': patch +--- + +Fix Ethers contract identification From 3493caf04db5ff2d586c31a76fe29afb5d5f0fdb Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Thu, 12 Sep 2024 18:05:34 +0200 Subject: [PATCH 3/3] add comment --- examples/sdk-simple/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/sdk-simple/index.ts b/examples/sdk-simple/index.ts index c35c5617..513e3bfa 100644 --- a/examples/sdk-simple/index.ts +++ b/examples/sdk-simple/index.ts @@ -17,6 +17,7 @@ const provider = new ethers.WebSocketProvider(moonbeam.ws[0], { }); // Using ethers +// *****WARNING: IN THE UPCOMING VERSION OF THIS SDK, ethers SUPPORT WILL BE REMOVED, PLEASE SWITCH TO viem WHEN POSSIBLE // eslint-disable-next-line @typescript-eslint/no-unused-vars const ethersSigner = new ethers.Wallet(moonbeamPrivateKey, provider);