Comments (17)
Hi @MaoxinCao , did you mean signing transaction? All transactions are signed offline with SwiftyEOS. Try to make a token transfer like the README file described: Using Currency.transferCurrency
.
But some params are needed to be fetched from an eos endpoint (block prefix and/or block number).
from swiftyeos.
Hi @MaoxinCao , did you solve the problem?
from swiftyeos.
I have the same question..
from swiftyeos.
how to sign to like this:
{
"signatures": [
"SIG_K1_KdRNkKSDNFUb7gU45UZcySykeGRGp4ESzEZj4pyJwWsuDVkRcHjREViyF1qQmci8981zib3zGebD64YAXgsNQkzAa7jftK"
],
"compression": "none",
"packed_context_free_data": "",
"packed_trx": "a4f38c5b390282247889000000000100a6823403ea3055000000572d3ccdcd01104260d33d364dc300000000a8ed323241104260d33d364dc3204260d33d364dc31027000000000000044a554e474c45002054657374206279207368616e676a696e67202e2020323031383039303330303200"
}
from swiftyeos.
@zhenghongchuan it's a signed transaction, right?
I'll make it clear by posting an example. I have a transaction to make, it's a token-transfer transaction:
- Account
agoodaccount
wants to transfer 1 EOS to accountgq3dinztgage
. The first step is to have a transaction action like this:
{
"account":"eosio.token",
"name":"transfer",
"authorization":[
{
"actor":"agoodaccount",
"permission":"active"
}
],
"data":{
"from":"agoodaccount",
"to":"gq3dinztgage",
"quantity":"1.0000 EOS"
}
}
- With the raw transaction action, the next step is to pack it, by converting this key-value based structure(json) to hex representation with the contract's ABI. After packing, the whole trasaction will be something like you've posted:
a4f38c5b390282247889000000000100a6823403ea3055000000572d3ccdcd01104260d33d364dc300000000a8ed323241104260d33d364dc3204260d33d364dc31027000000000000044a554e474c45002054657374206279207368616e676a696e67202e2020323031383039303330303200
(It's the string I just copied from your code.
- After that, the final thing is signing. Using EOS's standard signing method, and your private key, to sign this hex string to a signature:
SIG_K1_KdRNkKSDNFUb7gU45UZcySykeGRGp4ESzEZj4pyJwWsuDVkRcHjREViyF1qQmci8981zib3zGebD64YAXgsNQkzAa7jftK
- Then we got the result:
{
"signatures": [
"SIG_K1_KdRNkKSDNFUb7gU45UZcySykeGRGp4ESzEZj4pyJwWsuDVkRcHjREViyF1qQmci8981zib3zGebD64YAXgsNQkzAa7jftK"
],
"compression": "none",
"packed_context_free_data": "",
"packed_trx": "a4f38c5b390282247889000000000100a6823403ea3055000000572d3ccdcd01104260d33d364dc300000000a8ed323241104260d33d364dc3204260d33d364dc31027000000000000044a554e474c45002054657374206279207368616e676a696e67202e2020323031383039303330303200"
}
The packed transaction, signature, no compression by default, and no context free data. It's ready. Then we can ship this signed transaction
http body to one of the EOS RPC endpoint using RPC push_transaction
API:
POST http://yourdomainandport/v1/chain/push_transaction
That's all.
With SwiftyEOS, it's much easier to make it happen because you don't need to care about the step 2 and step 3:
var transfer = Transfer()
transfer.from = "agoodaccount"
transfer.to = "gq3dinztgage"
transfer.quantity = "1.0000 EOS"
transfer.memo = "eureka"
Currency.transferCurrency(transfer: transfer, privateKey: importedPk!, completion: { (result, error) in
if error != nil {
if (error! as NSError).code == RPCErrorResponse.ErrorCode {
print("\(((error! as NSError).userInfo[RPCErrorResponse.ErrorKey] as! RPCErrorResponse).errorDescription())")
} else {
print("other error: \(String(describing: error?.localizedDescription))")
}
} else {
print("Ok. Txid: \(result!.transactionId)")
}
})
You can also find the code snippet in the project readme file. It's written in Swift but could be used with Objective-C, too.
from swiftyeos.
The crypto signing progress itself is offline. But you can't make the whole process totally offline, because we need to fetch some chain block data and put it together with our transaction, to make a signature.
BTW it's safe to get the abi_json data from an RPC endpoint. Though we could make this step "offline" for the contract we know, it's dangerous because the contract may change anytime.
from swiftyeos.
@croath Thanks Reply.
I am currently doing is multi-signature, so I need to sign offline on multiple terminals. But the signature in SwiftyEOS seems to be put into the transaction.
from swiftyeos.
@croath How can I get the privateKey in my currentAccount?
from swiftyeos.
@MaoxinCao Sorry that multi-sig is not supported yet.
But I'm sure I could provide a low-level method just for calculating signatures for a given context. Will be ready in next versions.
from swiftyeos.
@zhenghongchuan With currentAccount
there's no need to take the privateKey, just use SELocalAccount
's pushTransaction
. Unlock with a password is a safer way in iOS.
from swiftyeos.
@croath The point is that can I get the sign json by my currentAccount, and how to do it. And can I create wallet by a account name? Thanks.
from swiftyeos.
let abi = try AbiJson(code: "currency", action: "transfer", json: jsonString)
EOSRPC.sharedInstance.chainInfo { (chainInfo, error) in
EOSRPC.sharedInstance.getBlock(blockNumOrId: "\(chainInfo!.lastIrreversibleBlockNum)" as AnyObject, completion: { (blockInfo, error) in
EOSRPC.sharedInstance.abiJsonToBin(abi: abi, completion: { (bin, error) in
})
})
}
How to create AbiJson object? I wrote this, bin is always nil.
from swiftyeos.
-
Yes and no. There's way you can get the final signed json yourself, read the source file and find the way I do in Transaction.swift.
-
No. A wallet can not be created by just a name. A private key associated with that account is needed.
from swiftyeos.
@MaoxinCao Then what the error
is?
And are you sure the code you wanna use is currency
?
from swiftyeos.
@croath Thank you!
from swiftyeos.
@croath It's work...
let abi = try AbiJson(code: "eosio.token", action: "transfer", json: jsonString)
from swiftyeos.
🎉
from swiftyeos.
Related Issues (20)
- AnyCodable HOT 1
- 如何使用助记词 HOT 10
- Transactions signing crash HOT 2
- 相关咨询
- Archive compile error HOT 2
- How to create KeyPair by Mnemonic HOT 1
- 怎么通过助记词生成的种子Seed,生成私钥和公钥呢? HOT 1
- Pod or Carthage support HOT 2
- Remote account creation HOT 1
- README.md HOT 1
- 购买资源接口报500,接口参数貌似错了
- AnyCodable HOT 5
- Availability of Currency transfer in objective c
- 在OC中无法使用Currency.transferCurrency方法,有没有什么办法可以解决
- crash when i import by mnemonic HOT 1
- 能不能加上消息签名 HOT 1
- is this project dead? or still working? HOT 2
- "The operation couldn’t be completed. (SwiftyEOSErrorDomain error 80000.)" HOT 1
- No method found in BigInt.swift file HOT 4
- PublicKey from string
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftyeos.