From 61e71430e7826e8450da2bf93e92a3269470b310 Mon Sep 17 00:00:00 2001 From: mmaurello <93129175+mmaurello@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:18:21 +0200 Subject: [PATCH 1/2] Fix ethers contract identification error (#348) * fix how we validate if the contract is from Ethers and update example * add changeset * add comment --- .changeset/famous-meals-wait.md | 5 +++ examples/sdk-simple/index.ts | 37 ++++++++++++++++----- packages/sdk/src/contract/contract.utils.ts | 2 +- 3 files changed, 35 insertions(+), 9 deletions(-) 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 diff --git a/examples/sdk-simple/index.ts b/examples/sdk-simple/index.ts index 6acdc27a..513e3bfa 100644 --- a/examples/sdk-simple/index.ts +++ b/examples/sdk-simple/index.ts @@ -1,19 +1,40 @@ /* 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 +// *****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); + +// 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 +86,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 +114,7 @@ export async function fromMoonbeam() { .asset(dot) .source(moonbeam) .destination(polkadot) - .accounts(evmSigner.address, pair.address, { + .accounts(address, pair.address, { evmSigner, }); @@ -114,7 +135,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 59027cfcd978744de3f1c9c6481e4b31981643e6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:23:58 +0200 Subject: [PATCH 2/2] Version Packages (#349) Co-authored-by: github-actions[bot] --- .changeset/famous-meals-wait.md | 5 ----- examples/sdk-simple/package.json | 2 +- package-lock.json | 4 ++-- packages/sdk/CHANGELOG.md | 6 ++++++ packages/sdk/package.json | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 .changeset/famous-meals-wait.md diff --git a/.changeset/famous-meals-wait.md b/.changeset/famous-meals-wait.md deleted file mode 100644 index da8f7a50..00000000 --- a/.changeset/famous-meals-wait.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@moonbeam-network/xcm-sdk': patch ---- - -Fix Ethers contract identification diff --git a/examples/sdk-simple/package.json b/examples/sdk-simple/package.json index a11e45e2..9184d47f 100644 --- a/examples/sdk-simple/package.json +++ b/examples/sdk-simple/package.json @@ -13,7 +13,7 @@ "license": "MIT", "dependencies": { "@moonbeam-network/xcm-config": "2.5.12", - "@moonbeam-network/xcm-sdk": "2.5.13", + "@moonbeam-network/xcm-sdk": "2.5.14", "@moonbeam-network/xcm-utils": "2.1.7" }, "devDependencies": { diff --git a/package-lock.json b/package-lock.json index 16f7230e..67505536 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,7 @@ "license": "MIT", "dependencies": { "@moonbeam-network/xcm-config": "2.5.12", - "@moonbeam-network/xcm-sdk": "2.5.13", + "@moonbeam-network/xcm-sdk": "2.5.14", "@moonbeam-network/xcm-utils": "2.1.7" }, "devDependencies": { @@ -19625,7 +19625,7 @@ }, "packages/sdk": { "name": "@moonbeam-network/xcm-sdk", - "version": "2.5.13", + "version": "2.5.14", "license": "MIT", "dependencies": { "@moonbeam-network/xcm-builder": "2.4.7", diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index 3688d1a0..5eb0154d 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -1,5 +1,11 @@ # @moonbeam-network/xcm-sdk +## 2.5.14 + +### Patch Changes + +- [#348](https://github.com/moonbeam-foundation/xcm-sdk/pull/348) [`61e7143`](https://github.com/moonbeam-foundation/xcm-sdk/commit/61e71430e7826e8450da2bf93e92a3269470b310) Thanks [@mmaurello](https://github.com/mmaurello)! - Fix Ethers contract identification + ## 2.5.13 ### Patch Changes diff --git a/packages/sdk/package.json b/packages/sdk/package.json index eaf3aba9..8fac1ed6 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@moonbeam-network/xcm-sdk", - "version": "2.5.13", + "version": "2.5.14", "description": "The Moonbeam XCM SDK enables developers to easily deposit and withdraw assets to Moonbeam/Moonriver from the relay chain and other parachains in the Polkadot/Kusama ecosystem", "scripts": { "build": "tsup",