layout | permalink |
---|---|
post |
/how-to-make-transaction-post/ |
Transaction submit to SEBAK main net and write in blockchain when after transaction confirmed . Both balance , Source account and target account, will be changed by approved transaction. Each of trasnactions iclude below properties.
- source account
- fee
- sequence id
- list of operations
Below informations explain to How to make transaction in SEBK with sebak-pyutil
Before creating new transaction, you should check these,
- 'secret seed' of source account
- 'public address' of target account
- 'network id'
You can simply check 'network id' from SEBAK node information. If the address of your sebak node is 'https://testnet-sebak.blockchainos.org',
$ curl -v https://testnet-sebak.blockchainos.org
...
"policy": {
"network-id": "sebak-test-network",
"initial-balance": "10000000000000000000",
"base-reserve": "1000000",
...
The value of "network-id"
, sebak-test-network
is the 'network id'.
For the nature of transaction of SEBAK, one Transction
can have multple Operation
s. Operation
is the base unit of operating accounts like creating new account and payment. Currently SEBAK supports various kind of operations, but most of users will use CreateAccount
and Payment
operations.
>>> from sebak.operation import create_account, payment
>>> target = 'GB3AOQD2M5AKMNWUP2HFCVQYFQNGTAFTJ24BHZ56ONSGGOXMG3EBO6OE'
>>> amount = '100'
>>> payment_operation = payment(target, amount)
>>> target = 'GD54SAKFHJ2QSBLEHZIQV3UWQ42OD6VQ6HKF6TN6F72US3AUQNDSONEV'
>>> amount = '1000000'
>>> create_account_operation = create_account(target, amount)
amount
must bestr
.- the unit of
amount
must beGON
,1BOS
is10000000GON
. target
should be valid address of keypair.
At this time, you can up to 100
operations in one transaction. This number can be adjusted. This limit also can be checked by node information.
>>> from sebak.transaction import Transaction
>>> operations = (payment_operation, create_account_operation)
>>> sequence_id = 1
>>> tx = Transaction(sequence_id, operations)
sequence_id
is the last state of account. It will be varied when your account state is changed, so you should check the latestsequence_id
from network. You can get the laetstsequence_id
from https://bosnet.github.io/sebak/api/#accounts-account-details-get .
You must sign you transaction instance before sengding transaction.
>>> from sebak import keypair
>>> source = 'SDJLIFJ3PMT22C2IZAR4PY2JKTGPTACPX2NMT5NPERC2SWRWUE4HWOEE'
>>> kp = keypair.from_seed(source)
>>> network_id = b'sebak-test-network'
>>> tx.sign(kp, network_id)
>>> tx.hash
'8PqQDCrvewu6JvGqHgyagESwjQ7zAeTKGJHeJmVi2X4n'
>>> tx.signature
'nU46BuF6f1PUUCoHoy3EXMxdibvRC6ZYyzLPsr4aNJYJnDDvSdcn52Qf9CGy5R9UbkMgW6mdKGwrHNvd3oCoRsp'
kp
must be generated from yoursecret-seed
, not `public address'.network_id
must bebytes
.
If you successfully sign your transaction, you can serialize your transaction instance to 'json', or 'dict',
>>> json_string = tx.to_json()
>>> print(json_string)
{
"H": {
"version": "1",
"created": "2018-11-17 14:21:58-09.00",
"signature": "nU46BuF6f1PUUCoHoy3EXMxdibvRC6ZYyzLPsr4aNJYJnDDvSdcn52Qf9CGy5R9UbkMgW6mdKGwrHNvd3oCoRsp"
},
"B": {
"source": "GAG5EESGOZIHTKK5N2NBHX25EWRC3S3TWZT7RMCSBX65A3KTJKILQKCF",
"fee": "20000",
"sequence_id": 1,
"operations": [
{
"H": {
"type": "payment"
},
"B": {
"amount": "100",
"target": "GB3AOQD2M5AKMNWUP2HFCVQYFQNGTAFTJ24BHZ56ONSGGOXMG3EBO6OE"
}
},
{
"H": {
"type": "create-account"
},
"B": {
"amount": "1000000",
"target": "GD54SAKFHJ2QSBLEHZIQV3UWQ42OD6VQ6HKF6TN6F72US3AUQNDSONEV",
"linked": ""
}
}
]
}
}
>>> d = tx.to_dict()
from pprint import pprint
>>> pprint(d)
{ 'B': { 'fee': '20000',
'operations': [ { 'B': { 'amount': '100',
'target': 'GB3AOQD2M5AKMNWUP2HFCVQYFQNGTAFTJ24BHZ56ONSGGOXMG3EBO6OE'},
'H': {'type': 'payment'}},
{ 'B': { 'amount': '1000000',
'linked': '',
'target': 'GD54SAKFHJ2QSBLEHZIQV3UWQ42OD6VQ6HKF6TN6F72US3AUQNDSONEV'},
'H': {'type': 'create-account'}}],
'sequence_id': 1,
'source': 'GAG5EESGOZIHTKK5N2NBHX25EWRC3S3TWZT7RMCSBX65A3KTJKILQKCF'},
'H': { 'created': '2018-11-17 14:21:58-09.00',
'signature': 'nU46BuF6f1PUUCoHoy3EXMxdibvRC6ZYyzLPsr4aNJYJnDDvSdcn52Qf9CGy5R9UbkMgW6mdKGwrHNvd3oCoRsp',
'version': '1'}}
So you are ready to submit transactons, you can just post your json to SEBAK node.
$ curl -v \
-XPOST \
-H 'Content-Type: application/json' \
-d @your-transaction.json \
https://testnet-sebak.blockchainos.org/api/v1/transactions
...
> POST /api/v1/transactions HTTP/2
> Host: testnet-sebak.blockchainos.org
> User-Agent: curl/7.62.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 749
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
* We are completely uploaded and fine
< HTTP/2 200
< content-type: application/problem+json
< x-ratelimit-limit: 100
< x-ratelimit-remaining: 98
< x-ratelimit-reset: 1542432619
< date: Sat, 17 Nov 2018 05:30:08 GMT
< content-length: 101
< via: 1.1 google
< alt-svc: clear
<
* Connection #0 to host testnet-sebak.blockchainos.org left intact
...
The API of sending transaction, please see https://bosnet.github.io/sebak/api/#trasactions-transactions-post .
- In SEBAK, like other cryptocurrencies there is 'fee'. 'fee' is multiplied by the number of operations in one transaction.
target
address must new account, this means, it does not exist in the SEBAK network. You can check the account status thru account API of SEBAK. Please see https://bosnet.github.io/sebak/api/#accounts-account-details-get .amount
for creating account must be bigger than base reserve, you can check the amount from SEBAK node information like 'network-id'
target
address must exist in network.