New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eth-contract-class

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eth-contract-class - npm Package Compare versions

Comparing version 0.0.13-beta.2 to 0.0.13-beta.3

74

embark/index.js
// embark plugin to use eth-contract-class
const generateClass = require('../lib/generateClass').default;
module.exports = Embark => {
Embark.events.on('runcode:ready', () => {
Embark.events.emit('runcode:register', 'generateClass', require('eth-contract-class'), () => {
Embark.registerTestContractFactory(function testContractFactory(contractRecipe, web3) {
if (!contractRecipe.code) return null;
const generateClass = require('eth-contract-class').default;
const ContractClass = generateClass(contractRecipe.abiDefinition, contractRecipe.code);
const contract = new ContractClass(web3, contractRecipe.deployedAddress);
Embark.registerTestContractFactory(function testContractFactory(contractRecipe, web3) {
if (!contractRecipe.code) return null;
const ContractClass = generateClass(contractRecipe.abiDefinition, contractRecipe.code);
const contract = new ContractClass(web3, contractRecipe.deployedAddress);
contract.$runtimeByteCode = '0x' + contractRecipe.runtimeBytecode;
contract.$runtimeByteCode = '0x' + contractRecipe.runtimeBytecode;
// embark creates a empty Object for contracts when using embark.require('Embark/contracts/*')
// then uses Object.setPrototypeOf(contractObject, contractFactoryResult) to "populate" the
// object. Unfortunately this will ensure that the contract instance is not callable directly
// so we instantiate the contract instance here & return the object.
// we provide the `.at` function here so we can provide a way to get a new Contract instance
return Object.assign(contract, {
new: (...args) => ContractClass.new(web3, ...args),
at: address => new ContractClass(web3, address),
});
});
// embark creates a empty Object for contracts when using embark.require('Embark/contracts/*')
// then uses Object.setPrototypeOf(contractObject, contractFactoryResult) to "populate" the
// object. Unfortunately this will ensure that the contract instance is not callable directly
// so we instantiate the contract instance here & return the object.
// we provide the `.at` function here so we can provide a way to get a new Contract instance
return Object.assign(contract, {
deploy: (...args) => ContractClass.new(web3, ...args),
at: address => new ContractClass(web3, address),
});
});
// For some reason this is called multiple times, so we use .once
Embark.events.once('blockchain:ready', () => {
Embark.events.emit('runcode:register', 'generateClass', generateClass, () => {
Embark.registerCustomContractGenerator(contract => {
return `
${contract.className} = generateClass(${JSON.stringify(contract.abiDefinition)}, '${
${contract.className} = new (generateClass(${JSON.stringify(contract.abiDefinition)}, '${
contract.code
}');
${contract.className}Instance = new ${contract.className}(web3, '${
}'))(web3, '${contract.deployedAddress}');`;
});
});
});
Embark.registerContractsGeneration(function(options) {
const contractGenerations = [];
Object.keys(options.contracts).map(className => {
const contract = options.contracts[className];
const abi = JSON.stringify(contract.abiDefinition);
contractGenerations.push(
`
/* global web3 */
"use strict";
// Loading EmbarkJS will make web3 globally available
const isNode = (typeof process !== 'undefined' && process.versions && process.versions.node);
const EmbarkJSNode = isNode && require('../embarkjs.node');
let EmbarkJSBrowser;
try {
EmbarkJSBrowser = require('../embarkjs').default;
} catch(e) {};
const generateClass = require('eth-contract-class').default;
let ${className} = new (generateClass(${abi}, '${contract.code}'))(web3, '${
contract.deployedAddress
}');
`;
});
module.exports = ${className};
`,
);
});
return contractGenerations.join('\n');
});
};
{
"name": "eth-contract-class",
"version": "0.0.13-beta.2",
"version": "0.0.13-beta.3",
"description": "generate js wrapper class around an ethereum contract",
"main": "lib/generateClass.js",
"directories": {
"lib": "lib"
"lib": "lib",
"embark": "embark"
},

@@ -9,0 +10,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc