Skip to content

API reference

Zhiting Lin edited this page Mar 8, 2019 · 2 revisions

API Reference

Bytom-Chrome-Extension injects a global API into websites visited by its users at window.bytom. This API allows websites to request user login, load data from blockchains the user has a connection to, and suggest the user sign transactions.

Methods

bytom.transfer(to, amount)

Bytom create a simple transaction spend from the current account with the spend amount to the target address.

Here's an example of everyone's favorite method, sending a BTM transaction:

bytom.transfer(
  tm1qjlwwqttpyg3n09g3tkcw3lpps7un59vc85s03f,
  200
)

bytom.advancedTransfer(input, output, gas, args, confirmations)

An Advanced BTM transaction will require the input,output, and the args to contract.

Here's an example of sending an advanced transactions with the smart contract:

input:[
  {"type":"spend_utxo","output_id":"e12eca5132dc6455f44bf92909db97e995ae5ecb35417462e04b72333f5015f0"},
  {"amount":1750000000,"asset":"f855baf98778a892bad0371f5afca845191824dc8584585d566fbbc8ef1f304c","type":"spend_wallet"}
  ]

output:[
  {"amount":1750000000,"asset":"f855baf98778a892bad0371f5afca845191824dc8584585d566fbbc8ef1f304c","control_program":"00147211ec12410ce8bd0d71cab0a29be3ea61c71eb1","type":"control_program"},
  {"amount":3500000000,"asset":"00d38a1c946e8cba1a69493240f281cd925002a43b81f516c4391b5fb2ffdacd","address":"tm1qjlwwqttpyg3n09g3tkcw3lpps7un59vc85s03f","type":"control_address"}
  ]
  
args: [
  {"type":"integer","value":150000000},
  {"type":"address","value":"tm1qjlwwqttpyg3n09g3tkcw3lpps7un59vc85s03f"},
  {"type":"data","value":""}
  ]

bytom.advancedTransfer(
  input,
  ouput,
  4*10000000,
  args,
  1
).then((resp) => {
  //response
})

Input and Output object format are the followings:

    { 
        "type":"spend_utxo", 
        "output_id":"utxostring" 
    }
    { 
        "type":"spend_wallet", 
        "asset":"assetID", 
        "amount":amount 
    }
    { 
        "type":"control_address", 
        "amount":amount, 
        "asset":"assetID", 
        "address":"address" 
    }
    { 
        "type":"control_program", 
        "amount":amount, 
        "asset":"assetID", 
        "control_program":"controlProgram" 
    }

Arguement can use the following format:

{
  "type": "data",
  "value": "ba5a63e7416caeb945eefc2ce874f40bc4aaf6005a1fc792557e41046f7e502f"
}

//or 

{
  "type": "integer",
  "value": 100
}

//or 

{
  "type": "string",
  "value": "string"
}

//or

{
  "type": "boolean",
  "value": true
}

//or

{
  "type": "address",
  "value": "bm1q5u8u4eldhjf3lvnkmyl78jj8a75neuryzlknk0"
}

bytom.request(eventName, options)

The provider supports listening for some events:

  • balance, {Assetid, Guid}, returns the balances of certain assetID and guid.
  • currentAccount, returns current Account on the Bystore.
  • currentNetwork, returns current network ID string.
  • listAllAccount, returns an array of all accounts in the local.

Example

bytom.request('currentAccount')
 .then((resp) => {
  // Time to reload your interface with accounts!
})
bytom.request(
  'balance',
  {
    id: "00d38a1c946e8cba1a69493240f281cd925002a43b81f516c4391b5fb2ffdacd",
    guid: "03f7bc79-a0ee-44f7-9af9-df31df68afe6"
  })
 .then((resp) => {
  // The actual balance!
})
Clone this wiki locally