diff --git a/testdata/e2e/relay_para.js b/testdata/e2e/relay_para.js new file mode 100644 index 0000000..36f20c1 --- /dev/null +++ b/testdata/e2e/relay_para.js @@ -0,0 +1,83 @@ +import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; +import { Builder } from "@paraspell/sdk"; + +async function testRelayToPara() { + console.log("*".repeat(100)); + console.log("Demo on Sending tokens from Relay Chain to Para chain. \n"); + console.log("*".repeat(100), "\n"); + + console.log("Establishing connection to Relay Chain...."); + let relayWsProvider = new WsProvider("ws://127.0.0.1:34322"); + const relayaAPI = await ApiPromise.create({ provider: relayWsProvider }); + + const relayBlock = await relayaAPI.rpc.chain.getBlock(); + console.log( + "Latest Relay Chain Block Height: ", + relayBlock.block.header.number.toHuman(), + "\n" + ); + + console.log("Establishing connection to Para Chain...."); + let paraWsProvider = new WsProvider("ws://127.0.0.1:34328"); + const paraAPI = await ApiPromise.create({ + provider: paraWsProvider, + noInitWarn: true, + }); + + const paraBlock = await paraAPI.rpc.chain.getBlock(); + console.log( + "Latest Para Chain Block Height: ", + paraBlock.block.header.number.toHuman(), + "\n" + ); + const accountAddress = "gXCcrjjFX3RPyhHYgwZDmw8oe4JFpd5anko3nTY8VrmnJpe"; + console.log( + "Destination Para Chain Account Address : ", + accountAddress, + "\n" + ); + + const initialBal = await paraAPI.query.tokens.accounts(accountAddress, { + token: "KSM", + }); + console.log( + "Initial KSM Balance on Destination chain : ", + initialBal.free.toHuman() + ); + + console.log( + "Building an XCM call to transfer asset from relay chain to Para chain...\n" + ); + const call = Builder(relayaAPI) + .to("BifrostPolkadot", 2000) // Destination Parachain and Para ID + .amount(10000000000000) // Token amount + .address("gXCcrjjFX3RPyhHYgwZDmw8oe4JFpd5anko3nTY8VrmnJpe") // AccountId32 or AccountKey20 address + .build(); // Function called to build call + + console.log("Getting Alice address to sign and send the transaction.. \n"); + const keyring = new Keyring({ type: "sr25519" }); + const alice = keyring.addFromUri("//Alice"); + console.log("Alice Address : ", alice.address, "\n"); + + const hash = await call.signAndSend(alice); + console.log( + "Transaction Successfully submitted. \nHash: ", + JSON.stringify(hash) + ); + relayaAPI.disconnect(); + + // TODO: Listen for events and then check final Balance + await new Promise((f) => setTimeout(f, 25000)); + + const finalBal = await paraAPI.query.tokens.accounts(accountAddress, { + token: "KSM", + }); + console.log( + "KSM Balance on Destination chain after transfer: ", + finalBal.free.toHuman() + ); + + paraAPI.disconnect(); +} + +testRelayToPara(); diff --git a/testdata/e2e/test.ts b/testdata/e2e/test.ts deleted file mode 100644 index 5ecd057..0000000 --- a/testdata/e2e/test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import paraspell from "@paraspell/sdk" -import { ApiPromise, WsProvider } from "@polkadot/api"; -import { web3FromAddress } from "@polkadot/extension-dapp"; - -async function sendXCM(){ -let wsProvider = new WsProvider("ws://127.0.0.1:9944"); -const api = await ApiPromise.create({ provider: wsProvider }); -let call = paraspell.xcmPallet.transferRelayToPara( - api, - "Acala", - "UNIT", - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" -); -const injector = await web3FromAddress( - "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" -); -call?.signAndSend( - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - { signer: injector.signer }, - ({ status, txHash }) => { - console.log({ - text: `Transaction hash is ${txHash.toHex()}`, - duration: 10000, - speed: 100, - }); - if (status.isFinalized) { - console.log({ - text: `Transaction finalized at blockHash ${status.asFinalized}`, - type: "success", - duration: 10000, - speed: 100, - }); - } - } -); -} - -sendXCM() \ No newline at end of file