Skip to content

Instantly share code, notes, and snippets.

@harsh-98
Last active June 25, 2020 01:44
Show Gist options
  • Save harsh-98/ceaf6fa92e95269a532916bcdf339c72 to your computer and use it in GitHub Desktop.
Save harsh-98/ceaf6fa92e95269a532916bcdf339c72 to your computer and use it in GitHub Desktop.

For running this script which uses REST endpoints of ava. I am using the default network id , which I took as 12.

go run main/* --public-ip=127.0.0.1 --snow-sample-size=1 --snow-quorum-size=1 --staking-tls-enabled=false --network-id=12 --api-admin-enabled=true

And then ./ava.sh. This script is using default network id so the funds are there in ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN

Install jq for running the below script.

#!/bin/sh
set -e
# set -x
OKGREEN='\033[92m'
FAIL='\033[91m'
WARN='\033[93m'
INFO='\033[94m'
ENDC='\033[0m'
function PassPrint() {
echo "$OKGREEN $@ $ENDC"
}
function InfoPrint() {
echo "$INFO $@ $ENDC"
}
function WarnPrint() {
echo "$WARN $@ $ENDC"
}
WarnPrint Phase 1 creating user and address on x chain
PassPrint Creating user
USERNAME=xx
PASSWORD=#Rest123sample
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/keystore/rest/user/create -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\"}"
PassPrint listing username
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/keystore/rest/user/list
InfoPrint checking aliases
PassPrint creating account with /ext/bc/X/rest/address/create
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/X/rest/address/create -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\"}"
PassPrint creating account with /ext/X/rest/address/create
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/X/rest/address/create -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\"}"
PassPrint creating account with /ext/avm/rest/address/create
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/avm/rest/address/create -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\"}"
PassPrint creating account with /ext/bc/avm/rest/address/create
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/avm/rest/address/create -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\"}"
PassPrint listing address
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/X/rest/address/list -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\"}"
PassPrint loading private key ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/X/rest/key/import -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\",\"privateKey\": \"ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN\"}"
PassPrint Fetch asset info /ext/X/asset/description
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/X/rest/asset/description -d '{"assetID": "AVA"}'
PassPrint Checking balance of the loaded key
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/X/rest/balance -d '{"assetID": "AVA", "address": "X-6Y3kysjF9jnHnYkdS9yGAuoHyae2eNmeV"}'
PassPrint Checking all asset balance of loaded key
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/X/rest/balance/all -d '{"address": "X-6Y3kysjF9jnHnYkdS9yGAuoHyae2eNmeV"}'
WarnPrint Phase 2 creating address on P chain
PassPrint creating address
Paddress=`curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/P/rest/account/create -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\"}" |jq .address`
echo $Paddress
PassPrint export ava from x chain
txid=`curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/X/rest/ava/export -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\", \"to\": $Paddress , \"amount\": 20000 }"| jq .txID`
echo tx id $txid
sleep 3
PassPrint import ava in p chain
tx=`curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/P/rest/ava/import -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\", \"to\": $Paddress , \"payerNonce\": 1 }"| jq .tx`
echo "Import ava data $tx"
PassPrint issue tx
issuetx=`curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/P/rest/tx/issue -d "{\"tx\": $tx}" | jq .txID`
echo "TX issue: $issuetx"
PassPrint checking tx status
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/avm/rest/tx/status -d "{\"txID\": $issuetx}"
PassPrint fetching account details on p chain
curl -XPOST -H 'content-type:application/json' 127.0.0.1:9650/ext/P/rest/account/get -d "{\"address\": $Paddress}"
WarnPrint Phase 3 staking and Validating
nodeID=`curl -XPOST -H 'content-type:application/json' 127.0.0.1:9650/ext/admin/rest/node/id | jq .nodeID`
echo "Node if $nodeID"
PassPrint generate unsigned tx
unsignedTx=`curl -XPOST -H 'content-type:application/json' 127.0.0.1:9650/ext/P/rest/validator/add/subnet/default -d "{ \"id\": $nodeID, \"startTime\": 1692000000 , \"endTime\":1692265599, \"delegationFeeRate\":0, \"destination\": $Paddress, \"stakeAmount\":20000, \"payerNonce\":2}" | jq .unsignedTx`
echo "unsignedTx : $unsignedTx"
PassPrint stake signed tx
staketx=`curl -XPOST -H 'content-type:application/json' 127.0.0.1:9650/ext/P/rest/sign -d "{\"username\": \"$USERNAME\",\"password\": \"$PASSWORD\", \"signer\": $Paddress, \"tx\": $unsignedTx}" | jq .tx`
echo "signed staking tx: $staketx"
PassPrint issue tx
issuetx=`curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/P/rest/tx/issue -d "{\"tx\": $staketx}" | jq .txID`
echo $issuetx
PassPrint check tx status
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/avm/rest/tx/status -d "{\"txID\": $issuetx}"
PassPrint getting pending validators
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/P/rest/validator/pending
PassPrint getting current validators
curl -XPOST -H 'content-type:application/json;' 127.0.0.1:9650/ext/P/rest/validator/current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment