Skip to content

Latest commit

 

History

History
97 lines (62 loc) · 2.1 KB

erc20-outbound.md

File metadata and controls

97 lines (62 loc) · 2.1 KB

ERC20 - Outbound (WRC20 ⇒ ERC20)

Basic Steps

  • Send approve tx on Wanchain
  • Get outbound fee
  • Send lock tx on Wanchain with outbound fee
  • Wait for storeman response on Ethereum
  • Send redeem tx on Ethereum
  • Wait for storeman response on Wanchain

Required and optional fields

Lock fields

  • to - the receiving Wanchain account
  • from - the sending Ethereum account
  • value - the value to be transferred (in wei)
  • storeman - the storeman (wan/eth) accounts to use
  • redeemKey - the tx redeem key, including x and xHash
  • token - the token addresses on Wanchain and Ethereum
  • outboundFee - the value of fee (in wei)

Redeem fields

  • to - the receiving Ethereum account
  • redeemKey - the tx redeem key, including x and xHash
  • token - the token addresses on Wanchain and Ethereum

Revoke fields

  • from - the sending Wanchain account
  • redeemKey - the tx redeem key, including x and xHash
  • token - the token addresses on Wanchain and Ethereum

Using Wanx

Simple Usage: if the specified Wanchain and Ethereum accounts are open, then you can do the whole crosschain transaction all in one call. You will want to set up event handlers to watch for progress.

cctx.send(opts);

cctx.on('info', info => {
...

Alternatively, you can do the lock and redeem steps separately.

// do lock
cctx.lock(opts);

cctx.on('info', info => {
...

// later, and even maybe elsewhere, do redeem
cctx.redeem(opts);

Advanced Usage: if you need to handle each step separately, like if some steps need to happen on the client and others on the server, you can manually handle each step of the crosschain transaction.

// fine grain handling
Promise.resolve([]).then(() => {

  const approveTx = cctx.buildApproveTx(opts);
  return webwan.eth.sendTransaction(approveTx);

}).then(receipt => {

  return cctx.getOutboundFee(opts);

}).then(fee => {

  opts.outboundFee = fee;

  const lockTx = cctx.buildLockTx(opts);
  return webwan.eth.sendTransaction(lockTx);

}).then(receipt => {

  return cctx.listenLock(opts);

}).then(log => {
...