Skip to main content

Get a system contract address

Get a system contract address, take AElf.ContractNames.Token as an example

const newWallet = AElf.wallet.createNewWallet();
const tokenContractName = "AElf.ContractNames.Token";
let tokenContractAddress;
(async () => {
// get chain status
const chainStatus = await aelf.chain.getChainStatus();
// get genesis contract address
const GenesisContractAddress = chainStatus.GenesisContractAddress;
// get genesis contract instance
const zeroContract = await aelf.chain.contractAt(
GenesisContractAddress,
newWallet
);
// Get contract address by the read only method `GetContractAddressByName` of genesis contract
tokenContractAddress = await zeroContract.GetContractAddressByName.call(
AElf.utils.sha256(tokenContractName)
);
})();