-
Notifications
You must be signed in to change notification settings - Fork 24
Wallet restful and console API Usage.cn
钱包API一共包括以下几种,在console中输入wallet 回车,可见列表。
wallet { ccinvoketx: function(), createPaymentTx: function(), createRawTransaction: function(), getAddrUtxos: function(), getBalance: function(), getPtnTestCoin: function(), sendRawTransaction: function(), transferToken: function github.com/palletone/go-palletone/cmd/console.(*bridge).TransferToken-fm() }
下面分别介绍。
当使用consloe 调用时,统一格式为:wallet.method,例如:wallet.createRawTransaction
createRawTransaction
参数格式为wallet.createRawTransaction( from, to ,amount ,fee)
例如:
wallet.createRawTransaction("P1H4uUec5di1wCm8pKGLPxhXM6s7xVutKs9","P1sn5uKz2SBvhcRKtQGEqrpGB7mkf73btd",100,10)
getAddrUtxos
参数格式为 : wallet.getAddrUtxos(addresss)
例如:
wallet.getAddrUtxos("P1GtaPbhCnSnMHpwEYbHYBVv4wMTz3yMUTG")
getBalance 参数格式为 : wallet.getBalance(addresss) 例如: wallet.getBalance("P1GtaPbhCnSnMHpwEYbHYBVv4wMTz3yMUTG")
sendRawTransaction 参数格式为:wallet.sendRawTransaction(signedtxstring) 例如: wallet.sendRawTransaction("{"payload":[{"inputs":[ {"txid":"0xdf714994146f1a60d9e63e4ea3c015cd8c77a1cfa23bf96086d7a1332265d777","message_index":0,"out_index":1,"hash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","signature":"0x4079ef31bc2311429a49f506e56063ebe32ef1fef305f5ae9673020664778ff63651a03a9768b823e0df4fa3d5d66f17b9ddce6e8451938d97f64db5b4783d5b44210287ac65fc1c15e851f258509ce73235e1907d3e24ae42abfc9c2e4b074b5e4722"} ],"outputs":[ {"amount":10000000000,"asset":"PTN+8000000000000","to_address":"P1GtaPbhCnSnMHpwEYbHYBVv4wMTz3yMUTG"} , {"amount":99999956000000000,"asset":"PTN+8000000000000","to_address":"P15GK12gMx7Ei979MqSjsi7GgZf5Y2dn66e"} ]}],"invoke_request":{"ContractAddress":"","FunctionName":"","Args":null}}")
其中:signedtxstring 为钱包端接收到wallet.createRawTransaction 创建的交易之后,签名并将其添加到签名字段所构成的字符串。
Restful API 调用方法 首先确认服务器端的地址和端口,端口默认是8545. 确认ptn-config.toml 文件中, HTTPModules = ["net", "web3", "ptn","wallet"] 开启wallet resetful 服务。
createRawTransaction 使用POST 方法,将以下bodydata 发送到服务器地址和 端口,注意http 头部字段Content-Type:application/json
{"jsonrpc":"2.0","method":"wallet_createRawTransaction","params":["P15GK12gMx7Ei979MqSjsi7GgZf5Y2dn66e","P1GtaPbhCnSnMHpwEYbHYBVv4wMTz3yMUTG",30000000,10],"id":1}
创建之后会获取原始的交易,例如:
{ "jsonrpc": "2.0", "id": 1, "result": "{"payload":[{"inputs":[{"txid":"0x3b471090404331dbb0ca668b03ed1aae2f7576ffbd471e8d7bc7ce28a34862cb","message_index":0,"out_index":0,"hash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","signature":""}],"outputs":[{"amount":10000000000,"asset":"PTN","to_address":"P1sn5uKz2SBvhcRKtQGEqrpGB7mkf73btd"},{"amount":99999989000000000,"asset":"PTN","to_address":"P19kW96FMGRwczYGxyizdAY6mWYLckADZdz"}]}],"invoke_request":{"ContractAddress":"","FunctionName":"","Args":null}}" } 之后的签名动作,由钱包完成。单元测试中已经实现钱包端功能,所以,我们可以模拟钱包签名的动作。 找到walletapi_test.api ,TestSignHash 函数 ,将上述result的内容,赋值给test 。注意,私钥也要做相应的修改。 运行测示例,得到签名后的交易字符串。例如: {"payload":[{"inputs":[{"txid":"0x3b471090404331dbb0ca668b03ed1aae2f7576ffbd471e8d7bc7ce28a34862cb","message_index":0,"out_index":0,"hash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","signature":"0x4079ef31bc2311429a49f506e56063ebe32ef1fef305f5ae9673020664778ff63651a03a9768b823e0df4fa3d5d66f17b9ddce6e8451938d97f64db5b4783d5b44210287ac65fc1c15e851f258509ce73235e1907d3e24ae42abfc9c2e4b074b5e4722"}],"outputs":[{"amount":10000000000,"asset":"PTN","to_address":"P1sn5uKz2SBvhcRKtQGEqrpGB7mkf73btd"},{"amount":99999989000000000,"asset":"PTN","to_address":"P19kW96FMGRwczYGxyizdAY6mWYLckADZdz"}]}],"invoke_request":{"ContractAddress":"","FunctionName":"","Args":null}}
将此结果 转义后作为
sendRawTransaction 的参数: {"jsonrpc":"2.0","method":"wallet_sendRawTransaction","params":["{"payload":[{"inputs":[{"txid":"0x3b471090404331dbb0ca668b03ed1aae2f7576ffbd471e8d7bc7ce28a34862cb","message_index":0,"out_index":0,"hash":"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470","signature":"0x4079ef31bc2311429a49f506e56063ebe32ef1fef305f5ae9673020664778ff63651a03a9768b823e0df4fa3d5d66f17b9ddce6e8451938d97f64db5b4783d5b44210287ac65fc1c15e851f258509ce73235e1907d3e24ae42abfc9c2e4b074b5e4722"}],"outputs":[{"amount":10000000000,"asset":"PTN","to_address":"P1sn5uKz2SBvhcRKtQGEqrpGB7mkf73btd"},{"amount":99999989000000000,"asset":"PTN","to_address":"P19kW96FMGRwczYGxyizdAY6mWYLckADZdz"}]}],"invoke_request":{"ContractAddress":"","FunctionName":"","Args":null}}"],"id":1} 得到结果形如: { "jsonrpc": "2.0", "id": 1, "result": "0x34bc968196e9822510747b26734889044e403c36574f6c846edaca45b3a5e52e" } result 不为全0 ,说明发送成功
getAddrUtxos
body格式为 :
{"jsonrpc":"2.0","method":"wallet_getAddrUtxos","params":["P19kW96FMGRwczYGxyizdAY6mWYLckADZdz"],"id":1}
例如:
{"jsonrpc":"2.0","method":"wallet_getAddrUtxos","params":["P19kW96FMGRwczYGxyizdAY6mWYLckADZdz"],"id":1}
得到结果:
{
"jsonrpc": "2.0",
"id": 1,
"result": "{"item":"address_utxos","info":[{"txid":"0x34bc968196e9822510747b26734889044e403c36574f6c846edaca45b3a5e52e","message_index":0,"out_index":1,"amount":99999989000000000,"asset":"PTN","pk_script_hex":"0x76a9145ffb37908945148847e9fe704d1c4b4cec9d066f88ac","pk_script_string":"OP_DUP OP_HASH160 5ffb37908945148847e9fe704d1c4b4cec9d066f OP_EQUALVERIFY OP_CHECKSIG","lock_time":0,"falg_status":"normal"}]}"
}
getBalance 参数格式为 : {"jsonrpc":"2.0","method":"wallet_getBalance","params":["P19kW96FMGRwczYGxyizdAY6mWYLckADZdz"],"id":1} 例如: {"jsonrpc":"2.0","method":"wallet_getBalance","params":["P19kW96FMGRwczYGxyizdAY6mWYLckADZdz"],"id":1} 得到结果
{ "jsonrpc": "2.0", "id": 1, "result": { "PTN": "999999890" } }
GetPtnTestCoin
参数格式: from to amount limit password duration
Console 调用实例 wallet.getPtnTestCoin("P19kW96FMGRwczYGxyizdAY6mWYLckADZdz","P1GBQMq3jSPgTfTDBf2J5mwWWBPHSUtCP8C", "10", "1",10)
Restful API 调用实例 {"jsonrpc":"2.0","method":"wallet_getPtnTestCoin","params":["P15GK12gMx7Ei979MqSjsi7GgZf5Y2dn66e","P1GtaPbhCnSnMHpwEYbHYBVv4wMTz3yMUTG","10","1",10],"id":1}
ccinvoketx
Console 创币调用接口: 参数说明: from地址,to地址,PTN数量(Dao),手续费(Dao),合约ID(固定的PCGTta3M4t3yXu8uRgkKvaWd2d8DREThG43),方法名(createToken),token名字,token符号(全局唯一),小数最小精度(最大18),token初始总量,增发地址
wallet.ccinvoketx("P13WSzZD6U3eBaEB735xTB3eh4PzFU4S7Yu","P1GWZhLPwCmuVUfcXDP6ZzPtupcft3cAa7g","1000","1","PCGTta3M4t3yXu8uRgkKvaWd2d8DREThG43",["createToken", "wzy test description","wzy","1","1000","P13WSzZD6U3eBaEB735xTB3eh4PzFU4S7Yu”])
Restful API 调用实例: {"jsonrpc":"2.0","method":"wallet_ccinvoketx","params":["P13WSzZD6U3eBaEB735xTB3eh4PzFU4S7Yu","P1GWZhLPwCmuVUfcXDP6ZzPtupcft3cAa7g","1000","1","PCGTta3M4t3yXu8uRgkKvaWd2d8DREThG43",["createToken", "wzy test description","wyy","1","1000","P13WSzZD6U3eBaEB735xTB3eh4PzFU4S7Yu"]],"id":1}
增发调用接口: 增发调用:from地址,to地址,PTN数量(Dao),手续费(Dao),合约ID(固定的PCGTta3M4t3yXu8uRgkKvaWd2d8DREThG43),方法名(supplyToken),token符号(全局唯一),增发数量
wallet.ccinvoketx("P13WSzZD6U3eBaEB735xTB3eh4PzFU4S7Yu","P1GWZhLPwCmuVUfcXDP6ZzPtupcft3cAa7g","100","1","PCGTta3M4t3yXu8uRgkKvaWd2d8DREThG43",["supplyToken", "wzy","1000”]) Restful API 调用方法 {"jsonrpc":"2.0","method":"wallet_ccinvoketx","params":["P13WSzZD6U3eBaEB735xTB3eh4PzFU4S7Yu","P1GWZhLPwCmuVUfcXDP6ZzPtupcft3cAa7g","1000","1","PCGTta3M4t3yXu8uRgkKvaWd2d8DREThG43",["supplyToken","wyy","1000"]],"id":1}
token转账 Token资产ID(用getBalance可以看到),from地址,to地址,Token数量,手续费(PTN)
console 调用方式:
wallet.transferToken("WZY+106YMLLKNMQW996HX0A","P13WSzZD6U3eBaEB735xTB3eh4PzFU4S7Yu","P1GWZhLPwCmuVUfcXDP6ZzPtupcft3cAa7g","100","1")
restful API 调用方式(注意地址密码通过最后一个参数传输,这里是1 ,用红色标出) {"jsonrpc":"2.0","method":"wallet_transferToken","params":["WZY+106YMLLKNMQW996HX0A","P13WSzZD6U3eBaEB735xTB3eh4PzFU4S7Yu","P1GWZhLPwCmuVUfcXDP6ZzPtupcft3cAa7g","100","1","1"],"id":1}
查询交易记录 console 调用方式: wallet.getTranscations("P1nuyFKhESpcPEFXc6qWLPDXjvGQ4DVWNF") "[{"txid":"0x7c869482c540a96031ff6bf51bfb0aad0f804c67fa4b4e7ead09fa1372a2a0f4","inputs":["P1CV76HBFaZmxATUgrQ18pgRn7oYnGag2bF"],"outputs":[{"address":"P1nuyFKhESpcPEFXc6qWLPDXjvGQ4DVWNF","vout":1297314800000000,"asset":"PTN"},{"address":"P1CV76HBFaZmxATUgrQ18pgRn7oYnGag2bF","vout":98702685100000000,"asset":"PTN"}]}]" restful API 调用方式 {"jsonrpc":"2.0","method":"wallet_getTranscations","params":["P1nuyFKhESpcPEFXc6qWLPDXjvGQ4DVWNF"],"id":1} 结果形如: { "jsonrpc": "2.0", "id": 1, "result": "[{"txid":"0x7c869482c540a96031ff6bf51bfb0aad0f804c67fa4b4e7ead09fa1372a2a0f4","inputs":["P1CV76HBFaZmxATUgrQ18pgRn7oYnGag2bF"],"outputs":[{"address":"P1nuyFKhESpcPEFXc6qWLPDXjvGQ4DVWNF","vout":1297314800000000,"asset":"PTN"},{"address":"P1CV76HBFaZmxATUgrQ18pgRn7oYnGag2bF","vout":98702685100000000,"asset":"PTN"}]}]" }
PalletOne©2018-2019
Home
Getting started
- Install and build
- Create a private chain
- Launch the PalletOne Client
- Create a PalletOne Account
- Send and Receive PTN
- Create and send your token
- Backing up your account and data
- Restoring your account
- Deposit contract
- Mediator Node Installation and Joining
- Howto Become a Mediator
- Howto Run a Unit-producing Mediator
Developer Tools
- Getting PTNs from PalletOne's Testnet Faucet
- Wallet restful and console API Usage
- Third-Party-Wallet-Support
- Third-Party-Wallet-Contract-Invoke
- API Document
FAQ