Skip to content

Instantly share code, notes, and snippets.

@Asone Asone/instance.ts
Last active Feb 1, 2018

Embed
What would you like to do?
Create an instance of smart-contract to interact with when contract address is not already specified
// this is useful when you have to interact with contract instanciated on-the-go from another contract and can't use the deployed() method of truffle-contract
/**
*
* @ABIJSON : a JSON object representing the ABI file ( mostly generated with a solidity compiler or a deployment framework ( embark / truffle )
* @nodeEntryPoint : node of the ETH chain to interact with
* @scDeployedAddress : Address of the contract to interact with
* @myMethod : Method of the smart contrac to call
* @arg1,arg2,argN : some arguments for the method.
* @signatureAddress : address originating the transaction
* @maxGas : gas that will be provided for the transaction. If can't be determined in advance, should be quite large, moreover if you plan to call a method that itself will deploy another contract
*
**/
var sc = contract(<ABIJSON>);
sc.setProvider(<nodeEntryPoint>);
sc.at(<scDeployedAddress>).then((instance) => {
return instance.<myMethod>(arg1, arg2,<argN>,{ from : <signatureAddress>, gas : <maxGas> });
})
.then((r) => {
console.log(r); // Result
})
.catch((e) => {
console.log(e); // Error
});
@Asone

This comment has been minimized.

Copy link
Owner Author

Asone commented Nov 23, 2017

We assume here we're using typescript

@Asone

This comment has been minimized.

Copy link
Owner Author

Asone commented Nov 23, 2017

TODO : provide another gist for ABI-less methods calls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.