Last active
February 23, 2024 07:44
-
-
Save o-az/cf643b6c87cd3977e1678c7a0d0a6b6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { raise } from '#/utilities' | |
import { unionActions } from '#/actions.ts' | |
import { mnemonicToAccount } from 'viem/accounts' | |
import { http, publicActions, createWalletClient } from 'viem' | |
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing' | |
import { UCS01_EVM_ADDRESS, demoMnemonic, chain } from '#/constants' | |
main().catch(_ => { | |
console.error(_) | |
process.exit(1) | |
}) | |
async function main() { | |
const demoEthereumAccount = mnemonicToAccount(demoMnemonic) | |
const demoEthereumAddress = demoEthereumAccount.address | |
const demoUnionAccount = await DirectSecp256k1HdWallet.fromMnemonic(demoMnemonic, { | |
prefix: 'union', | |
}) | |
const [demoUnionAccountData] = await demoUnionAccount.getAccounts() | |
const demoUnionAddress = demoUnionAccountData?.address ?? raise('demoUnionAddress is undefined') | |
const client = createWalletClient({ | |
chain: chain.ethereum.sepolia, | |
account: demoEthereumAccount, | |
transport: http(process.env.SEPOLIA_RPC_URL), | |
}) | |
.extend(publicActions) | |
.extend(unionActions) | |
const denomAddress = await client.getDenomAddress() | |
const balanceOnUnion = await client.getBalance({ | |
chainId: '6', // union-testnet-6 | |
address: demoUnionAddress, | |
assetId: chain.union.testnet.token.denom, | |
}) | |
const sendAssetFromUnionToEthereum = await client.sendAsset({ | |
chainId: '6', // union-testnet-6 | |
signer: demoUnionAccount, | |
assetId: chain.union.testnet.token.address, | |
amount: '1234', | |
denom: 'muno', | |
receiver: demoEthereumAddress, | |
gasPrice: '0.001muno', | |
}) | |
const balanceOnSepolia = await client.getBalance({ | |
chainId: '11155111', // sepolia | |
address: demoEthereumAddress, | |
}) | |
const approveAssetOnSepolia = await client.approveAsset({ | |
chainId: '11155111', // sepolia | |
signer: demoEthereumAccount, | |
amount: 135920n, | |
spender: UCS01_EVM_ADDRESS, | |
assetId: denomAddress, | |
}) | |
const sendAssetFromSepoliaToUnion = await client.sendAsset({ | |
chainId: '11155111', // sepolia | |
portId: chain.ethereum.sepolia.portId, | |
signer: demoEthereumAccount, | |
assetId: denomAddress, | |
amount: 100n, | |
receiver: demoUnionAddress, | |
simulate: true, | |
}) | |
console.log({ | |
balanceOnUnion, | |
sendAssetFromUnionToEthereum, | |
balanceOnSepolia, | |
approveAssetOnSepolia, | |
sendAssetFromSepoliaToUnion, | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment