0.0.1-rc8 • Published 3 years ago
@kuzirashi/test-provider v0.0.1-rc8
(THIS BRANCH IS ONLY FOR TEST!) Polyjuice Http Provider
a godwoken-compatible http provider for web3.js.
now you can call your smart-contract on godwoken with metamask and eth address.
init web3
Before:
import Web3 from 'web3';
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8024'));
Now:
import Web3 from 'web3';
import PolyjuiceHttpProvider from './PolyjuiceHttpProvider';
var web3 = new Web3(new PolyjuiceHttpProvider('http://localhost:8024', GodwokenOption, ['your abi items array']));
for GodwokenOption
: see here.
init contract instance
Before:
import Web3 from 'web3';
var provider = new Web3.providers.HttpProvider('http://localhost:8024');
var web3 = new Web3(provider);
var contract = web3.eth.Contract(abi, contract_address);
Now:
import Web3 from 'web3';
import PolyjuiceHttpProvider from './PolyjuiceHttpProvider';
var provider = new PolyjuiceHttpProvider('http://localhost:8024', GodwokenOption, ['your abi items array']);
var web3 = new Web3(provider);
var contract = web3.eth.Contract(abi, contract_address);
basically, PolyjuiceHttpProvider is just a extended class of [web3-providers-http]
getting started
git clone https://github.com/RetricSu/polyjuice-providers-http.git
cd polyjuice-providers-http
yarn
build:
yarn build
node version:
/lib/index.node.js
usage:
const PolyjuiceHttpProvider = require('./PolyjuiceHttpProvider');
web version:
/lib/index.js
useage:
import PolyjuiceHttpProvider from './PolyjuiceHttpProvider';
browser version:
/build/browser/PolyjuiceHttpProvider.js
usage:
<script src="/path/to/PolyjuiceHttpProvider.js"></script>
hardhat
hardhat is using ethers
instead of web3.js
, you can find ethers-compatibale JsonRpcProvider
and WalletSigner
in /lib/hardhat/providers
usage:
const { PolyjuiceJsonRpcProvider } = require('PolyjuiceHttpProvider/lib/hardhat/providers');
const PolyjuiceWallet = require('PolyjuiceHttpProvider/lib/hardhat/wallet-signer');
before you can run test and an minimal example, create an .test.env file with some godwoken-polyjuice config.
cat > ./test.env <<EOF
WEB3_JSON_RPC=<godwoken web3 rpc>
ROLLUP_TYPE_HASH=<godwoken rollup type hash>
ETH_ACCOUNT_LOCK_CODE_HASH=<eth account lock code hash>
EXAMPLE_CONTRACT_ADDRESS=<an example test contract deployed address>
PRIVATE_KEY=<your eth test private key, do not use in production>
test
yarn test
start a minimal dapp example
yarn example