Skip to content

Instantly share code, notes, and snippets.

@Asone
Last active February 1, 2018 10:32
Show Gist options
  • Save Asone/6d1ed5cbd61a47fce7a670bcf28085ec to your computer and use it in GitHub Desktop.
Save Asone/6d1ed5cbd61a47fce7a670bcf28085ec to your computer and use it in GitHub Desktop.
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
Copy link
Author

Asone commented Nov 23, 2017

We assume here we're using typescript

@Asone
Copy link
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