Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change PocketProvider from MVP to testnet/mainnet ready #60

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

nymd
Copy link

@nymd nymd commented Jun 26, 2020

As Pocket Network prepares for launch, this PR will update the Portis PocketProvider to be mainnet ready.

Removed:
pocket-js-core and the PocketDevID

Replaced with:
pocket-web3-provider and pass-in variables to enable a Pocket Application Authentication Token

Sample usage:

<html>
	<head>
		<script src="./index.js"></script>
		<script src="node_modules/@pokt-network/web3-provider/dist/web.js"></script>
		<script src="node_modules/web3/dist/web3.min.js"></script>
		<script type="text/javascript">
			async function TestProvider() {
				const dispatchers = [new URL("https://node1.testnet.pokt.network:443")];
				const pocket = new PocketWeb3Provider.Pocket(dispatchers);
				const PocketAAT = PocketWeb3Provider.PocketAAT;
				const pocketPrivateKey = '38310b6dcb2c66a1c1d8e29a13f8ca7604dbdaa20b1dca3e3bfd0bc73a16661e87d0cfcca00db63702829f15cb45d3139de5578c926d4118d5093bd237962d2f'
				const pocketPublicKey = '87d0cfcca00db63702829f15cb45d3139de5578c926d4118d5093bd237962d2f'
				const pocketAddress = '144faa3251f326840d9daf8cbd9c63e263da6329'
				const pocketPassphrase = 'yo'
				const clientPrivateKey = '22c6cf663e9932bb691b1432c9d8dae906d2609ff85e08792fceb10b2a0e9feffa457de4393c386ae3c4dde8703bf25080cc9909d98b55fbc7d6f2ca057450a2'
				const clientPublicKey = 'fa457de4393c386ae3c4dde8703bf25080cc9909d98b55fbc7d6f2ca057450a2'
				const clientAddress = '2d089de210afd5176b46b38b7c5f4b1ce63622bf'
				const blockchain = '0022'

				const clientAccount = await pocket.keybase.createAccount(pocketPassphrase);
				const unlockAcct =  await pocket.keybase.unlockAccount(clientAccount.addressHex,pocketPassphrase,0);

				const isUnlocked = await pocket.keybase.isUnlocked(clientAccount.addressHex); 

				const pocketAAT = await PocketAAT.from("0.0.1",  clientAccount.publicKey.toString("hex"), pocketPublicKey, pocketPrivateKey);

				const portisInstance = new Portis('e3203321-c265-41d9-a638-e8eb33b49122', {
					nodeUrl: 'https://node1.testnet.pokt.network:443',
					nodeProtocol: 'pocket',
					chainId: blockchain
				}, {
					pocket: pocket,
					pocketAAT: pocketAAT,
					accounts: ["0x2a14D313F58bA0bd4e8Fa282082D11DA24b1DaA3".toUpperCase(), "0xF0BE394Fb2Def90824D11C7Ea189E75a8e868fA6".toUpperCase()],
					privateKeys: ["F3D7A8A15A23E2689511A7505D389960D007925119DEC14892466F0EDB0876B8"]
					
				});
				
				const web3 = new Web3(portisInstance.provider);

				const txBal = await web3.eth.getBalance("0x2a14d313f58ba0bd4e8fa282082d11da24b1daa3")
				console.log(txBal);
				
				const ethRelayData = '{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendRawTransaction\",\"params\":["0xf861328082520894f0be394fb2def90824d11c7ea189e75a8e868fa6822710802ca05baeac4f6e701e488c4de40d5764bcc1212e2fc559aab1e1a190e56678ce14e1a0272e4e95a669c70244e339c012e858d578658a264060968f713c82ba59943f66"],\"id\":67}'
				
				// to send tokens in a relay
				const ethRelayResponse = await pocket.sendRelay(ethRelayData, blockchain, pocketAAT);
				console.log(ethRelayResponse)
				// only return the payload w/ the result
				const parsedPayload = JSON.parse(ethRelayResponse.payload);
				console.log(parsedPayload)
			}
			TestProvider()
		</script>
	</head>
	<body>
		<pre>Test</pre>
	</body>
</html>

Create a Pocket account:
Pocket Wallet

Obtaining testnet tokens:
Pocket Faucet

Generating a PocketAAT:
AAT Documentation

@nymd nymd marked this pull request as ready for review June 26, 2020 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants