Comments (6)
@nitika-goel I have successfully signed with web3-provider-engine and @0xproject/subproviders
here is snippet code for kovan infura(with out meta mask) , hope it helps
// import lib
var PrivateKeyWalletSubprovider = require('@0xproject/subproviders').PrivateKeyWalletSubprovider
var ProviderEngine = require('web3-provider-engine')
var RpcSubprovider = require('web3-provider-engine/subproviders/rpc.js')
var Web3Wrapper = require('@0xproject/web3-wrapper').Web3Wrapper
// usage
engine = new ProviderEngine()
engine.addProvider(new PrivateKeyWalletSubprovider(mainAccount.privateKey))
engine.addProvider(new RpcSubprovider({ rpcUrl: NET_WORK_INFURA }))
engine.start()
configs = {
networkId: 42
}
web3Wrapper = new Web3Wrapper(engine)
zeroEx = new ZeroEx(engine, configs)
now sign as normal.
from 0x-monorepo.
@nitika-goel, you cannot simply use new Web3.providers.HttpProvider(KOVAN_ENDPOINT)
as your provider since the infura node does not have your Ethereum address on file. You need to use providerEngine to create a provider that forwards requests specific to your accounts to a signer you can use, and all other requests to the Infura node. An example of such a subprovider can be found here.
To get started though, I would use TestRPC since we have an article on how to get started with it.
from 0x-monorepo.
Thanks @fabioberger . I did try using the providerengine but somehow the code breaks whenever I access any of the ZeroEx methods.
I am successfully able to create an order and sign it through metamask but I do not intend to do it that way as I need the entire process to be automated without the signer popup. Also, I need to integrate with this with a project running on Kovan and hence do not intend to use testrpc.
Following is the code I am using. It breaks after printing the nulladdress. I might be missing something really small. Could you please help me with it.
const Web3 = require('web3');
const Accounts=require('web3-eth-accounts');
const ZeroEx = require('0x.js').ZeroEx;
const BigNumber = require('bignumber.js');
const lightwallet= require('eth-lightwallet');
const Transaction = require('ethereumjs-tx');
const ProviderEngine = require("web3-provider-engine");
const Web3Subprovider = require("web3-provider-engine/subproviders/web3.js");
const HookedWalletProvider = require('web3-provider-engine/subproviders/hooked-wallet.js');
const CacheSubprovider = require('web3-provider-engine/subproviders/cache.js');
const FixtureSubprovider = require('web3-provider-engine/subproviders/fixture.js');
const FilterSubprovider = require('web3-provider-engine/subproviders/filters.js');
const VmSubprovider = require('web3-provider-engine/subproviders/vm.js');
const HookedWalletSubprovider = require("hooked-web3-provider");
const NonceSubprovider = require('web3-provider-engine/subproviders/nonce-tracker.js');
const RpcSubprovider = require('web3-provider-engine/subproviders/rpc.js');
const injectMetrics = require('web3-provider-engine/test/util/inject-metrics');
const KOVAN_ENDPOINT='https://kovan.infura.io/';
(async () => {
var engine=new ProviderEngine();
var web3=new Web3(engine);
// console.log(logAcc.address);
engine.addProvider(new FixtureSubprovider({
web3_clientVersion: 'ProviderEngine/v0.0.0/javascript',
net_listening: true,
eth_hashrate: '0x00',
eth_mining: false,
eth_syncing: true
}));
engine.addProvider(new CacheSubprovider());
// filters
engine.addProvider(new FilterSubprovider());
// pending nonce
engine.addProvider(new NonceSubprovider());
// vm
engine.addProvider(new VmSubprovider());
var providerA = injectMetrics(new HookedWalletProvider({
getAccounts: function(cb){
cb(null, ["0x7f4d8f26d33FDF092f713979FEc2753F9f14C331"])
},
signTransaction: function(txParams, cb){
var tx = new Transaction(txParams)
tx.sign(privateKey)
var rawTx = '0x'+tx.serialize().toString('hex')
cb(null, rawTx)
},
}));
engine.addProvider(providerA);
engine.addProvider(new RpcSubprovider({
rpcUrl: 'https://kovan.infura.io/',
}))
// log new blocks
engine.on('block', function(block){
console.log('================================')
console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
console.log('================================')
})
// network connectivity error
engine.on('error', function(err){
// report connectivity errors
console.error(err.stack)
})
// start polling for blocks
engine.start();
var zeroEx = new ZeroEx(web3.currentProvider);
// Number of decimals to use (for ETH and ZRX)
const DECIMALS = 18;
// Addresses
const NULL_ADDRESS = ZeroEx.NULL_ADDRESS;
console.log("Null address is "+NULL_ADDRESS);
const WETH_ADDRESS = await zeroEx.etherToken.getContractAddressAsync();
console.log("ETH token address is "+ WETH_ADDRESS); // The wrapped ETH token contract
const ZRX_ADDRESS = await zeroEx.exchange.getZRXTokenAddressAsync();
console.log("ZeroEx Address is "+ ZRX_ADDRESS) // The ZRX token contract
const EXCHANGE_ADDRESS = await zeroEx.exchange.getContractAddressAsync(); // The Exchange.sol address (0x exchange smart contract)
console.log("Exchange address is "+ EXCHANGE_ADDRESS);
// console.log("WEB get accounts " +web3.eth.getAccounts());
// // list of accounts
var account = await zeroEx.getAvailableAddressesAsync();
console.log(account);
})().catch(console.log);
from 0x-monorepo.
What's the error message?
from 0x-monorepo.
There is no error message. It just breaks the execution.
from 0x-monorepo.
Breaks or hangs? If it is hanging, that is because of web3/web3.js#844. The solution is to import 0x.js
and anything else that has web3
as a dependency after importing all ProviderEngine packages.
from 0x-monorepo.
Related Issues (20)
- sol-compiler: build fails behind proxy since #1596 HOT 2
- sol-tracing-utils: consider changing the solidity parser HOT 1
- sol-compiler: fails on file with structs only HOT 2
- @0x/utils: Extra space in `provider.send` varies HOT 4
- @0x/contract-wrappers: `marketBuyOrdersFillOrKill` incorrect ABI encoding HOT 2
- [sol-compiler] New release of sol-compiler?
- Buy Contract - Call fails after payment token approval
- @0x/sol-compiler bug: sol-compiler not recognizing pragma experimental 0.5.0 HOT 2
- @0x/staking wrong dependency HOT 2
- sol-compiler does not recognize solc versions after 0.5.12 HOT 1
- Using sol-trace with external, existing contracts as interfaces HOT 3
- command for new package? HOT 2
- Instant revamp bake-off HOT 23
- 0x-contract-wrappers & 0x/abi-gen: TypeError: Cannot instantiate typing.Union HOT 2
- sol-compiler update link for solc binary downloads HOT 2
- Issues with installing project dependencies on MacOS Catalina HOT 3
- asset-swapper: CryptoCom is missing from market operation types HOT 2
- [abi-gen] [base-contract] Crypto algorithms blocking javascript main thread HOT 2
- [sol-compiler] AST is not present in the output when requested HOT 2
- python: getting signature using private key HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 0x-monorepo.