How to use the @truffle/interface-adapter.Web3Shim function in @truffle/interface-adapter

To help you get started, we’ve selected a few @truffle/interface-adapter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trufflesuite / truffle / packages / core / lib / console.js View on Github external
"migrations_directory",
      "networks",
      "network",
      "network_id",
      "provider",
      "resolver",
      "build_directory"
    ]);

    this.options = options;

    this.repl = options.repl || new ReplManager(options);
    this.command = new Command(tasks);

    this.interfaceAdapter = new InterfaceAdapter();
    this.web3 = new Web3Shim({
      provider: options.provider,
      networkType: options.networks[options.network].type
    });

    // Bubble the ReplManager's exit event
    this.repl.on("exit", () => this.emit("exit"));
  }
github trufflesuite / truffle / packages / contract / lib / contract / constructorMethods.js View on Github external
network_id = json;
      json = this._json;
    }

    json = utils.merge({}, this._json || {}, json);

    temp._constructorMethods = this._constructorMethods;
    temp._properties = this._properties;

    temp._property_values = {};
    temp._json = json;

    bootstrap(temp);

    temp.interfaceAdapter = new InterfaceAdapter();
    temp.web3 = new Web3Shim({
      networkType: temp.networkType
    });
    temp.class_defaults = temp.prototype.defaults || {};

    if (network_id) {
      temp.setNetwork(network_id);
    }

    // Copy over custom key/values to the contract class
    Object.keys(json).forEach(key => {
      if (key.indexOf("x-") !== 0) return;
      temp[key] = json[key];
    });

    return temp;
  },
github trufflesuite / truffle / packages / core / lib / networks.js View on Github external
const provider = Provider.create(network_options);

    const first = network_id + "";
    const second = network_options.network_id + "";

    if (first === second) return callback(null, true);

    const isFirstANumber = isNaN(parseInt(network_id)) === false;
    const isSecondANumber =
      isNaN(parseInt(network_options.network_id)) === false;

    // If both network ids are numbers, then they don't match, and we should quit.
    if (isFirstANumber && isSecondANumber) return callback(null, false);

    const interfaceAdapter = new InterfaceAdapter();
    const web3 = new Web3Shim({
      provider,
      networkType: network_options.type
    });
    web3.eth.net
      .getId(current_network_id => {
        if (first === current_network_id) return callback(null, true);

        if (isFirstANumber === false) {
          BlockchainUtils.matches(first, provider, callback);
        } else {
          // Nothing else to compare.
          return callback(null, false);
        }
      })
      .catch(callback);
  }
github trufflesuite / truffle / packages / contract / lib / contract / constructorMethods.js View on Github external
if (typeof json !== "object") {
      network_id = json;
      json = this._json;
    }

    json = utils.merge({}, this._json || {}, json);

    temp._constructorMethods = this._constructorMethods;
    temp._properties = this._properties;

    temp._property_values = {};
    temp._json = json;

    bootstrap(temp);

    temp.web3 = new Web3Shim({
      networkType: temp.networkType
    });
    temp.class_defaults = temp.prototype.defaults || {};

    if (network_id) {
      temp.setNetwork(network_id);
    }

    // Copy over custom key/values to the contract class
    Object.keys(json).forEach(key => {
      if (key.indexOf("x-") !== 0) return;
      temp[key] = json[key];
    });

    return temp;
  },
