Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ethers contract identification error #348

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-meals-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@moonbeam-network/xcm-sdk': patch
---

Fix Ethers contract identification
37 changes: 29 additions & 8 deletions examples/sdk-simple/index.ts
Original file line number Diff line number Diff line change
@@ -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 ===========================================================

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -93,7 +114,7 @@ export async function fromMoonbeam() {
.asset(dot)
.source(moonbeam)
.destination(polkadot)
.accounts(evmSigner.address, pair.address, {
.accounts(address, pair.address, {
evmSigner,
});

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/contract/contract.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function isWalletClient(signer: EvmSigner): signer is WalletClient {
export function isEthersContract(
contract: Contract | GetContractReturnType<Abi | readonly unknown[]>,
): contract is Contract {
return 'signer' in contract;
return !('abi' in contract);
}