Last active
February 1, 2018 10:32
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}); |
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
We assume here we're using typescript