github trufflesuite / truffle / packages / migrate / migration.js View on Github external
prepareForMigrations(options) {
    const logger = options.logger;
    const interfaceAdapter = createInterfaceAdapter({
      provider: options.provider,
      networkType: options.networks[options.network].type
    });
    const web3 = new Web3Shim({
      provider: options.provider,
      networkType: options.networks[options.network].type
    });

    const resolver = new ResolverIntercept(options.resolver);

    // Initial context.
    const context = { web3, interfaceAdapter, config: this.config };

    const deployer = new Deployer({
      logger,
      confirmations: options.confirmations,
      timeoutBlocks: options.timeoutBlocks,
      networks: options.networks,
      network: options.network,
      network_id: options.network_id,
github trufflesuite / truffle / packages / core / lib / package.js View on Github external
OS.EOL +
            OS.EOL +
            "    http://truffleframework.com/tutorials/using-infura-custom-provider" +
            OS.EOL
        )
      );
    }

    options.network = "ropsten";

    var provider = options.provider;
    const interfaceAdapter = new InterfaceAdapter({
      provider: options.provider,
      networkType: "ethereum"
    });
    var web3 = new Web3Shim({
      provider: options.provider,
      networkType: "ethereum"
    });
    var host = options.ethpm.ipfs_host;

    if (host instanceof EthPM.hosts.IPFS === false) {
      host = new EthPM.hosts.IPFS(
        options.ethpm.ipfs_host,
        options.ethpm.ipfs_port,
        options.ethpm.ipfs_protocol
      );
    }

    options.logger.log("Finding publishable artifacts...");

    self.publishable_artifacts(options, function(err, artifacts) {
github trufflesuite / truffle / packages / environment / environment.js View on Github external
detect: async function(config) {
    expect.options(config, ["networks"]);

    helpers.setUpConfig(config);
    helpers.validateNetworkConfig(config);

    const interfaceAdapter = new InterfaceAdapter({
      provider: config.provider,
      networkType: config.networks[config.network].type
    });
    const web3 = new Web3Shim({
      provider: config.provider,
      networkType: config.networks[config.network].type
    });

    await Provider.testConnection(config);
    await helpers.detectAndSetNetworkId(config, web3, interfaceAdapter);
    await helpers.setFromOnConfig(config, web3, interfaceAdapter);
  },
github trufflesuite / truffle / packages / require / require.js View on Github external
exec: function(options, done) {
    expect.options(options, [
      "contracts_build_directory",
      "file",
      "resolver",
      "provider",
      "network",
      "network_id"
    ]);

    const interfaceAdapter = createInterfaceAdapter({
      provider: options.provider,
      networkType: options.networks[options.network].type
    });
    const web3 = new Web3Shim({
      provider: options.provider,
      networkType: options.networks[options.network].type
    });

    try {
      const fn = this.file({
        file: options.file,
        context: { web3, interfaceAdapter },
        resolver: options.resolver
      });
      fn(done);
    } catch (error) {
      done(error);
    }
  }
};
github trufflesuite / truffle / packages / environment / environment.js View on Github external
fork: async function(config) {
    expect.options(config, ["from", "provider", "networks", "network"]);

    const interfaceAdapter = new InterfaceAdapter({
      provider: config.provider,
      networkType: config.networks[config.network].type
    });
    const web3 = new Web3Shim({
      provider: config.provider,
      networkType: config.networks[config.network].type
    });

    const accounts = await web3.eth.getAccounts();
    const block = await interfaceAdapter.getBlock("latest");

    const upstreamNetwork = config.network;
    const upstreamConfig = config.networks[upstreamNetwork];
    const forkedNetwork = config.network + "-fork";
    const ganacheOptions = {
      fork: config.provider,
      gasLimit: block.gasLimit
    };
    if (accounts.length > 0) ganacheOptions.unlocked_accounts = accounts;
github trufflesuite / truffle / packages / environment / environment.js View on Github external
detect: async function(config) {
    expect.options(config, ["networks"]);

    helpers.setUpConfig(config);
    helpers.validateNetworkConfig(config);

    const web3 = new Web3Shim({
      provider: config.provider,
      networkType: config.networks[config.network].type
    });

    await helpers.detectAndSetNetworkId(config, web3);
    await helpers.setFromOnConfig(config, web3);
  },

@truffle/interface-adapter

A library that provides an adapter layer for Truffle to interace with different types of networks/ledgers.

MIT
Latest version published 1 year ago

Package Health Score

55 / 100
Full package analysis

Similar packages