说在前面:
请先阅读此文章:ERC20 代币 API 调用-前期准备(一)
一、查看合约对象可调用的 api 接口
在JS交互窗口中输入:
cfcContract
得到以下输出:
> cfcContract
{
abi: [{
constant: true,
inputs: [],
name: "name",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: false,
inputs: [{...}, {...}],
name: "approve",
outputs: [{...}],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: true,
inputs: [],
name: "totalSupply",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: false,
inputs: [{...}, {...}, {...}],
name: "transferFrom",
outputs: [{...}],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: true,
inputs: [],
name: "decimals",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: false,
inputs: [{...}],
name: "withdrawEther",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: false,
inputs: [{...}],
name: "burn",
outputs: [{...}],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: false,
inputs: [{...}],
name: "unfreeze",
outputs: [{...}],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: true,
inputs: [{...}],
name: "balanceOf",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: true,
inputs: [],
name: "owner",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: true,
inputs: [],
name: "symbol",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: false,
inputs: [{...}, {...}],
name: "transfer",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: true,
inputs: [{...}],
name: "freezeOf",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
constant: false,
inputs: [{...}],
name: "freeze",
outputs: [{...}],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: true,
inputs: [{...}, {...}],
name: "allowance",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}, {
inputs: [{...}, {...}, {...}, {...}],
payable: false,
stateMutability: "nonpayable",
type: "constructor"
}, {
payable: true,
stateMutability: "payable",
type: "fallback"
}, {
anonymous: false,
inputs: [{...}, {...}, {...}],
name: "Transfer",
type: "event"
}, {
anonymous: false,
inputs: [{...}, {...}],
name: "Burn",
type: "event"
}, {
anonymous: false,
inputs: [{...}, {...}],
name: "Freeze",
type: "event"
}, {
anonymous: false,
inputs: [{...}, {...}],
name: "Unfreeze",
type: "event"
}],
address: "0xd4b33b74cec5141c0c40be4a664641495c6afc7e",
transactionHash: null,
Burn: function(),
Freeze: function(),
Transfer: function(),
Unfreeze: function(),
allEvents: function(),
allowance: function(),
approve: function(),
balanceOf: function(),
burn: function(),
decimals: function(),
freeze: function(),
freezeOf: function(),
name: function(),
owner: function(),
symbol: function(),
totalSupply: function(),
transfer: function(),
transferFrom: function(),
unfreeze: function(),
withdrawEther: function()
}
>
返回到控制台的结果就是你可以调用的各个接口。
二、简单实例如何调用接口
将智能合约中的eth代币转出:
- withdrawEther方法调用
web3.eth.defaultAccount = "0xbb438852706212284ff8E1ED6dA7F000e9ecd1A6"
personal.unlockAccount("私钥")
cfcContract.withdrawEther(75000000000000000)
代币销毁:
- burn方法调用
personal.unlockAccount("私钥")
cfcContract.burn(100000000000000000000) // 由于该cfc代币的denamic为18,所以要销毁的数量=数量*10^18
代币冻结:
- freeze方法调用
personal.unlockAccount("私钥")
cfcContract.freeze(100000000000000000000)
代币解冻:
- unfreeze方法调用
personal.unlockAccount("私钥")
cfcContract.unfreeze(100000000000000000000)
以上只使用了部分接口,其他接口都雷同。
web3.eth.defaultAccount 方法是指定默认账户,可代替 from(发送方的账户)
如果搭建过程中遇到任何问题,请发送问题致邮件:Adamson_xgp@163.com,我会尽我所能帮您解答。
打赏(加密货币)
BTC地址:1MHAPXoydTMTXi9r5mHYp3kGFYkKGcpXf
ETH地址:0x8d345c08805c1e0d21f518bb301640e937b8c2c6
ADA地址:DdzFFzCqrhsqmBCy6zTcdy1bshH3p5LtfmssqvL8AUcPjf55q7LteaJtx7eztaayftSj3aKWS4qWqUPJVt3ZiPVmtoKHdRYrfMHDzwGn
EOS地址:0x8d345c08805c1e0d21f518bb301640e937b8c2c6