Skip to content
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
4 changes: 2 additions & 2 deletions builders/interoperability/xcm/xcm-sdk/v1/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ The SDK provides the following core methods:
??? code "Parameters"
| Name | Type | Description |
|:----------:|:------------:|:-----------------------------------------------------------:|
| `options?` | *SdkOptions* | Allows you to specify an `ethersSigner` or `polkadotSigner` |
| `options?` | *SdkOptions* | Allows you to specify an `evmSigner` or `polkadotSigner` |

??? code "Returns"
| Name | Type | Description |
Expand All @@ -144,7 +144,7 @@ The SDK provides the following core methods:
|:-----------------------:|:--------------------------------:|:--------------------------------------------------------------------------------------:|
| `destinationAddress` | *string* | The address of the receiving account on the destination chain |
| `destinationKeyorChain` | *string \| AnyChain* | The key or `Chain` data for the destination chain |
| `ethersSigner?` | *EthersSigner* | The Ethers signer for Ethereum-compatible chains that use H160 Ethereum-style accounts |
| `evmSigner?` | *EthersSigner | WalletClient* | The signer for Ethereum-compatible chains that use H160 Ethereum-style accounts. Can be either an Ethers Signer or a viem WalletClient |
| `keyOrAsset` | *string \| Asset* | The key or `Asset` data for the asset being transferred |
| `polkadotSigner?` | *PolkadotSigner \| IKeyringPair* | The Polkadot signer or Keyring pair |
| `sourceAddress` | *string* | The address of the sending account on the source chain |
Expand Down
48 changes: 43 additions & 5 deletions builders/interoperability/xcm/xcm-sdk/v1/xcm-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ npm install ethers@^5.7.2 @polkadot/api @polkadot/util-crypto

## Create Signers {: #create-signers }

When transferring assets between chains, you'll need signers in place to sign the transactions. If you're interacting with an Ethereum-compatible chain that uses standard Ethereum-style H160 addresses, such as Moonbeam, you'll need to have an Ethereum signer, more specifically an [Ethers.js](https://docs.ethers.org/v5/){target=_blank} signer. To interact with the relay chain or other parachains, you'll need a [Polkadot](https://polkadot.js.org/docs/api/){target=_blank} signer.
When transferring assets between chains, you'll need signers in place to sign the transactions. If you're interacting with an Ethereum-compatible chain that uses standard Ethereum-style H160 addresses, such as Moonbeam, you'll need to have an Ethereum signer, which can be an [Ethers.js](https://docs.ethers.org/v5/){target=_blank} signer, or a [viem Wallet Client](https://viem.sh/docs/clients/wallet.html){target=_blank}. To interact with the relay chain or other parachains, you'll need a [Polkadot](https://polkadot.js.org/docs/api/){target=_blank} signer.

You can pass, for example, a [MetaMask signer into Ethers](https://docs.ethers.org/v5/getting-started/#getting-started--connecting){target=_blank} or another compatible wallet. Similarly, with Polkadot, you can [pass a compatible wallet to the signer using the `@polkadot/extension-dapp` library](https://polkadot.js.org/docs/extension/){target=_blank}.

To create a signer for Ethers.js and Polkadot.js, you can refer to the following sections.
To create a signer for EVM and Polkadot.js, you can refer to the following sections.

!!! remember
**Never store your private key or mnemonic in a JavaScript or TypeScript file.**

### Create a Ethers Signer {: #create-a-ethers-signer }
### Create a EVM Signer {: #create-a-evm-signer }

To create a Ethers signer, you can use the following code snippet:

Expand Down Expand Up @@ -107,6 +107,44 @@ For Moonbeam specifically, you can use the following configurations:
const ethersSigner = new ethers.Wallet(privateKey, provider);
```

Alternatively, you can create a viem Wallet Client to pass as EVM Signer

=== "Moonbeam"

```js
import { createWalletClient, custom } from 'viem'
import { moonbeam } from 'viem/chains'

const client = createWalletClient({
chain: moonbeam,
transport: custom(window.ethereum)
})
```

=== "Moonriver"

```js
import { createWalletClient, custom } from 'viem'
import { moonriver } from 'viem/chains'

const client = createWalletClient({
chain: moonriver,
transport: custom(window.ethereum)
})
```

=== "Moonbase Alpha"

```js
import { createWalletClient, custom } from 'viem'
import { moonbase } from 'viem/chains'

const client = createWalletClient({
chain: moonbase,
transport: custom(window.ethereum)
})
```

!!! note
--8<-- 'text/common/endpoint-setup.md'

Expand Down Expand Up @@ -206,7 +244,7 @@ const fromPolkadot = async() => {
.asset('dot')
.source('polkadot')
.destination('moonbeam')
.accounts(pair.address, ethersSigner.address {
.accounts(pair.address, evmSigner.address {
pair,
});
}
Expand All @@ -224,7 +262,7 @@ import { Sdk } from '@moonbeam-network/xcm-sdk';

const fromPolkadot = async() => {
const data = await Sdk().getTransferData({
destinationAddress: ethersSigner.address,
destinationAddress: evmSigner.address,
destinationKeyOrChain: 'moonbeam',
keyOrAsset: 'dot',
polkadotSigner: pair,
Expand Down