-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AbigailDeng
authored and
AbigailDeng
committed
Jul 4, 2024
1 parent
b896052
commit 556f6ac
Showing
4 changed files
with
80 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,60 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello AElf</title> | ||
</head> | ||
<body> | ||
<p>Hello AElf.</p> | ||
|
||
<script type="text/javascript" src="../../dist/aelf.umd.js"></script> | ||
<script type="text/javascript"> | ||
const AElf = window.AElf; | ||
const Wallet = AElf.wallet; | ||
const sha256 = AElf.utils.sha256; | ||
<head> | ||
<title>Hello AElf</title> | ||
</head> | ||
|
||
const wallet = AElf.wallet.createNewWallet(); | ||
const walletGetByKey = AElf.wallet.getWalletByPrivateKey(wallet.privateKey); | ||
const walletGetByMn = AElf.wallet.getWalletByMnemonic(wallet.mnemonic); | ||
console.log(wallet.address); | ||
console.log(walletGetByKey); | ||
console.log(walletGetByMn); | ||
// link to Blockchain | ||
const aelf = new AElf(new AElf.providers.HttpProvider('http://18.162.41.20:8000')); | ||
if (!aelf.isConnected()) { | ||
alert('Blockchain Node is not running.'); | ||
} | ||
<body> | ||
<p>Hello AElf.</p> | ||
|
||
// the contract you want to query | ||
const tokenContractName = 'AElf.ContractNames.Token'; | ||
const { | ||
// directly accessible information | ||
GenesisContractAddress | ||
} = aelf.chain.getChainStatus({ sync: true }); | ||
aelf.chain | ||
.contractAt(GenesisContractAddress, wallet) | ||
.then(zeroC => { | ||
// return contract's address which you query by contract's name | ||
return zeroC.GetContractAddressByName.call(sha256(tokenContractName)); | ||
}) | ||
.then(tokenContractAddress => { | ||
// return contract's instance and you can call the methods on this instance | ||
return aelf.chain.contractAt(tokenContractAddress, wallet, { | ||
refBlockNumberStrategy: -8 | ||
}); | ||
}) | ||
.then(async tokenContract => { | ||
// return token's info | ||
const result = await tokenContract.GetTokenInfo.call({ | ||
symbol: 'ELF' | ||
}); | ||
console.log(result, 'view token(ELF) info'); | ||
return tokenContract; | ||
}) | ||
.then(async tokenContract => { | ||
const sendResult = tokenContract.Transfer( | ||
{ | ||
symbol: 'ELF', | ||
// memo: '', | ||
to: 'ELF_s3tE7DA1TNndCKsXM4frMAsYfiaU3kXc1obVxxSJ2bhQEC7HA_tDVW', | ||
amount: 100 | ||
}, | ||
{ | ||
refBlockNumberStrategy: -16, | ||
sync: true | ||
} | ||
); | ||
console.log(sendResult, 'sendResult=='); | ||
// alert(JSON.stringify(res)); | ||
<script type="text/javascript" src="../../dist/aelf.umd.js"></script> | ||
<script type="text/javascript"> | ||
const AElf = window.AElf; | ||
const Wallet = AElf.wallet; | ||
const sha256 = AElf.utils.sha256; | ||
|
||
const wallet = AElf.wallet.createNewWallet(); | ||
const walletGotByKey = AElf.wallet.getWalletByPrivateKey(wallet.privateKey); | ||
const walletGotByMn = AElf.wallet.getWalletByMnemonic(wallet.mnemonic); | ||
console.log(wallet.address); | ||
console.log(walletGotByKey); | ||
console.log(walletGotByMn); | ||
// link to Blockchain | ||
const aelf = new AElf(new AElf.providers.HttpProvider( | ||
'https://tdvw-test-node.aelf.io/' | ||
)); | ||
|
||
if (!aelf.isConnected()) { | ||
alert('Blockchain Node is not running.'); | ||
} | ||
|
||
// the contract you want to query | ||
const tokenContractName = 'AElf.ContractNames.Token'; | ||
const { | ||
// directly accessible information | ||
GenesisContractAddress | ||
} = aelf.chain.getChainStatus({ sync: true }); | ||
aelf.chain.contractAt(GenesisContractAddress,wallet) | ||
.then(zeroC => { | ||
// return contract's address which you query by contract's name | ||
return zeroC.GetContractAddressByName.call(sha256(tokenContractName)); | ||
}) | ||
.then(tokenContractAddress => { | ||
// return contract's instance and you can call the methods on this instance | ||
return aelf.chain.contractAt(tokenContractAddress,wallet); | ||
}) | ||
.then(tokenContract => { | ||
// return token's info | ||
return tokenContract.GetTokenInfo.call({ | ||
symbol: 'ELF' | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
}) | ||
.then(res => { | ||
console.log(res); | ||
alert(JSON.stringify(res)); | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters