Installation

To install AIWA, head to the Chrome Web Store and install from there. You can skip ahead to the Getting Started section if you do this.

We also offer unpacked versions for Chrome. These are the latest builds available since it usually takes a few days for a build to be reviewed by Google. See github.com/blockxlabs/aiwa/releases for our latest release.

To install:

  • Decompress the downloaded ZIP file
  • Go to chrome://extensions
  • Enable 'Developer Mode' (top right corner of window)
  • Click "Load Unpacked" and select the 'build' directory that was just decompressed

Keep in mind that the unpacked versions don't auto-update. You'll need to manually remove and install the updated version through the same process. If you watch the aiwa repo, you'll be notified by email whenever a new release is available.

Getting Started

If you're familiar with other browser-based wallets, it's quite similar. Just declare aion-web3 after window.onLoad.

We're handling the following functions as promises instead of callbacks:

  • sign
  • send
  • getAccounts

Use aionweb3 the same way as web3, but simply change variable name from web3 to aionweb3.

Examples

Allowing users in privacy mode to grant access to a DApp

If a user is in privacy mode, AIWA will wait until prompted to give account information. Therefore access must be granted by the user before a transaction can be processed. Best practice is to create a button to allow for this. It can also be done after onLoad. If a user does not have privacy mode on it will ignore the code. So always make sure to put it in.

aiwa.enable();
						

Initializing Contract Instance

When initializing the contract instance

window.onload = () => {
  const contractInstance = aionweb3.eth.contract(ABI).at(CONTRACT_ADDRESS)
}

Contract Read Function

When calling a read function on a contract, you can simply use the function namespace:

contractInstance.functionName([Param1], [Param2])

Contract Write Function

Calling a write function is similar to a read in this instance since this involves a transaction a transaction hash will be returned or an error.

const writeFunction = async () => {
try {
  const txHash = await contractInstance.functionName([Param1], [Param2])
  return txHash
}catch(err) {
  console.log(err);
  }
}

Sign Method

Utilize the sign method to able to sign data from a specific account:

const signFunction = async () => {
 try {
  const signedMsg = await aionweb3.eth.sign(aionweb3.eth.accounts[0], "0x123456");
  console.log(signedMsg);   
 }catch(err) {
  console.log(err);
 } 
}

Sign Transaction

Similarly to sign a transaction, utilize the signTransaction method as shown below.

const signTransactionFunction = async () => {
 const tx = { 
    to: '0xa020f60b3f4aba97b0027ca81c5d20c9898d7c43a50359d209596b86e8ce3ca2',
    value: 0,
    data:"0x123456",
    from: aionweb3.eth.accounts[0]
  };
 try {
    const signedTx = await aionweb3.eth.signTransaction(tx)
 }catch(err){
    console.log(err);
 }
}