-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-contract-call.js
More file actions
30 lines (26 loc) · 866 Bytes
/
Copy pathtest-contract-call.js
File metadata and controls
30 lines (26 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { Web3 } = require('web3');
async function testContractCall() {
const web3 = new Web3('http://127.0.0.1:8545');
const contractAddress = '0xC89Ce4735882C9F0f0FE26686c53074E09B0D550';
console.log('1. 測試 totalSupply:');
try {
const result = await web3.eth.call({
to: contractAddress,
data: '0x18160ddd' // totalSupply()
});
console.log('totalSupply result:', result);
} catch (error) {
console.error('totalSupply error:', error);
}
console.log('2. 測試 balanceOf:');
try {
const result = await web3.eth.call({
to: contractAddress,
data: '0x70a08231000000000000000000000000ffcf8fdee72ac11b5c542428b35eef5769c409f0' // balanceOf(second account)
});
console.log('balanceOf result:', result);
} catch (error) {
console.error('balanceOf error:', error);
}
}
testContractCall();