Skip to content

Instantly share code, notes, and snippets.

@ILoomans
Last active May 11, 2021 19:20
Show Gist options
  • Save ILoomans/e8cb55c72f8b1b274da7fc375cb5a6ba to your computer and use it in GitHub Desktop.
Save ILoomans/e8cb55c72f8b1b274da7fc375cb5a6ba to your computer and use it in GitHub Desktop.
Ink contract error after two hours of substrate-node-deployment
function deployContract(){
const wsProvider = new WsProvider('ws://localhost:9944');
let api = await ApiPromise.create({ provider: wsProvider, types });
const keyring = new Keyring({ type: 'sr25519' });
let wallet = keyring.addFromUri('//Bob', { name: 'Bob default' });
const code = new CodePromise(api, ABI, WASM);
const constructorIndex = 0;
const gasLimit = 200000000000;
let endowment = 1000000000000000;
code.tx
.new(
{ gasLimit, salt: randomAsHex(), value: endowment },
1000, //amount
100, //price
wallet.address
)
.signAndSend(wallet, ({ status, events }) => {
if (status.isInBlock || status.isFinalized) {
events
.filter(({ event }) => api.events.system.ExtrinsicFailed.is(event))
.forEach(
({
event: {
data: [error, info],
},
}) => {
console.log('error')
res.status(500).json(error)
}
);
events
.filter(({ event }) => api.events.contracts.CodeStored.is(event))
.forEach(
({
event: {
data: [code_hash],
},
}) => {
console.log(`code hash: ${code_hash}`);
}
);
events
.filter(({ event }) => api.events.contracts.Instantiated.is(event))
.forEach(
({
event: {
data: [deployer, contract],
},
}) => {
console.log(`contract address: ${contract} at index ${index}`);
}
);
}
});
}
// works fine before two hours pass by
function fetchOwnerBalance(){
const wsProvider = new WsProvider('ws://localhost:9944');
let api = await ApiPromise.create({ provider: wsProvider, types });
const keyring = new Keyring({ type: 'sr25519' });
let wallet = keyring.addFromUri('//Bob', { name: 'Bob default' });
const contract = new ContractPromise(api, abi, addressid);
let owner = await contract.query.getOwner(wallet.address,{value:0,gasLimit:-1})
// Fails right here after two hours -> 'Cant read toHuman() of undefined'
owner = owner.output.toHuman()
let ownerBalance = await contract.query.balanceOf(wallet.address, { value: 0, gasLimit: -1 }, owner);
ownerBalance = parseInt(ownerBalance.output)
return ownerBalance
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment