-
Notifications
You must be signed in to change notification settings - Fork 24
Wallet Restful and Console API Usage
钱包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,locktime) 参数说明: from:发送地址 to:接收地址 amount:发送数量 fee:手续费 locktime: 锁定时间,采用时间戳格式,为1970年1月1日至今的秒数。当这个值小于500000000(5亿)时,表示锁定高度。
例如:
wallet.createRawTransaction("P1H4uUec5di1wCm8pKGLPxhXM6s7xVutKs9","P1sn5uKz2SBvhcRKtQGEqrpGB7mkf73btd",100,10,0)
getAddrUtxos
参数格式为 :
wallet.getAddrUtxos(addresss)
例如:
wallet.getAddrUtxos("P1GtaPbhCnSnMHpwEYbHYBVv4wMTz3yMUTG")
getBalance
参数格式为 :
wallet.getBalance(addresss)
例如:
wallet.getBalance("P1GtaPbhCnSnMHpwEYbHYBVv4wMTz3yMUTG")
sendRawTransaction
参数格式为:
wallet.sendRawTransaction(signedtxstring)
例如:
wallet.sendRawTransaction("f90150a06a155e25b6b72e19e700e26a8a5d8fd66348a49bb6369eb6afcbef41446171a6f9012cf9012980b90125f90122f88cf88ae3a0b11a08725aa65de6f60f4739a516470ef68398d5d0042d503786c521c86b19cb8080b86340e19567e417e6f29a811ca1016beef52ee828941f0b000014498aa66225577969452ae325d6557ea08a7e439315c6599c7f76f1d5c4d8fd816e1919f56e5e56b62103219fe309fe05c95b5515e58dc8937493e0c1da9bbde5e27459e6597c0059a47180f891f846870e35fa931a00009976a91405bb920e316e46f9b639ae3a9f5a130d2cf6386188ace39000000000000000000000000000000000900000000000000000000000000000000080f84788014a670164e6ec009976a91456be6e395cfa5aecf66338814560e95f23ff4dd188ace3900000000000000000000000000000000090000000000000000000000000000000008080") "0x6a155e25b6b72e19e700e26a8a5d8fd66348a49bb6369eb6afcbef41446171a6")
其中:signedtxstring 为钱包端接收到wallet.createRawTransaction 创建的交易之后,签名并将其添加到签名字段所构成的字符串,再进行rlp编码的结果。
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": "f8e6a06a155e25b6b72e19e700e26a8a5d8fd66348a49bb6369eb6afcbef41446171a6f8c3f8c180b8bef8bce7e6e3a0b11a08725aa65de6f60f4739a516470ef68398d5d0042d503786c521c86b19cb80808080f891f846870e35fa931a00009976a91405bb920e316e46f9b639ae3a9f5a130d2cf6386188ace39000000000000000000000000000000000900000000000000000000000000000000080f84788014a670164e6ec009976a91456be6e395cfa5aecf66338814560e95f23ff4dd188ace3900000000000000000000000000000000090000000000000000000000000000000008080" } 之后的签名动作,由钱包完成。单元测试中已经实现钱包端功能,所以,我们可以模拟钱包签名的动作。 找到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}}
将此结果进行rlp 编码,作为 sendRawTransaction 的参数:
{"f8e6a06a155e25b6b72e19e700e26a8a5d8fd66348a49bb6369eb6afcbef41446171a6f8c3f8c180b8bef8bce7e6e3a0b11a08725aa65de6f60f4739a516470ef68398d5d0042d503786c521c86b19cb80808080f891f846870e35fa931a00009976a91405bb920e316e46f9b639ae3a9f5a130d2cf6386188ace39000000000000000000000000000000000900000000000000000000000000000000080f84788014a670164e6ec009976a91456be6e395cfa5aecf66338814560e95f23ff4dd188ace3900000000000000000000000000000000090000000000000000000000000000000008080"],"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