Signature providers for Web Applications

Each blockchain has it's own signature provider and provides an easy way to set up your application using Scatter as a way to sign transactions instead of having users enter their private keys into your applications.

Once a signature provider is set up, you use it the same way as you use the original library ( web3, eosjs, tronweb, etc ). Let's see how we can set up signature providers for supported blockchains.

Using a Proxy Provider

Proxy providers allow you to use the requiredFields object within transaction to get more information from the user during your signature requests.
// eosjs
const options = {};
const eos = scatter.eos( network, Eos, options );

// eosjs2
const rpc = new eosjs_jsonrpc.JsonRpc(...);
const api = scatter.eos(network, eosjs2.Api, {rpc});

// web3
const web3 = scatter.eth( network, Web3 );
// For custom contracts you MUST supply your contract's ABI.
const options = {from:account.address, abi};

// tron
const tronWeb = new TronWeb(fullNode, fullNode, eventServer);
const tron = scatter.trx(network, tronWeb);

Using a Hook Provider
Hook providers won't allow you to use the requiredFields logic, but they are a bit simpler to set up.
// eosjs
const eos = Eos({ httpEndpoint:'', signatureProvider:scatter.eosHook(network) })

// eosjs2
const rpc = new eosjs_jsonrpc.JsonRpc(...);
const api = new eosjs.Api({ rpc, signatureProvider:scatter.eosHook(network) });

Right now ScatterETH and ScatterTron do not support the hook provider.

What is the network to pass in?

The network you pass into signature providers is the actual endpoint you wish to interact with. It is formatted just like the network you pass into the Requirable Fields object. You should also make sure that the chainId matches the one that you are requesting accounts from the user with, or else you won't be able to get valid signatures.


Want to get Required Fields?

You can require fields to be returned if the user signs the transaction. This allows you to get things you need to complete real world transactions such as addresses for physical shipments, or an email for receipts.

Remember that this only works with Proxy Providers and not Hook Providers.

// ---------------------------------------
// EOS
// ---------------------------------------

// Right
const contract = await eos.contract('hello', {requiredFields});
const result = await contract.hi(...);

// Wrong
const contract = await eos.contract('hello');
const result = await contract.hi(..., {requiredFields});

// ---------------------------------------
// Ethereum
// ---------------------------------------

    from: account.address,
    to: '0x11f4d......',
    value: '1',

const options = {from:account.address, abi, requiredFields, fields => {
    console.log('fields', fields);