Dapp API Examples

Use imToken2.0 DApp browser scan this qrCode to view exmaples.
show code
imToken.callAPI('navigator.closeDapp')
      
show code
imToken.callAPI('navigator.goBack')
      
show code
imToken.callAPI('navigator.toggleNavbar')
      
show code
imToken.callAPI('navigator.getOrientation', function(err, result) {
	alert(result)
})
      
show code
imToken.callAPI('navigator.setOrientation', 'landscape')
      
show code
imToken.callAPI('navigator.setOrientation', 'portrait')
      
show code
imToken.callAPI('native.alert', 'winner winner, chicken dinner!')
      
show code
imToken.callAPI('native.confirm', {
    title: 'this is title',
    message: 'this is a long message',
    cancelText: 'cancel',
    confirmText: 'confirm'
}, function (err, result) {
    if(err) {
      alert('user canceled')
    } else {
      alert('user confirmed')
    }
})          
      
show code
imToken.callAPI('native.toastInfo', '123456789')
      
show code
imToken.callAPI('native.showLoading', 'loading!');
setTimeout(function() {
    imToken.callAPI('native.hideLoading')
}, 2000)
      
show code
imToken.callAPI('native.selectPicture',{maxWidth: 400, maxHeight: 200}, function (err, ret) {
    if(err) {
      alert(err.message)
    } else {
      document.getElementById('imgContainer').src = ret.data
    }
  })
      
show code
 imToken.callAPI('native.setClipboard', 'are you ok?')
      
show code
imToken.callAPI('native.share', {
  title: 'dapp example',
  message: 'this is example of dapp sdk',
  url: location.href,
}, function (err, ret) {
  if(err) {
    alert('user not share')
  } else {
    alert('shared')
  }
})
      
show code
imToken.callAPI('native.scanQRCode', function (err, ret) {
  if(err) {
    alert(err)
  } else {
    alert(ret)
  }
})
      
show code
var params = {
  to: '0xD9bcf1e096e1C4adD0d587c1E9c620C1072326d4',
  from: window.accounts[0],
  value: '1250000000000000',
  orderInfo: 'buy a cup of coffee',
  feeCustomizable: true
}

imToken.callAPI('transaction.tokenPay', params, function (err, hash) {
  if (err) {
    alert(err)
  } else {
    alert(hash)
  }
})
      
show code
var params = {
  from: window.accounts[0],
  to: '0xD9bcf1e096e1C4adD0d587c1E9c620C1072326d4',
  value: '1250000000000000',
  orderInfo: 'signTransaction',
}

imToken.callAPI('transaction.signTransaction', params, function (err, hash) {
  if (err) {
    alert(err)
  } else {
    alert(hash)
  }
})
      
show code
imToken.callAPI('user.getCurrentAccount', function(err, address) {
  if(err) {
    alert(err)
  } else {
    alert(address)
  }
})
      
show code
imToken.callAPI('user.getAccountList', function(err, list) {
  if(err) {
    alert(err)
  } else {
    alert(list)
  }
})
      
show code
imToken.callAPI('user.showAccountSwitch', {
  contractAddress: '0x0000000000000000000000000000000000000000',
  // Note: contractAddress param will remove in the next version. 
}, function(err, address) {
  if(err) {
    alert(err)
  } else {
    alert(address)
  }
})
      
show code
imToken.callAPI('device.getCurrentLanguage', function(err, language) {
  if(err) {
    alert(err)
  } else {
    alert(language)
  }
})
      
show code
imToken.callAPI('device.getCurrentCurrency', function(err, currency) {
  if(err) {
    alert(err)
  } else {
    alert(currency)
  }
})