Comment on page
Ale Wallet Developers
The Ale wallet development API and example codes.
The Ale 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 Ale wallet provider's name is "aleereum".
typeof window[“aleereum”] !== “undefined”
const provider = window[“aleereum”]
const isConnected: boolean = provider.isConnected
const islocked: boolean = provider.islocked
const networkId: string = provider.networkId
NetworkId = 1: Mainnet (Under development)
NetworkId - 2: Dome-A Testnet
NetworkId = 3: Huygens Testnet
const account = provider.account
interface result {
success: boolean
balance: number
msg: string
}
const balance: Promise<result> = provider.getBalance(account)
const connectStatus: Promise<boolean> = provider.connect()
provider.on("on_account_change", (account) => console.log(account))
provider.on("on_networkId_change", (networkId) => console.log(networkId))
provider.on("on_isConnected_change", (isConnected) => console.log(isConnected))
provider.on("on_islocked_change", (islocked) => console.log(islocked))
// 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);
},
},
}
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 modified 1yr ago