ofc虚拟币转账脚本

本地转账脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
echo ">>默认gas:21000(0x5208)<<"
echo ">>默认gasPrice:5E12(0x48c27395000)<<"
function validateAddress(){
local addr=$1
local length=${#addr}
if [ x"$addr" = x ];then
return 0
elif [ $length -ne 52 ]; then
echo $1"位数<52"
return 0
fi
return 1
}
function transfer(){
local unlock=$(curl -X POST --data '{"jsonrpc":"2.0","method":"ofbank_unlockW","params":["'$2'","'$5'"],"id":1}' $1)
echo "解锁账户结果:" $unlock
local result=$(curl -X POST --data '{"jsonrpc":"2.0","method":"ofbank_sendTrans","params":[{"from":"'$2'","to":"'$3'","value":"'$4'","gas":"0x5208","gasPrice":"0x48c27395000"}],"id":1}' $1)
echo $result
}
read -p "输入server rpc:" rpc_server
fromIsSafe=0
toIsSafe=0
while ([ $fromIsSafe == 0 ] || [ $toIsSafe == 0 ])
do
read -p "From address:" from_address
read -p "To address:" to_address
validateAddress $from_address
fromIsSafe=$?
validateAddress $to_address
toIsSafe=$?
done

read -p "value:" value
read -p "salt:" salt

echo "输入的RPC:"$rpc_server
echo "转账地址:"$from_address
echo "转入地址:"$to_address
echo "转入金额:"$value
read -r -p "请确认继续这笔交易?[Y/n] " confirm
case $confirm in
[yY][eE][sS]|[yY])
transfer $rpc_server $from_address $to_address $value $salt
;;

[nN][oO]|[nN])
exit 1
;;

*)
echo "终止操作"
exit 1
;;
esac
坚持技术分享,您的支持将鼓励我继续创作!