Last active
January 8, 2019 19:20
-
-
Save noot/002911382618bc221583edd05a9b9a6d to your computer and use it in GitHub Desktop.
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
const ethers = require('ethers') | |
const Wallet = ethers.Wallet | |
const providers = ethers.providers | |
// change ContractName to the name of your contract | |
const contractJson = require('./build/contracts/ContractName.json') | |
const abiEncoder = new ethers.utils.AbiCoder() | |
const deploy = async() => { | |
// copy your private key here | |
let wallet = new Wallet("privatekey") | |
// change url if needed | |
let provider = new providers.JsonRpcProvider("http://localhost:8545", "unspecified") | |
wallet = wallet.connect(provider) | |
let contractFactory = new ethers.ContractFactory( contractJson.abi , contractJson.bin , wallet ) | |
let contract = await contractFactory.deploy() | |
await provider.waitForTransaction(contract.deployTransaction.hash) | |
let receipt = await provider.getTransactionReceipt(contract.deployTransaction.hash) | |
console.log("contract deployed") | |
return contract | |
} | |
const call = async() => { | |
let contract = await deploy() | |
// these are the parameters | |
let _identifiedAddress | |
let _jurisdiction | |
let _effectiveTime | |
let _expiryTime | |
let _publicData | |
let _documentsEncrypted | |
let _documentAvailabilityEncrypted | |
// address of the contract we wish to call inside our main contract | |
let addressOfContractToCall | |
// format calldata with abiEncoder | |
let parameters = abiEncoder.encode(["address", "uint16", "uint64", "uint64", "bytes", "bytes", "bytes32"], | |
[_identifiedAddress, _jurisdiction, _effectiveTime, _expiryTime, _publicData, _documentsEncrypted, _documentAvailabilityEncrypted]) | |
// generate hash of function signature | |
let signature = contract.interface.functions.setAttestation.signature | |
let hash = ethers.utils.solidityKeccak256(signature) | |
let calldata = `${hash.slice(0,8)}${parameters.slice(2)}` | |
let tx = await contract.callContract(addressOfContractToCall, calldata) | |
await provider.waitForTransaction(tx.hash) | |
let receipt = await provider.getTransactionReceipt(tx.hash) | |
console.log(receipt) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment