Created
October 21, 2019 19:40
-
-
Save luyzdeleon/fe61262d4475219227e067964d87f6ab to your computer and use it in GitHub Desktop.
Pocket + Terminal integration sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TerminalHttpProvider = require('@terminal-packages/sdk').TerminalHttpProvider; | |
const PocketProvider = require('pocket-js-web3-provider'); | |
const Web3 = require('web3'); | |
var pocketProvider = new PocketProvider("ETH", "1", "<Your Pocket Dev ID here>", { | |
// This is just a stub, only gets called when eth_sendRawTransaction or eth_sendTransaction are called. | |
transactionSigner: { | |
/* | |
Callback method called to determine wether or not the | |
TransactionSigner supports signing transactions for the given addr */ | |
hasAddress: async function (address) { | |
return false; | |
}, | |
/* | |
Callback method called to generate a serialized signed format | |
of the given a Web3.js transaction object | |
(https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction) | |
*/ | |
signTransaction: async function (txParams) { | |
console.log(txParams); | |
return "0x"; | |
} | |
}, | |
maxNodes: 3, | |
requestTimeOut: 20000, | |
sslOnly: false | |
}); | |
const web3 = new Web3( | |
new TerminalHttpProvider({ | |
host: "test", | |
apiKey: '<Your Terminal Account API Key>', | |
// projectId is not required to log but we suggest | |
// using it for the best experience | |
projectId: '<Your Terminal Project ID>', | |
// source can be any static or dynamic string as well | |
source: "POCKET", // One cool thing would be to have Pocket added to the SourceType enum. | |
customHttpProvider: pocketProvider, | |
web3Version: "1" | |
}) | |
); | |
for(var i = 0; i < 10; i++) { | |
web3.eth.getBalance("<Introduce any Ethereum mainnet address here>").then(function (balance) { | |
console.log(balance); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, just some hints here, you don’t need “host” defined with a custom provider and also you can use the enum Web3Versions which is exported in the sdk to define that Web3Versions.one.
I will also add you to our whitelisted sources enum 👍 this will be in the next sdk release tomorrow time.