Commit f00fb2a6 authored by chenqikuai's avatar chenqikuai

update

parent 4c26a6c4
require('isomorphic-fetch');
const { seed } = require('@33cn/wallet-base') const { seed } = require('@33cn/wallet-base')
const BtyBaseSdk = require('@33cn/chain33-rpc-api').default
const fetch = require('node-fetch') const fetch = require('node-fetch')
const url = 'https://mainnet.bityuan.com/api' const url = 'https://mainnet.bityuan.com/api'
...@@ -7,59 +9,87 @@ const wallet = seed.newWalletFromMnemonic('今 歇 罐 雷 巧 撒 刺 念 漏 ...@@ -7,59 +9,87 @@ const wallet = seed.newWalletFromMnemonic('今 歇 罐 雷 巧 撒 刺 念 漏
const account = wallet.newAccount('account1') const account = wallet.newAccount('account1')
fetch(url, { const chain33Rpc = new BtyBaseSdk(url)
method: 'post',
body: JSON.stringify({
"jsonrpc": "2.0", chain33Rpc.createRawTransaction({
"id": new Date().getTime(), "to": "1J36i7xcrwgZHHNLkKjTp9HuyZfv3gdYeU",
"method": "Chain33.CreateRawTransaction", "amount": 1e8,
"params": [ "fee": 0,
{ "note": "从nodejs中发起的请求",
"to": "1J36i7xcrwgZHHNLkKjTp9HuyZfv3gdYeU", "isToken": false,
"amount": 1e8, "isWithdraw": false,
"fee": 0, }).then(ret => {
"note": "从nodejs中发起的请求",
"isToken": false,
"isWithdraw": false,
}
]
})
}).then(ret => ret.json()).then(ret => {
const { result: txHex } = ret; const { result: txHex } = ret;
console.log(txHex, "show txHex"); console.log(txHex, "show txHex");
chain33Rpc.signRawTx({
fetch(url, { 'privkey': account.privateKey.toString('hex'),
method: 'post', "txHex": txHex,
body: JSON.stringify({ "expire": "300s",
"jsonrpc": "2.0", "fee": 0,
"id": new Date().getTime(), }).then(ret => {
"method": "Chain33.SignRawTx",
"params": [
{
// 'addr': signedTx,
'privkey': account.privateKey.toString('hex'),
"txHex": txHex,
"expire": "300s",
"fee": 0,
}
]
})
}).then(ret => ret.json()).then(ret => {
const { result: data } = ret; const { result: data } = ret;
console.log(data, 'show data'); console.log(data, 'show data');
chain33Rpc.sendTransaction(data).then(ret => {
fetch(url, {
method: 'post',
body: JSON.stringify({
"jsonrpc": "2.0",
"id": new Date().getTime(),
"method": "Chain33.SendTransaction",
"params": [{
"data": data,
}]
})
}).then(ret => ret.json()).then(ret => {
console.log(ret, "show final result"); console.log(ret, "show final result");
}) })
}) })
}) })
// fetch(url, {
// method: 'post',
// body: JSON.stringify({
// "jsonrpc": "2.0",
// "id": new Date().getTime(),
// "method": "Chain33.CreateRawTransaction",
// "params": [
// {
// "to": "1J36i7xcrwgZHHNLkKjTp9HuyZfv3gdYeU",
// "amount": 1e8,
// "fee": 0,
// "note": "从nodejs中发起的请求",
// "isToken": false,
// "isWithdraw": false,
// }
// ]
// })
// }).then(ret => ret.json()).then(ret => {
// const { result: txHex } = ret;
// console.log(txHex, "show txHex");
// fetch(url, {
// method: 'post',
// body: JSON.stringify({
// "jsonrpc": "2.0",
// "id": new Date().getTime(),
// "method": "Chain33.SignRawTx",
// "params": [
// {
// // 'addr': signedTx,
// 'privkey': account.privateKey.toString('hex'),
// "txHex": txHex,
// "expire": "300s",
// "fee": 0,
// }
// ]
// })
// }).then(ret => ret.json()).then(ret => {
// const { result: data } = ret;
// console.log(data, 'show data');
// fetch(url, {
// method: 'post',
// body: JSON.stringify({
// "jsonrpc": "2.0",
// "id": new Date().getTime(),
// "method": "Chain33.SendTransaction",
// "params": [{
// "data": data,
// }]
// })
// }).then(ret => ret.json()).then(ret => {
// console.log(ret, "show final result");
// })
// })
// })
...@@ -4,6 +4,14 @@ ...@@ -4,6 +4,14 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@33cn/chain33-rpc-api": {
"version": "1.5.27",
"resolved": "https://registry.npmjs.org/@33cn/chain33-rpc-api/-/chain33-rpc-api-1.5.27.tgz",
"integrity": "sha512-ctUMYa1Z/Nf3d6y9dEL0S/s/YJuNuxRPD+d2rP+r8RDjnjCpdLl0ArceRLoLmK0p67+pz0A6r2s6qMHQ+nfoIg==",
"requires": {
"json-bigint": "^0.3.0"
}
},
"@33cn/wallet-base": { "@33cn/wallet-base": {
"version": "1.0.12", "version": "1.0.12",
"resolved": "https://registry.npm.taobao.org/@33cn/wallet-base/download/@33cn/wallet-base-1.0.12.tgz", "resolved": "https://registry.npm.taobao.org/@33cn/wallet-base/download/@33cn/wallet-base-1.0.12.tgz",
...@@ -110,6 +118,11 @@ ...@@ -110,6 +118,11 @@
"resolved": "https://registry.npm.taobao.org/bech32/download/bech32-1.1.4.tgz", "resolved": "https://registry.npm.taobao.org/bech32/download/bech32-1.1.4.tgz",
"integrity": "sha1-44yfN78Xm46xauOncrQMNW1IMuk=" "integrity": "sha1-44yfN78Xm46xauOncrQMNW1IMuk="
}, },
"bignumber.js": {
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.1.tgz",
"integrity": "sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA=="
},
"bindings": { "bindings": {
"version": "1.5.0", "version": "1.5.0",
"resolved": "https://registry.npm.taobao.org/bindings/download/bindings-1.5.0.tgz", "resolved": "https://registry.npm.taobao.org/bindings/download/bindings-1.5.0.tgz",
...@@ -257,6 +270,11 @@ ...@@ -257,6 +270,11 @@
"minimalistic-crypto-utils": "^1.0.1" "minimalistic-crypto-utils": "^1.0.1"
} }
}, },
"es6-promise": {
"version": "4.2.8",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz",
"integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w=="
},
"escape-latex": { "escape-latex": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npm.taobao.org/escape-latex/download/escape-latex-1.2.0.tgz", "resolved": "https://registry.npm.taobao.org/escape-latex/download/escape-latex-1.2.0.tgz",
...@@ -326,6 +344,15 @@ ...@@ -326,6 +344,15 @@
"resolved": "https://registry.npm.taobao.org/inherits/download/inherits-2.0.4.tgz", "resolved": "https://registry.npm.taobao.org/inherits/download/inherits-2.0.4.tgz",
"integrity": "sha1-D6LGT5MpF8NDOg3tVTY6rjdBa3w=" "integrity": "sha1-D6LGT5MpF8NDOg3tVTY6rjdBa3w="
}, },
"isomorphic-fetch": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz",
"integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==",
"requires": {
"node-fetch": "^2.6.1",
"whatwg-fetch": "^3.4.1"
}
},
"javascript-natural-sort": { "javascript-natural-sort": {
"version": "0.7.1", "version": "0.7.1",
"resolved": "https://registry.npm.taobao.org/javascript-natural-sort/download/javascript-natural-sort-0.7.1.tgz", "resolved": "https://registry.npm.taobao.org/javascript-natural-sort/download/javascript-natural-sort-0.7.1.tgz",
...@@ -336,6 +363,14 @@ ...@@ -336,6 +363,14 @@
"resolved": "https://registry.npm.taobao.org/js-sha256/download/js-sha256-0.9.0.tgz", "resolved": "https://registry.npm.taobao.org/js-sha256/download/js-sha256-0.9.0.tgz",
"integrity": "sha1-C4msFmWD6R75EjZEvTxTNM6dCWY=" "integrity": "sha1-C4msFmWD6R75EjZEvTxTNM6dCWY="
}, },
"json-bigint": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-0.3.1.tgz",
"integrity": "sha512-DGWnSzmusIreWlEupsUelHrhwmPPE+FiQvg+drKfk2p+bdEYa5mp4PJ8JsCWqae0M2jQNb0HPvnwvf1qOTThzQ==",
"requires": {
"bignumber.js": "^9.0.0"
}
},
"long": { "long": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/long/download/long-4.0.0.tgz", "resolved": "https://registry.npm.taobao.org/long/download/long-4.0.0.tgz",
...@@ -554,6 +589,11 @@ ...@@ -554,6 +589,11 @@
"safe-buffer": "^5.1.1" "safe-buffer": "^5.1.1"
} }
}, },
"whatwg-fetch": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.1.tgz",
"integrity": "sha512-IEmN/ZfmMw6G1hgZpVd0LuZXOQDisrMOZrzYd5x3RAK4bMPlJohKUZWZ9t/QsTvH0dV9TbPDcc2OSuIDcihnHA=="
},
"wif": { "wif": {
"version": "2.0.6", "version": "2.0.6",
"resolved": "https://registry.npm.taobao.org/wif/download/wif-2.0.6.tgz", "resolved": "https://registry.npm.taobao.org/wif/download/wif-2.0.6.tgz",
......
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
"license": "ISC", "license": "ISC",
"devDependencies": {}, "devDependencies": {},
"dependencies": { "dependencies": {
"@33cn/chain33-rpc-api": "^1.5.27",
"@33cn/wallet-base": "^1.0.12", "@33cn/wallet-base": "^1.0.12",
"es6-promise": "^4.2.8",
"isomorphic-fetch": "^3.0.0",
"node-fetch": "^2.6.1" "node-fetch": "^2.6.1"
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment