Code Monkey home page Code Monkey logo

bridge-sdk's Introduction

Bridge SDK

Basic usage

Install from npm:

npm i @terra-money/bridge-sdk

Connect station:

import { StationWallet, ChainType, BridgeType, isValidAddress } from '@terra-money/bridge-sdk'

const wallet = new StationWallet()

if (!wallet.isSupported()) {
  console.log(
    `${wallet.description.name} is not supported on your device, please try from a different wallet.`,
  )
} else if (!wallet.isInstalled()) {
  console.log(`You can install ${wallet.description.name} here: ${wallet.description.installLink}`)
}

wallet
  .connect(ChainType.terra)
  .then(({ address }) => console.log(address))

If you are using TerraLedgerWallet you can specify more options on the connect function, to select a custom derivation index (default is 0) and to use bluetooth (default is USB)

Get the balance (wallet must be already connected):

wallet
  .getBalance('uluna')
  .then((res) => {
    res.success
      ? console.log(`Balance: ${res.data} uluna`)
      : console.log(`Error: ${res.error}`
  })

Send tx from station (wallet must be already connected):

const destinationAddress = 'osmo1...'

// validate destination address
if(!isValidAddress(destinationAddress, ChainType.osmosis)) {
  console.log('Error: invalid address')
  return
}

// transfer
wallet
  .transfer({
    src: ChainType.terra,
    dst: ChainType.osmosis,
    bridge: BridgeType.ibc,
    address: destinationAddress,
    coin: {
      amount: 100_000,
      denom: 'uluna',
    },
  })
  .then((res) => {
    res.success
      ? console.log(`TX hash: ${res.txhash}`)
      : console.log(`Error: ${res.error}`
  })

You can use the same functions on the TerraLedgerWallet,KeplrWallet and MetaMaskWallet to send a tx from those wallets

You can find more info about the available functions on the Wallet inteface

Coming soon

  • More IBC chains

  • Support for wormhole

  • Other wallets: (Station mobile, Coinbase wallet, BSC, WalletConnect, Keplr Mobile)

  • Function estimateBridgeFee() to calculate the fee that the user will pay on the transfer.

  • Function waitForTx()to wait until the tx is confirmed on-chain.

  • Functions onAccountChange() and onNetworkChange() to trigger actions when the user switch account or networ.

bridge-sdk's People

Contributors

alecande11 avatar 0xphilipp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.