Giter Site home page Giter Site logo

Comments (21)

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024 1

Hi,
An order is essentially a bunch of data, that conforms to the Order type.
There is no function to generate it, cause it's just a plain JS object.
You can generate it yourself and pass it into any function accepting an order.
However - there are some fields, that you can use some helper functions/consts to fill.

const order = {
	exchangeContractAddress: string, // Can be fetched from [zeroEx.exchange.getExchangeContractAddress](https://0xproject.com/docs/0xjs#getContractAddressAsync)
	expirationUnixTimestampSec: BigNumber, // This is up to you
	feeRecipient: string, // Specify the fee recepient address or use `ZeroEx.NULL_ADDRESS` to disable fees
	maker: string, // The address creating an order
	makerFee: BigNumber, // Fee size the maker pays in Base Units or `new BigNumber(0)`
	makerTokenAddress: string,
	makerTokenAmount: BigNumber,
	salt: BigNumber, // Use [ZeroEx.generatePseudoRandomSalt](https://0xproject.com/docs/0xjs#generatePseudoRandomSalt)
	taker: string, // Taker address or `ZeroEx.NULL_ADDRESS` if you want anyone to be able to fill the order (most probably)
	takerFee: BigNumber, // Fee size the taker pays in Base Units or `new BigNumber(0)`
	takerTokenAddress: string,
	takerTokenAmount: BigNumber,
}

This is how you get a plain Order.
In order to make it useful (fillable) you'd like to sign it.

const orderHash = ZeroEx.getOrderHashHex(order);
const ecSignature = zeroEx.signOrderHashAsync(orderHash, signerAddress);
const signedOrder = {
   ...order,
   ecSignature,
};

I'll also recommend to check out the tests for more examples.
Specifically for order creation: https://github.com/0xProject/0x.js/blob/master/test/utils/order_factory.ts

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024 1

You can use the provider-engine with the HookedWalletSubprovider to sign the transactions and access accounts.
And you can connect it to infura via RpcSubprovider

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024 1

Here is the example subprovider we wrote for a Ledger https://github.com/0xProject/website/blob/development/ts/subproviders/ledger_wallet_subprovider_factory.ts

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024 1

Here is an another example - that calls a signature server to sign transactions: https://github.com/Neufund/server-wallet-provider/blob/master/src/index.js

from 0x-monorepo.

EeevilPopTart avatar EeevilPopTart commented on May 24, 2024 1

@LogvinovLeon How can I go about signing an order using only a private key? If I need to add my private key to a provider, how can I do that programmatically so that I don't have to use something like MetaMask or a Ledger? I have order data and a private key, hash the order data, now I just want to sign it so I can submit it to a relayer.

Edit: I've found a solution. I'm using the 0x node module to generate the hash, then signing it using the private key via the ecsign function from ethereumjs-util.

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024

@support-somish Can this issue be closed? Did you successfully generate an order?

from 0x-monorepo.

 avatar commented on May 24, 2024

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024

You can use 0x.js with Kovan or testrpc. We don't support Rinkeby yet.
You can run and test 0x.js with testrp. This is how we run onr tests and CI.
If you need some kovan ETH just use a faucet available as a part of kovan OTC.

from 0x-monorepo.

 avatar commented on May 24, 2024

We tried creating an order through the ts file but we are unable to execute ZeroEx.generatePseudoRandomSalt as it says that generatePseudoRandomSalt is not a function. We are able to access all other functions of the ZeroEx object except this one.

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024

You can try printing the whole ZeroEx object and checking, that this function is there.
Which version of 0x.js are you using?

from 0x-monorepo.

 avatar commented on May 24, 2024

We used command npm install 0x.js to install 0x in our project. The current version is 0.9.3. Please see the object image attached. Is there a specific version we need to use?
0x object

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024

generatePresudoRandomSalt is a static function. You're printing an instance, not a constructor.
Are you sure, you're calling it like ZeroEx.generatePresudoRandomSalt, not like: zeroEx.generatePresudoRandomSalt?
The first way is correct.

from 0x-monorepo.

 avatar commented on May 24, 2024

Many thanks, we were able to create an order hash.

Just one more thing, we are trying to sign the order hash using the following:
zeroEx.signOrderHashAsync(orderHash,"0x7266C50F1f461d2748e675B907eF22987F6B5358")
.then(function(ECSignature) {
console.log("Signature is "+ECSignature);
})
.catch(function(error) {
console.log('Caught error: ', error);
});

We get the error: Specified signerAddress 0x7266C50F1f461d2748e675B907eF22987F6B5358 isn't available through the supplied web3 provider. We are using Web3.providers.HttpProvider("https://kovan.infura.io/") as the Web3 Provider.

Can you please help.

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024

Convert the address to lover case

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024

Newer versions of 0x.js throw a better error message in this case

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024

Actually - this will not help, cause in order to sign - you'll need a private key.
Infura obviously doesn't have your private key.

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024

You'll need a web3 instance that has access to your accounts. What's your use case? What do you plan to use for signing?

from 0x-monorepo.

 avatar commented on May 24, 2024

We need to build a nodeJS API which will automatically(based on a few system checks), create orders for exchanging ERC20 tokens. Generally we use web3.eth.sendRawTransaction to send data on chain via infura.io.

from 0x-monorepo.

LogvinovLeon avatar LogvinovLeon commented on May 24, 2024

Closing because of inactivity. Feel free to reopen if still valid.

from 0x-monorepo.

nitika-goel avatar nitika-goel commented on May 24, 2024

Hi, pardon for the inactivity. I'm still unable to solve this. Intend to use infura as I cannot run a local geth node. Here is the code I am using:

const Web3 = require('web3');
const Accounts=require('web3-eth-accounts');
const HookedWeb3Provider=require("hooked-web3-provider");
const ZeroEx = require('0x.js').ZeroEx;
const BigNumber = require('bignumber.js');
const KOVAN_ENDPOINT='https://kovan.infura.io/';

(async () => {
    var web3=new Web3(new Web3.providers.HttpProvider(KOVAN_ENDPOINT));
    var accounts =new Accounts(KOVAN_ENDPOINT);
    // Creating a new Account
    var logAcc=web3.eth.accounts.privateKeyToAccount("528d53be9f33de80d68b148aac930b9ab757d798ef251bcbdcfd94b95961144a");
    console.log(logAcc);

   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);  // Ethereum 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);
     var account =  await zeroEx.getAvailableAddressesAsync();
     console.log(account);
})().catch(console.log);

I have created an account with a private key and am able to sign the order hash with web3.eth.accounts.sign() but in that case my vrs signatures generated do not match.

I intend to use the standard ZeroEx functions but the function zeroEx.getAvailableAddressesAsync() returns null value even though my web3 object has accounts json associated with it.

Can you please provide a sample of using your standard method with infura please?

from 0x-monorepo.

fabioberger avatar fabioberger commented on May 24, 2024

@EeevilPopTart you can use a Web3 Provider Engine custom provider setup with the HookedWalletSubProvider with a similar module passed into it as this: https://github.com/0xProject/0x.js/blob/development/packages/testnet-faucets/src/ts/id_management.ts

from 0x-monorepo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.