Skip to content

Instantly share code, notes, and snippets.

View DavidVotrubec's full-sized avatar

David Votrubec DavidVotrubec

View GitHub Profile
module.exports = async function(deployer, _, accounts) {
let someContract = await SomeContract.deployed();
try {
// If this contract method fails, the migration does not stop
await someContract.someMethod(namehash(''), web3.utils.sha3("eth"), accounts[0]);
}
catch (err) {
console.log('Deploy step X failed', err);
throw new Error('Deploy step X failed');
@DavidVotrubec
DavidVotrubec / console
Last active October 15, 2018 12:36
Truffle console is better than truffle develop
truffle console --network ganache_cli
The full procedure is like this
- make sure that ganache_cli is running and truffle.js is configured properly
- truffle networks --clean // to reset old garbage
- truffle console --network ganache_cli
- migrate
- interact with your deploys smart contract via JS
- MySmartContract.deployed().then(function(instance) {... call your contract's instance methods ;});
@DavidVotrubec
DavidVotrubec / deploy
Last active October 17, 2018 13:25
Codes for article on Medium - https://medium.com/p/6088f923d621/edit
myContract.deploy().send({from: accounts[1]})
@DavidVotrubec
DavidVotrubec / web3.js
Created October 15, 2018 07:23
Instance of web3 with provider from web3 injected by MetaMask
import Web3 from 'web3';
// We are assumming that the user has installed the Metamask browser extension
// and we are using Provider from the injected instance of web3
// to create instance of Web3 of our desired version
// See https://www.udemy.com/ethereum-and-solidity-the-complete-developers-guide/learn/v4/t/lecture/9020582?start=0 for more details
// This way we can simply import preconfigured instance of web3
const web3 = new Web3(window.web3.currentProvider);
export default web3;
@DavidVotrubec
DavidVotrubec / controllers.application.js
Last active June 15, 2016 21:41
Confirmation-Dialog-3
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
items: [
{id: 1, name: 'first item'},
{id: 2, name: 'second item'},
{id: 3, name: 'third item'},
{id: 4, name: 'fourth item'},
@DavidVotrubec
DavidVotrubec / controllers.application.js
Last active June 15, 2016 21:43
Confirmation-Dialog
import Ember from 'ember';
export default Ember.Component.extend({
itemToDelete: null,
hasItemToDelete: Ember.computed('itemToDelete', function(){
return this.get('itemToDelete') != null;
}),
_closeConfirmationDialog: function() {
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
myStrings: ['bla', 'asd', 'zzz', 'fgh'],
computedStrings: Ember.computed('myStrings.[]', function() {
return this.get('myStrings')
.map(aString => Ember.String.capitalize(aString));
}),
actions: {
@DavidVotrubec
DavidVotrubec / nl2br_in_ember.js
Last active May 12, 2016 07:25
Newline to <br/> in EmberJS
nl2br(str) {
var newStr = str.split('\n').map(function(item) {
const key = Math.random() * (9999999 - 1) + 1;
return (
<span key={key}>
{item}
<br/>
</span>
)
nl2br(str) {
var newStr = str.split('\n').map(function(item) {
const key = Math.random() * (9999999 - 1) + 1;
return (
<span key={key}>
{item}
<br/>
</span>
)
app.directive('someDirective', function () {
return {
scope: {
oneWay: '@',
twoWay: '=',
expr: '&'
}
};
});