OORT Wallet Developers

The OORT wallet development API and example codes.

The OORT wallet (Chrome Extension) API

The OORT wallet API provides tools for web developers interacting with MCP, the blockchain layer of CCN. The developers can use the API to transfer crypto assets, deploy smart contracts, and build dApps on MCP.

The OORT wallet provider's name is "aleereum".

Check if OORT wallet is installed

typeof window[“aleereum”] !== “undefined”
const provider = window[“aleereum”]

Check if OORT wallet is connected

const isConnected: boolean = provider.isConnected

Check if OORT wallet is locked

const islocked: boolean = provider.islocked

Get current network Id

const networkId: string = provider.networkId

NetworkId = 1: Mainnet (Under development)

NetworkId - 2: Dome-A Testnet

NetworkId = 3: Huygens Testnet

Get current account

const account = provider.account

Get an account balance

interface result {
	success: boolean
	balance: number
	msg: string
}
const balance: Promise<result> = provider.getBalance(account)

Connect or unlock the wallet

const connectStatus: Promise<boolean> = provider.connect()

Listen to the change of account

provider.on("on_account_change", (account) => console.log(account))

Listen to the change of networkId

provider.on("on_networkId_change", (networkId) => console.log(networkId))

Listen to the change of isConnected status of the wallet

provider.on("on_isConnected_change", (isConnected) => console.log(isConnected))

Listen to the change of lock/unlock status of the wallet

provider.on("on_islocked_change", (islocked) => console.log(islocked))

Examples

Vue.js example code

// ale.js
import store from "./store";

window.onload = function() {
  if (typeof window.aleereum !== "undefined") {
    const provider = window["aleereum"];

    if (provider.isAle) {
      store.commit("IS_ALE", true);
      store.commit("M_SET_DAPP_ACCOUNT", provider.account);
      store.commit("M_SET_DAPP_CONNECT", provider.isConnected);
      store.commit("M_SET_DAPP_NETWORK", provider.networkId);
      store.commit("IS_ALE_ENABLED", !provider.islocked);

    } else {
      store.commit("HAS_ALE", false);
    }
  } else {
    store.commit("IS_ALE", false);
  }
};


// App.vue
export default {
    mounted(){
        this.listenDataChange();
    },
    methods: {
        handleNetworkChange(networkID) {
          this.$store.commit("M_SET_DAPP_NETWORK", networkID);
        },
        handleLockChange(status) {
          this.$store.commit("IS_ALE_ENABLED", !status);
        },
        handleConnectChange(status) {
          this.$store.commit("M_SET_DAPP_CONNECT", status);
        },
        handleAccountChange(account) {
          this.$store.commit("M_SET_DAPP_ACCOUNT", account);
        },
        listenDataChange() {
          window.aleereum.on("on_networkId_change", this.handleNetworkChange);
          window.aleereum.on("on_islocked_change", this.handleLockChange);
          window.aleereum.on("on_isConnected_change", this.handleConnectChange);
          window.aleereum.on("on_account_change", this.handleAccountChange);
        },
    },
}

Send a transaction to smart contract

import Mcp from "mcp.js";

const abi = require("./abi.json");

const mcp = new Mcp();

mcp.Contract.setProvider(https://huygens.computecoin.network);

const core = "0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";  // contract address

const Contract = new mcp.Contract(abi, core);

// Query
Contract.methods.xxx().call()
.then(res => {
    console.log(res.toString());
})

// Transaction
Contract.methods.xxx().sendToBlock({
    from: account,
    amount: "0"
})
.then(res => {
    if(!res) {
        throw new Error("Transaction Failed.")
    } else {
        const hash = res.msg;   // blockHash
    } 
})

Last updated